From 69d16688e68a0c1f30cc3326ec29c4c5b0a5995d Mon Sep 17 00:00:00 2001 From: Mariano Ramon Date: Tue, 14 Apr 2020 05:10:33 -0300 Subject: [PATCH] splited functions a bit --- dmapp/dmweb/dm.py | 73 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/dmapp/dmweb/dm.py b/dmapp/dmweb/dm.py index 339f246..c4beff4 100644 --- a/dmapp/dmweb/dm.py +++ b/dmapp/dmweb/dm.py @@ -18,31 +18,23 @@ def index(): 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) - + second=0) end = datetime.datetime.today().replace (hour=23, minute=59, - second=59, - tzinfo=bsas) + second=59) + + rows = get_period_totals(start, end) + + return pprint(rows) + #return render_template("pages.html", rows=rows) + - 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) @@ -52,6 +44,30 @@ def totals(): Show total time used in each desktop for all time """ + """ + split times on selected period + cuantos segundos de diferencia desde el primer resultado al comienzo del periodo seleccionado + + TODO despues: calcular el delta del start al end y pedir recurrentemente esa franja para atras hasta que alguno de los registros supere la fecha/hora seleccionada + tambien puede ser ir incrementando el tamaƱo del bloque anterior a pedir hasta lograrlo + + cual es el ultimo registro del periodo anterior + + el delta es mayor a los segundos faltantes? + SI? PEOLA + NO? Bu, bueno. + LO VEMOS DESPUES caso edge de no registrado + cuantos segundos faltan del final del periodo con el ultimo resultado + ME CHUPA UN GUEVO (por ahora) siempre es el start del ultimo + resultado hasta que termina el dia + """ + + + + + + + pipe = [{'$group': {'_id':"$workspace",'totals': {'$sum': '$delta'}}}, {'$sort': { "_id": 1}}] @@ -61,5 +77,26 @@ def totals(): rows.append( {"ws" : total["_id"], "total": str(datetime.timedelta(seconds=total["totals"]))}) - print(rows) - return render_template("pages.html", rows=rows) \ No newline at end of file + + return render_template("pages.html", rows=rows) + + +def get_period_totals(start,end): + + bsas = pytz.timezone("Etc/GMT-3") + + lstart = start.replace(tzinfo=bsas) + lend = end.replace(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(total) + + # rows.append( {"ws" : total["_id"], + # "total": str(datetime.timedelta(seconds=total["totals"]))}) + + return rows