splited functions a bit

This commit is contained in:
Mariano Ramon
2020-04-14 05:10:33 -03:00
parent 5402b8854b
commit 69d16688e6

View File

@@ -18,31 +18,23 @@ def index():
Show total time used in each desktop for today Show total time used in each desktop for today
""" """
bsas = pytz.timezone("Etc/GMT-0")
start = datetime.datetime.today().replace(hour=0, start = datetime.datetime.today().replace(hour=0,
minute=0, minute=0,
second=0, second=0)
tzinfo=bsas)
end = datetime.datetime.today().replace (hour=23, end = datetime.datetime.today().replace (hour=23,
minute=59, minute=59,
second=59, second=59)
tzinfo=bsas)
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 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'}}}, pipe = [{'$group': {'_id':"$workspace",'totals': {'$sum': '$delta'}}},
{'$sort': { "_id": 1}}] {'$sort': { "_id": 1}}]
@@ -61,5 +77,26 @@ def totals():
rows.append( {"ws" : total["_id"], rows.append( {"ws" : total["_id"],
"total": str(datetime.timedelta(seconds=total["totals"]))}) "total": str(datetime.timedelta(seconds=total["totals"]))})
print(rows)
return render_template("pages.html", rows=rows) 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