ranggaptr commited on
Commit
52034ac
·
1 Parent(s): a40d3b2

Improve error handling and data type safety in DBManager; ensure numeric columns are converted to float and handle missing config values gracefully

Browse files
__pycache__/db_manager.cpython-313.pyc CHANGED
Binary files a/__pycache__/db_manager.cpython-313.pyc and b/__pycache__/db_manager.cpython-313.pyc differ
 
app.py CHANGED
@@ -12,7 +12,11 @@ model_mgr = ModelManager('model_ai_bta.pkl', 'laju_penipisan.pkl')
12
  # ==================== UTILITY FUNCTIONS ====================
13
 
14
  def get_min_safe_thickness():
15
- return float(db.get_config('min_safe_thickness'))
 
 
 
 
16
 
17
  def get_initial_empty_state():
18
  """Return empty state untuk initial load"""
 
12
  # ==================== UTILITY FUNCTIONS ====================
13
 
14
  def get_min_safe_thickness():
15
+ try:
16
+ val = db.get_config('min_safe_thickness')
17
+ return float(val) if val else 115.0
18
+ except:
19
+ return 115.0
20
 
21
  def get_initial_empty_state():
22
  """Return empty state untuk initial load"""
db_manager.py CHANGED
@@ -101,7 +101,12 @@ class DBManager:
101
  ''')
102
  row = cursor.fetchone()
103
  if row:
104
- return dict(row)
 
 
 
 
 
105
  return None
106
 
107
  def get_historis(self, limit=100, flagged_only=False):
@@ -123,7 +128,15 @@ class DBManager:
123
 
124
  cursor.execute(query, (limit,))
125
  rows = cursor.fetchall()
126
- return [dict(row) for row in rows]
 
 
 
 
 
 
 
 
127
 
128
  def get_all_data_as_dataframe(self):
129
  """Get all measurement data sebagai Pandas DataFrame"""
@@ -163,7 +176,11 @@ class DBManager:
163
  cursor = conn.cursor()
164
  cursor.execute("SELECT value FROM app_config WHERE key = ?", (key,))
165
  row = cursor.fetchone()
166
- return row[0] if row else None
 
 
 
 
167
 
168
  def set_config(self, key, value):
169
  """Set config value"""
@@ -194,7 +211,7 @@ class DBManager:
194
  ORDER BY timestamp DESC LIMIT 1
195
  ''')
196
  latest = cursor.fetchone()
197
- current_thickness = latest[0] if latest else 230
198
 
199
  # Total maintenance events
200
  cursor.execute("SELECT COUNT(*) FROM maintenance_log")
 
101
  ''')
102
  row = cursor.fetchone()
103
  if row:
104
+ result = dict(row)
105
+ # Ensure numeric columns are float
106
+ for col in ['cone_depan', 'bodi_tengah', 'cone_belakang', 'suhu_avg', 'ketebalan_actual', 'ketebalan_prediksi']:
107
+ if col in result and result[col] is not None:
108
+ result[col] = float(result[col])
109
+ return result
110
  return None
111
 
112
  def get_historis(self, limit=100, flagged_only=False):
 
128
 
129
  cursor.execute(query, (limit,))
130
  rows = cursor.fetchall()
131
+ results = []
132
+ for row in rows:
133
+ result = dict(row)
134
+ # Ensure numeric columns are float
135
+ for col in ['cone_depan', 'bodi_tengah', 'cone_belakang', 'suhu_avg', 'ketebalan_actual', 'ketebalan_prediksi']:
136
+ if col in result and result[col] is not None:
137
+ result[col] = float(result[col])
138
+ results.append(result)
139
+ return results
140
 
141
  def get_all_data_as_dataframe(self):
142
  """Get all measurement data sebagai Pandas DataFrame"""
 
176
  cursor = conn.cursor()
177
  cursor.execute("SELECT value FROM app_config WHERE key = ?", (key,))
178
  row = cursor.fetchone()
179
+ value = row[0] if row else None
180
+ # Ensure string type
181
+ if value is not None and isinstance(value, bytes):
182
+ value = value.decode('utf-8')
183
+ return value
184
 
185
  def set_config(self, key, value):
186
  """Set config value"""
 
211
  ORDER BY timestamp DESC LIMIT 1
212
  ''')
213
  latest = cursor.fetchone()
214
+ current_thickness = float(latest[0]) if latest else 230.0
215
 
216
  # Total maintenance events
217
  cursor.execute("SELECT COUNT(*) FROM maintenance_log")