Skip to content

Commit

Permalink
Merge pull request #873 from shankari/improve_monitoring_script
Browse files Browse the repository at this point in the history
Multiple changes to the monitoring script
  • Loading branch information
shankari authored Aug 10, 2022
2 parents ac7669a + 5694df1 commit 32e59c3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bin/monitor/check_participant_status.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import arrow
import emission.core.get_database as edb
import emission.core.wrapper.user as ecwu
import emission.storage.timeseries.timequery as estt

for ue in edb.get_uuid_db().find():
trip_count = edb.get_analysis_timeseries_db().count_documents({"user_id": ue["uuid"], "metadata.key": "analysis/confirmed_trip"})
location_count = edb.get_timeseries_db().count_documents({"user_id": ue["uuid"], "metadata.key": "background/location"})
first_trip = list(edb.get_analysis_timeseries_db().find({"user_id": ue["uuid"], "metadata.key": "analysis/confirmed_trip"}).sort("data.end_ts", 1).limit(1))
first_trip_time = first_trip[0]["data"]["end_fmt_time"] if len(first_trip) > 0 else None
last_trip = list(edb.get_analysis_timeseries_db().find({"user_id": ue["uuid"], "metadata.key": "analysis/confirmed_trip"}).sort("data.end_ts", -1).limit(1))
last_trip_time = last_trip[0]["data"]["end_fmt_time"] if len(last_trip) > 0 else None
print(f"For {ue['user_email']}: Trip count = {trip_count}, location count = {location_count}, last trip = {last_trip_time}")
now = arrow.now()
month_ago = now.shift(months=-1)
last_month_tq = estt.TimeQuery("data.start_ts", month_ago.timestamp, now.timestamp)
if 'computeConfirmed' in vars(ecwu.User):
confirmed_pct, valid_replacement_pct, score = ecwu.User.computeConfirmed(ue["uuid"], last_month_tq)
print(f"For {ue['user_email']}: Trip count = {trip_count}, location count = {location_count}, first trip = {first_trip_time}, last trip = {last_trip_time}, confirmed_pct ({month_ago} -> {now}) = exactly {confirmed_pct:.2f}")
else:
confirmed_count = edb.get_analysis_timeseries_db().count_documents({"user_id": ue["uuid"], "metadata.key": "analysis/confirmed_trip", "data.user_input": {"$ne": {}}})
confirmed_pct = confirmed_count / trip_count
print(f"For {ue['user_email']}: Trip count = {trip_count}, location count = {location_count}, first trip = {first_trip_time}, last trip = {last_trip_time}, confirmed_pct = approximately {confirmed_pct:.2f}")

0 comments on commit 32e59c3

Please sign in to comment.