Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -510,14 +510,15 @@ def generate_device_cards(df):
|
|
| 510 |
return '<p>No valid timestamps available to display.</p>'
|
| 511 |
|
| 512 |
# Calculate device stats
|
| 513 |
-
|
|
|
|
| 514 |
'status': 'last', # Most recent status
|
| 515 |
'timestamp': 'max', # Last log timestamp
|
| 516 |
-
|
| 517 |
-
})
|
| 518 |
|
| 519 |
-
#
|
| 520 |
-
|
|
|
|
| 521 |
|
| 522 |
# Log the aggregated stats
|
| 523 |
logging.info(f"Device stats after aggregation:\n{device_stats.to_string()}")
|
|
|
|
| 510 |
return '<p>No valid timestamps available to display.</p>'
|
| 511 |
|
| 512 |
# Calculate device stats
|
| 513 |
+
# Group by device_id and aggregate
|
| 514 |
+
device_stats = df_clean.groupby('device_id').agg({
|
| 515 |
'status': 'last', # Most recent status
|
| 516 |
'timestamp': 'max', # Last log timestamp
|
| 517 |
+
}).reset_index()
|
|
|
|
| 518 |
|
| 519 |
+
# Add the count of logs per device using size()
|
| 520 |
+
counts = df_clean.groupby('device_id').size().reset_index(name='count')
|
| 521 |
+
device_stats = device_stats.merge(counts, on='device_id')
|
| 522 |
|
| 523 |
# Log the aggregated stats
|
| 524 |
logging.info(f"Device stats after aggregation:\n{device_stats.to_string()}")
|