Skip to content

Commit f90a824

Browse files
murr2kclaude
andcommitted
fix: Correct 24h stats API by grouping before aggregation
- Add |> group() before min/max/mean to aggregate across all series - Without grouping, queries returned per-device_mac results giving wrong values - Update cost rate from $0.12 to $0.1172 to match Grafana dashboard Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 21c36a9 commit f90a824

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

fly/eagle-monitor/app.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,28 +440,28 @@ def get_stats():
440440
|> filter(fn: (r) => r["_field"] == "power_w")
441441
'''
442442

443-
# Get min
444-
min_query = query + '|> min()'
443+
# Get min (group() aggregates across all device_mac series)
444+
min_query = query + '|> group() |> min()'
445445
min_result = query_api.query(org=INFLUXDB_ORG, query=min_query)
446446
if min_result and min_result[0].records:
447447
result['min_24h'] = min_result[0].records[0].get_value()
448-
448+
449449
# Get max
450-
max_query = query + '|> max()'
450+
max_query = query + '|> group() |> max()'
451451
max_result = query_api.query(org=INFLUXDB_ORG, query=max_query)
452452
if max_result and max_result[0].records:
453453
result['max_24h'] = max_result[0].records[0].get_value()
454-
454+
455455
# Get mean
456-
avg_query = query + '|> mean()'
456+
avg_query = query + '|> group() |> mean()'
457457
avg_result = query_api.query(org=INFLUXDB_ORG, query=avg_query)
458458
if avg_result and avg_result[0].records:
459459
result['avg_24h'] = avg_result[0].records[0].get_value()
460460

461-
# Calculate cost (assuming $0.12 per kWh)
461+
# Calculate cost using avg power * hours (rate matches Grafana dashboard)
462462
if result['avg_24h'] > 0:
463463
kwh = (result['avg_24h'] / 1000) * hours # Convert W to kW and multiply by hours
464-
result['cost_24h'] = round(kwh * 0.12, 2) # $0.12 per kWh
464+
result['cost_24h'] = round(kwh * 0.1172, 2) # $0.1172 per kWh
465465

466466
except Exception as e:
467467
logger.error(f"Error querying InfluxDB: {e}")

0 commit comments

Comments
 (0)