RathodHarish commited on
Commit
44c9c3e
·
verified ·
1 Parent(s): 81c2d8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
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
- device_stats = df_clean.groupby('device_id', as_index=False).agg({
 
514
  'status': 'last', # Most recent status
515
  'timestamp': 'max', # Last log timestamp
516
- 'device_id': 'count' # Usage count (number of logs)
517
- })
518
 
519
- # Rename the columns directly
520
- device_stats.columns = ['device_id', 'status', 'timestamp', 'count']
 
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()}")