Raffael-Kultyshev commited on
Commit
c253083
·
1 Parent(s): 5c08ecc

Add error handling for data loading

Browse files
Files changed (1) hide show
  1. app.py +39 -14
app.py CHANGED
@@ -113,7 +113,17 @@ def prepare_data():
113
  'right_rot': right_rot
114
  }
115
 
116
- plot_data = prepare_data()
 
 
 
 
 
 
 
 
 
 
117
 
118
  METRIC_LABELS = {
119
  "x_cm": "X (cm)",
@@ -232,20 +242,35 @@ CUSTOM_CSS = """
232
 
233
  def build_plot_fig(metric: str, hand: str = "left") -> go.Figure:
234
  """Build Plotly figure for a metric."""
235
- times = plot_data['times']
236
-
237
- if hand == "left":
238
- if "cm" in metric:
239
- data = plot_data['left_pos'][metric.replace('_cm', '')]
240
- else:
241
- data = plot_data['left_rot'][metric.replace('_deg', '')]
242
- name = "Left Hand"
243
- else:
244
- if "cm" in metric:
245
- data = plot_data['right_pos'][metric.replace('_cm', '')]
246
  else:
247
- data = plot_data['right_rot'][metric.replace('_deg', '')]
248
- name = "Right Hand"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
 
250
  fig = go.Figure()
251
  fig.add_trace(
 
113
  'right_rot': right_rot
114
  }
115
 
116
+ try:
117
+ plot_data = prepare_data()
118
+ except Exception as e:
119
+ print(f"Error preparing plot data: {e}")
120
+ plot_data = {
121
+ 'times': [],
122
+ 'left_pos': {'x': [], 'y': [], 'z': []},
123
+ 'left_rot': {'yaw': [], 'pitch': [], 'roll': []},
124
+ 'right_pos': {'x': [], 'y': [], 'z': []},
125
+ 'right_rot': {'yaw': [], 'pitch': [], 'roll': []}
126
+ }
127
 
128
  METRIC_LABELS = {
129
  "x_cm": "X (cm)",
 
242
 
243
  def build_plot_fig(metric: str, hand: str = "left") -> go.Figure:
244
  """Build Plotly figure for a metric."""
245
+ try:
246
+ times = plot_data.get('times', [])
247
+
248
+ if hand == "left":
249
+ if "cm" in metric:
250
+ key = metric.replace('_cm', '')
251
+ data = plot_data.get('left_pos', {}).get(key, [])
252
+ else:
253
+ key = metric.replace('_deg', '')
254
+ data = plot_data.get('left_rot', {}).get(key, [])
255
+ name = "Left Hand"
256
  else:
257
+ if "cm" in metric:
258
+ key = metric.replace('_cm', '')
259
+ data = plot_data.get('right_pos', {}).get(key, [])
260
+ else:
261
+ key = metric.replace('_deg', '')
262
+ data = plot_data.get('right_rot', {}).get(key, [])
263
+ name = "Right Hand"
264
+
265
+ if not times or not data:
266
+ # Return empty plot
267
+ times = [0]
268
+ data = [0]
269
+ except Exception as e:
270
+ print(f"Error in build_plot_fig: {e}")
271
+ times = [0]
272
+ data = [0]
273
+ name = "Error"
274
 
275
  fig = go.Figure()
276
  fig.add_trace(