today stats

This commit is contained in:
Administrator 2022-10-07 01:08:58 +03:00
parent 51968a1c8f
commit fa8868f715
2 changed files with 12 additions and 0 deletions

View File

@ -49,5 +49,13 @@ class Events:
cw.writerow(row)
return si.getvalue()
def today_json(self):
values = self.collection.find({"date": self.today})
values = {value['event']: value['count'] for value in values}
json_data = {}
for metric in self.metrics:
json_data[metric] = values.get(metric) or 0
return json_data
events = Events()

View File

@ -28,4 +28,8 @@ def run():
output.headers["Content-type"] = "text/csv"
return output
@app.route('/stats/today', methods=["GET"])
def today():
return events.today_json()
app.run(host="0.0.0.0", port=8000)