sonuprasad23 commited on
Commit
c1e4b14
·
1 Parent(s): d6b49de

Fixing this

Browse files
Files changed (1) hide show
  1. server.py +15 -15
server.py CHANGED
@@ -124,9 +124,10 @@ def generate_and_send_reports(session_id, results, is_crash_report=False, is_ter
124
  if results:
125
  result_df = pd.DataFrame(results).set_index('Name')
126
  full_df.set_index('Name', inplace=True)
 
127
  full_df.update(result_df); full_df.reset_index(inplace=True)
128
 
129
- full_df['Status'] = full_df['Status'].fillna('Not Processed')
130
 
131
  final_report_df = full_df[['Name', 'PRN', 'Status']]
132
  bad_df = final_report_df[final_report_df['Status'] == 'Bad']
@@ -162,20 +163,19 @@ def status_page():
162
  APP_STATUS_HTML = """<!DOCTYPE html><html lang="en"><head><title>API Status</title><style>body{font-family:sans-serif;display:flex;justify-content:center;align-items:center;height:100vh;margin:0;background:#f0f2f5;}.status-box{text-align:center;padding:40px 60px;background:white;border-radius:12px;box-shadow:0 8px 30px rgba(0,0,0,0.1);}h1{font-size:24px;color:#333;margin-bottom:10px;} .indicator{font-size:18px;font-weight:600;padding:8px 16px;border-radius:20px;}.active{color:#28a745;background-color:#e9f7ea;}</style></head><body><div class="status-box"><h1>Hillside Automation API</h1><div class="indicator active">● Active</div></div></body></html>"""
163
  return Response(APP_STATUS_HTML)
164
 
 
 
 
 
 
 
 
 
165
  def extract_patient_name(raw_name):
166
  if not isinstance(raw_name, str): return ""
167
  name_only = raw_name.split('DOB')[0].strip()
168
  return re.sub(r'[:\d\-\s]+$', '', name_only).strip()
169
 
170
- def read_file_with_fallback_encoding(file_storage, filename):
171
- """Reads a file Storage object, trying UTF-8 then Latin-1."""
172
- try:
173
- return pd.read_excel(file_storage) if filename.endswith('.xlsx') else pd.read_csv(file_storage, engine='python', on_bad_lines='warn')
174
- except UnicodeDecodeError:
175
- print(f"[Server Log] UTF-8 reading failed for {filename}. Retrying with Latin-1.")
176
- file_storage.seek(0) # Reset file pointer
177
- return pd.read_csv(file_storage, engine='python', on_bad_lines='warn', encoding='latin-1')
178
-
179
  @socketio.on('connect')
180
  def handle_connect():
181
  print(f'Frontend connected.')
@@ -191,11 +191,11 @@ def handle_init_and_process(data):
191
  'start_date': data.get('start_date'), 'end_date': data.get('end_date')
192
  }
193
 
194
- app_data_file_info = data.get('app_data_file')
195
- quantum_data_file_info = data.get('quantum_data_file')
196
-
197
- app_data_content = read_file_content(app_data_file_info)
198
- quantum_data_content = read_file_content(quantum_data_file_info)
199
 
200
  df_app = pd.read_csv(io.StringIO(app_data_content))
201
  df_quantum = pd.read_csv(io.StringIO(quantum_data_content))
 
124
  if results:
125
  result_df = pd.DataFrame(results).set_index('Name')
126
  full_df.set_index('Name', inplace=True)
127
+ full_df['Status'] = full_df['Status'].astype('object')
128
  full_df.update(result_df); full_df.reset_index(inplace=True)
129
 
130
+ full_df['Status'].fillna('Not Processed', inplace=True)
131
 
132
  final_report_df = full_df[['Name', 'PRN', 'Status']]
133
  bad_df = final_report_df[final_report_df['Status'] == 'Bad']
 
163
  APP_STATUS_HTML = """<!DOCTYPE html><html lang="en"><head><title>API Status</title><style>body{font-family:sans-serif;display:flex;justify-content:center;align-items:center;height:100vh;margin:0;background:#f0f2f5;}.status-box{text-align:center;padding:40px 60px;background:white;border-radius:12px;box-shadow:0 8px 30px rgba(0,0,0,0.1);}h1{font-size:24px;color:#333;margin-bottom:10px;} .indicator{font-size:18px;font-weight:600;padding:8px 16px;border-radius:20px;}.active{color:#28a745;background-color:#e9f7ea;}</style></head><body><div class="status-box"><h1>Hillside Automation API</h1><div class="indicator active">● Active</div></div></body></html>"""
164
  return Response(APP_STATUS_HTML)
165
 
166
+ def read_file_content(b64_content, filename):
167
+ raw_bytes = base64.b64decode(b64_content)
168
+ try:
169
+ return raw_bytes.decode('utf-8')
170
+ except UnicodeDecodeError:
171
+ print(f"[Server Log] UTF-8 decoding failed for {filename}, falling back to Latin-1.")
172
+ return raw_bytes.decode('latin-1')
173
+
174
  def extract_patient_name(raw_name):
175
  if not isinstance(raw_name, str): return ""
176
  name_only = raw_name.split('DOB')[0].strip()
177
  return re.sub(r'[:\d\-\s]+$', '', name_only).strip()
178
 
 
 
 
 
 
 
 
 
 
179
  @socketio.on('connect')
180
  def handle_connect():
181
  print(f'Frontend connected.')
 
191
  'start_date': data.get('start_date'), 'end_date': data.get('end_date')
192
  }
193
 
194
+ app_data_file = data.get('app_data_file')
195
+ quantum_data_file = data.get('quantum_data_file')
196
+
197
+ app_data_content = read_file_content(app_data_file['content'], app_data_file['name'])
198
+ quantum_data_content = read_file_content(quantum_data_file['content'], quantum_data_file['name'])
199
 
200
  df_app = pd.read_csv(io.StringIO(app_data_content))
201
  df_quantum = pd.read_csv(io.StringIO(quantum_data_content))