added imperfect today totals

This commit is contained in:
Mariano Ramon
2020-04-12 08:20:00 -03:00
parent 2f72244972
commit 5402b8854b
4 changed files with 93 additions and 6 deletions

View File

@@ -1,7 +1,65 @@
from flask import Blueprint from flask import Blueprint, render_template
from pymongo import MongoClient
from pprint import pprint
import datetime
import pytz
client = MongoClient()
db = client.deskmeter
switches = db.switch
dmbp = Blueprint("deskmeter", __name__, url_prefix="/", template_folder='templates')
dmbp = Blueprint("deskmeter", __name__, url_prefix="/")
@dmbp.route("/") @dmbp.route("/")
def index(): def index():
return "Hello, World!" """
Show total time used in each desktop for today
"""
bsas = pytz.timezone("Etc/GMT-0")
start = datetime.datetime.today().replace(hour=0,
minute=0,
second=0,
tzinfo=bsas)
end = datetime.datetime.today().replace (hour=23,
minute=59,
second=59,
tzinfo=bsas)
pipe = [ {'$match': { 'date' : {"$gte": start, "$lt": end}} },
{'$group': { '_id':"$workspace",'totals': {'$sum': '$delta'}}},
{'$sort': { "_id": 1}}]
rows = []
for total in switches.aggregate(pipeline=pipe):
rows.append( {"ws" : total["_id"],
"total": str(datetime.timedelta(seconds=total["totals"]))})
return render_template("pages.html", rows=rows)
@dmbp.route("/totals")
def totals():
"""
Show total time used in each desktop for all time
"""
pipe = [{'$group': {'_id':"$workspace",'totals': {'$sum': '$delta'}}},
{'$sort': { "_id": 1}}]
rows = []
for total in switches.aggregate(pipeline=pipe):
rows.append( {"ws" : total["_id"],
"total": str(datetime.timedelta(seconds=total["totals"]))})
print(rows)
return render_template("pages.html", rows=rows)

View File

@@ -0,0 +1,14 @@
<html>
<head>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>

View File

@@ -0,0 +1,16 @@
{% extends 'layout.html' %}
{% block content %}
<table>
{% for row in rows %}
<tr>
<td>{{ row["ws"] }}</td>
<td>{{ row["total"] }}</td>
</tr>
{% endfor %}
</table>
{% endblock content %}

View File

@@ -18,7 +18,8 @@ desktops = ("Work",
"Browse", "Browse",
"Write", "Write",
"Learn", "Learn",
"Idle") "Idle",
"Self")
unlabeled = "Other" unlabeled = "Other"
@@ -39,8 +40,6 @@ def desktop(workspace_index):
except IndexError: except IndexError:
return unlabeled return unlabeled
current_workspace = active_workspace() current_workspace = active_workspace()
last_switch_time = now() last_switch_time = now()