added imperfect today totals
This commit is contained in:
@@ -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("/")
|
||||
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)
|
||||
14
dmapp/dmweb/templates/layout.html
Normal file
14
dmapp/dmweb/templates/layout.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
16
dmapp/dmweb/templates/pages.html
Normal file
16
dmapp/dmweb/templates/pages.html
Normal 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 %}
|
||||
Reference in New Issue
Block a user