Update app/routers/datasources.py
Browse files- app/routers/datasources.py +10 -1
app/routers/datasources.py
CHANGED
|
@@ -109,7 +109,16 @@ async def create_source_json(
|
|
| 109 |
print(f"[api/json] 🎯 Industry detected: {industry} ({confidence:.1%})")
|
| 110 |
|
| 111 |
# 3. 🎯 Prepare preview for real-time broadcast
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
# 4. 📡 Broadcast to connected dashboards
|
| 115 |
await sio.emit(
|
|
|
|
| 109 |
print(f"[api/json] 🎯 Industry detected: {industry} ({confidence:.1%})")
|
| 110 |
|
| 111 |
# 3. 🎯 Prepare preview for real-time broadcast
|
| 112 |
+
|
| 113 |
+
# Convert DataFrame to JSON-safe format
|
| 114 |
+
preview_df = df.head(3).copy()
|
| 115 |
+
for col in preview_df.columns:
|
| 116 |
+
if pd.api.types.is_datetime64_any_dtype(preview_df[col]):
|
| 117 |
+
preview_df[col] = preview_df[col].dt.strftime('%Y-%m-%d %H:%M:%S')
|
| 118 |
+
elif pd.api.types.is_timedelta64_dtype(preview_df[col]):
|
| 119 |
+
preview_df[col] = preview_df[col].astype(str)
|
| 120 |
+
|
| 121 |
+
preview_rows = preview_df.to_dict("records") if not preview_df.empty else []
|
| 122 |
|
| 123 |
# 4. 📡 Broadcast to connected dashboards
|
| 124 |
await sio.emit(
|