feat(grafana): show proved active app work
This commit is contained in:
@@ -60,6 +60,7 @@ def build_lines_for_day(host, report_date):
|
||||
rows = WORKTIME.aggregate_rows(events, bounds["start"], bounds["end"], host)
|
||||
hourly_rows = WORKTIME.aggregate_hourly_rows(events, bounds["start"], bounds["end"], host)
|
||||
summary = WORKTIME.build_report_summary(rows)
|
||||
true_active_apps = WORKTIME.build_true_active_apps(host, report_date)
|
||||
|
||||
lines = []
|
||||
daily_ts = _timestamp_ns(bounds["start"])
|
||||
@@ -118,6 +119,28 @@ def build_lines_for_day(host, report_date):
|
||||
daily_ts,
|
||||
)
|
||||
)
|
||||
|
||||
for app in true_active_apps:
|
||||
lines.append(
|
||||
_line(
|
||||
"aw_true_active_app_daily",
|
||||
{
|
||||
"host": host,
|
||||
"application": app["application"],
|
||||
"report_date": report_date.isoformat(),
|
||||
},
|
||||
{
|
||||
"proved_work_seconds": int(app.get("proved_work_seconds", 0) or 0),
|
||||
"evidence_events": int(app.get("evidence_events", 0) or 0),
|
||||
"proved_work_human": app.get("proved_work_human", ""),
|
||||
"proved_work_hhmm": app.get("proved_work_hhmm", ""),
|
||||
"last_action": app.get("last_action", ""),
|
||||
"last_action_local": app.get("last_action_local", ""),
|
||||
"last_action_utc": app.get("last_action_utc", ""),
|
||||
},
|
||||
daily_ts,
|
||||
)
|
||||
)
|
||||
return [line for line in lines if line]
|
||||
|
||||
|
||||
|
||||
@@ -28,8 +28,40 @@ def test_build_lines_for_day_emits_daily_hourly_and_summary(monkeypatch):
|
||||
]
|
||||
|
||||
monkeypatch.setattr(MODULE.WORKTIME, "fetch_events_for_date", lambda host, report_date: (bounds, events))
|
||||
monkeypatch.setattr(MODULE.WORKTIME, "build_true_active_apps", lambda host, report_date: [])
|
||||
lines = MODULE.build_lines_for_day("SHARKON2025", date(2026, 5, 14))
|
||||
|
||||
assert any(line.startswith("aw_rdp_worktime_daily,") for line in lines)
|
||||
assert any(line.startswith("aw_rdp_worktime_hourly,") for line in lines)
|
||||
assert any(line.startswith("aw_rdp_worktime_summary_daily,") for line in lines)
|
||||
|
||||
|
||||
def test_build_lines_for_day_emits_true_active_app_daily(monkeypatch):
|
||||
bounds = MODULE.WORKTIME.get_report_bounds(date(2026, 5, 14))
|
||||
|
||||
monkeypatch.setattr(MODULE.WORKTIME, "fetch_events_for_date", lambda host, report_date: (bounds, []))
|
||||
monkeypatch.setattr(
|
||||
MODULE.WORKTIME,
|
||||
"build_true_active_apps",
|
||||
lambda host, report_date: [
|
||||
{
|
||||
"application": "1С",
|
||||
"proved_work_seconds": 2040,
|
||||
"proved_work_human": "34 мин",
|
||||
"proved_work_hhmm": "00:34",
|
||||
"last_action": "1С:Предприятие",
|
||||
"last_action_local": "09:42",
|
||||
"last_action_utc": "2026-05-14T06:42:00Z",
|
||||
"evidence_events": 7,
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
lines = MODULE.build_lines_for_day("SHARKON2025", date(2026, 5, 14))
|
||||
|
||||
true_active_line = next(line for line in lines if line.startswith("aw_true_active_app_daily,"))
|
||||
assert "application=1С" in true_active_line
|
||||
assert "report_date=2026-05-14" in true_active_line
|
||||
assert "proved_work_seconds=2040i" in true_active_line
|
||||
assert "evidence_events=7i" in true_active_line
|
||||
assert 'last_action="1С:Предприятие"' in true_active_line
|
||||
|
||||
Reference in New Issue
Block a user