Update probe related models, routes and templates
This commit is contained in:
@@ -93,6 +93,23 @@ class Probe:
|
||||
raise Exception('Failed to create probe')
|
||||
return cls(**result.data[0])
|
||||
|
||||
def retire(self):
|
||||
"""Mark probe as retired with current timestamp"""
|
||||
supabase = get_supabase()
|
||||
result = supabase.table('probes').update({
|
||||
'retired_at': datetime.utcnow().isoformat()
|
||||
}).eq('id', self.id).execute()
|
||||
if not result.data:
|
||||
raise Exception('Failed to retire probe')
|
||||
self.retired_at = datetime.utcnow()
|
||||
|
||||
def delete(self):
|
||||
"""Delete probe from database"""
|
||||
supabase = get_supabase()
|
||||
result = supabase.table('probes').delete().eq('id', self.id).execute()
|
||||
if not result.data:
|
||||
raise Exception('Failed to delete probe')
|
||||
|
||||
@dataclass
|
||||
class Channel:
|
||||
"""Channel model representing individual measurement channels"""
|
||||
@@ -131,6 +148,19 @@ class Channel:
|
||||
channels.append(cls(**row))
|
||||
return channels
|
||||
|
||||
@classmethod
|
||||
def get_by_serial(cls, serial_number: str):
|
||||
"""Get channel by serial number if it exists (case-sensitive exact match)"""
|
||||
serial_upper = serial_number.upper()
|
||||
supabase = get_supabase()
|
||||
result = supabase.table('channels').select("*").eq('serial_number', serial_upper).execute()
|
||||
if not result.data:
|
||||
return None
|
||||
row = result.data[0]
|
||||
# Parse datetime string
|
||||
row['created_at'] = datetime.fromisoformat(row['created_at']) if row['created_at'] else None
|
||||
return cls(**row)
|
||||
|
||||
@classmethod
|
||||
def create(cls, probe_id: str, serial_number: str, parameter_id: str):
|
||||
"""Create a new channel"""
|
||||
@@ -259,6 +289,25 @@ class Calibration:
|
||||
result = supabase.table('calibrations').select("*").eq('work_order_id', work_order_id).execute()
|
||||
return [cls(**row) for row in result.data] if result.data else []
|
||||
|
||||
@classmethod
|
||||
def get_by_channel(cls, channel_id: str):
|
||||
"""Get all calibrations for a specific channel"""
|
||||
supabase = get_supabase()
|
||||
result = supabase.table('calibrations').select("*").eq('channel_id', channel_id).execute()
|
||||
calibrations = []
|
||||
for row in result.data if result.data else []:
|
||||
try:
|
||||
# Parse datetime strings
|
||||
for date_field in ['std_cal_date', 'std_cal_due', 'date']:
|
||||
if row.get(date_field):
|
||||
row[date_field] = datetime.fromisoformat(row[date_field])
|
||||
|
||||
calibrations.append(cls(**row))
|
||||
except Exception as e:
|
||||
print(f"Error parsing calibration data: {e}")
|
||||
continue
|
||||
return calibrations
|
||||
|
||||
@dataclass
|
||||
class Customer:
|
||||
"""Customer model representing clients who request calibrations"""
|
||||
|
||||
Reference in New Issue
Block a user