updated dmmain

This commit is contained in:
buenosairesam
2025-02-02 09:15:24 -03:00
parent 6db519ed62
commit ab31c03bf4

View File

@@ -5,10 +5,14 @@ import time
from pprint import pprint from pprint import pprint
from pymongo import MongoClient from pymongo import MongoClient
from zoneinfo import ZoneInfo
client = MongoClient() client = MongoClient()
now = datetime.datetime.utcnow
def now():
return datetime.datetime.now(ZoneInfo("America/Argentina/Buenos_Aires"))
db = client.deskmeter db = client.deskmeter
switches = db.switch switches = db.switch
@@ -72,25 +76,41 @@ def desktop(workspace_index):
current_workspace = active_workspace() current_workspace = active_workspace()
current_task = read_and_extract(task_file) current_task = read_and_extract(task_file)
last_switch_time = now() last_switch_time = now()
while True: switch = {
if current_workspace != active_workspace(): "workspace": desktop(current_workspace),
delta = round((now() - last_switch_time).total_seconds()) "date": now(),
"delta": 0,
"task": current_task,
}
switches.insert_one(switch)
while True:
current_task = read_and_extract(task_file)
current_workspace = active_workspace()
last_doc = switches.find_one(sort=[("_id", -1)])
if (
last_doc["workspace"] == desktop(current_workspace)
and last_doc["task"] == current_task
):
delta = round((now() - last_switch_time).total_seconds())
switches.update_one(
{"_id": last_doc["_id"]}, {"$set": {"delta": delta, "task": current_task}}
)
else:
time.sleep(2)
current_workspace = active_workspace()
# task = ""
# if current_workspace in [0, 1, 2]:
switch = { switch = {
"workspace": desktop(current_workspace), "workspace": desktop(current_workspace),
"date": last_switch_time, "date": now(),
"delta": delta, "delta": 0,
"task": current_task, "task": current_task,
} }
switches.insert_one(switch) switches.insert_one(switch)
current_workspace = active_workspace()
current_task = read_and_extract(task_file)
last_switch_time = now() last_switch_time = now()
time.sleep(2) time.sleep(2)