Spaces:
Running
Running
Commit ·
d6b49de
1
Parent(s): 0a9bac8
Fixing this
Browse files
server.py
CHANGED
|
@@ -167,15 +167,14 @@ def extract_patient_name(raw_name):
|
|
| 167 |
name_only = raw_name.split('DOB')[0].strip()
|
| 168 |
return re.sub(r'[:\d\-\s]+$', '', name_only).strip()
|
| 169 |
|
| 170 |
-
def
|
| 171 |
-
"""
|
| 172 |
-
b64_content = file_info.get('content')
|
| 173 |
-
raw_bytes = base64.b64decode(b64_content)
|
| 174 |
try:
|
| 175 |
-
return
|
| 176 |
except UnicodeDecodeError:
|
| 177 |
-
print(f"[Server Log] UTF-8
|
| 178 |
-
|
|
|
|
| 179 |
|
| 180 |
@socketio.on('connect')
|
| 181 |
def handle_connect():
|
|
@@ -192,8 +191,11 @@ def handle_init_and_process(data):
|
|
| 192 |
'start_date': data.get('start_date'), 'end_date': data.get('end_date')
|
| 193 |
}
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
df_app = pd.read_csv(io.StringIO(app_data_content))
|
| 199 |
df_quantum = pd.read_csv(io.StringIO(quantum_data_content))
|
|
|
|
| 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():
|
|
|
|
| 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))
|