add task feature

This commit is contained in:
buenosairesam
2025-01-25 07:04:22 -03:00
parent cbb7bf657a
commit 2da2f2641a
14 changed files with 666 additions and 154 deletions

13
Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
FROM python:3.9-alpine
RUN apk add --update
COPY . /src
WORKDIR /src
RUN
EXPOSE 8080
ENTRYPOINT [""]

View File

@@ -1,4 +1,4 @@
sudo systemctl start mongod.service sudo systemctl start mongod.service
. ~/mdir/venvs/deskmeter/bin/activate . ~/mdir/venvs/deskmeter/bin/activate
cd ~/mdir/deskmeter cd ~/mdir/python/deskmeter
python3 dmmain.py python3 dmmain.py

246
dm.err Normal file
View File

@@ -0,0 +1,246 @@
/home/mariano/wdir/def/deskmeter/dmmain.py:54: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()
/home/mariano/wdir/def/deskmeter/dmmain.py:58: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
delta = round((now() - last_switch_time).total_seconds())
/home/mariano/wdir/def/deskmeter/dmmain.py:67: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
last_switch_time = now()

0
dm.out Normal file
View File

65
dmapp/dm.err Normal file
View File

@@ -0,0 +1,65 @@
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5000
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 446-089-149
127.0.0.1 - - [24/Jan/2025 23:13:35] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Jan/2025 23:13:35] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [24/Jan/2025 23:13:37] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Jan/2025 23:13:40] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Jan/2025 23:13:41] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Jan/2025 23:13:42] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Jan/2025 23:13:42] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Jan/2025 23:13:43] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Jan/2025 23:13:44] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Jan/2025 23:13:44] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/Jan/2025 23:13:45] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [25/Jan/2025 03:49:01] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [25/Jan/2025 03:49:04] "GET /weel HTTP/1.1" 404 -
127.0.0.1 - - [25/Jan/2025 03:49:08] "GET /week HTTP/1.1" 200 -
127.0.0.1 - - [25/Jan/2025 03:51:00] "GET /totals HTTP/1.1" 200 -
127.0.0.1 - - [25/Jan/2025 03:54:52] "GET / HTTP/1.1" 200 -
* Detected change in '/home/mariano/wdir/def/deskmeter/dmapp/dmweb/dm.py', reloading
* Restarting with stat
* Debugger is active!
* Debugger PIN: 446-089-149
* Detected change in '/home/mariano/wdir/def/deskmeter/dmapp/dmweb/dm.py', reloading
* Restarting with stat
Traceback (most recent call last):
File "/home/mariano/wdir/def/deskmeter/dmapp/run.py", line 4, in <module>
app = create_app()
^^^^^^^^^^^^
File "/home/mariano/wdir/def/deskmeter/dmapp/dmweb/__init__.py", line 9, in create_app
app.register_blueprint(dm.dmbp)
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/flask/sansio/scaffold.py", line 47, in wrapper_func
return f(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/flask/sansio/app.py", line 595, in register_blueprint
blueprint.register(self, options)
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/flask/sansio/blueprints.py", line 335, in register
deferred(state)
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/flask/sansio/blueprints.py", line 434, in <lambda>
lambda s: s.add_url_rule(
^^^^^^^^^^^^^^^
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/flask/sansio/blueprints.py", line 110, in add_url_rule
self.app.add_url_rule(
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/flask/sansio/scaffold.py", line 47, in wrapper_func
return f(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/flask/sansio/app.py", line 653, in add_url_rule
self.url_map.add(rule_obj)
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/werkzeug/routing/map.py", line 177, in add
rule.bind(self)
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/werkzeug/routing/rules.py", line 581, in bind
self.compile()
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/werkzeug/routing/rules.py", line 726, in compile
self._parts.extend(self._parse_rule(rule))
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/werkzeug/routing/rules.py", line 632, in _parse_rule
convobj = self.get_converter(
^^^^^^^^^^^^^^^^^^^
File "/home/mariano/wdir/venv/dm/lib/python3.12/site-packages/werkzeug/routing/rules.py", line 595, in get_converter
raise LookupError(f"the converter {converter_name!r} does not exist")
LookupError: the converter 'str' does not exist

2
dmapp/dm.out Normal file
View File

@@ -0,0 +1,2 @@
* Serving Flask app 'deskmeter'
* Debug mode: on

View File

@@ -1,68 +1,87 @@
from collections import Counter
import datetime import datetime
from collections import Counter
from pprint import pprint from pprint import pprint
import pytz
from flask import Blueprint, render_template from flask import Blueprint, render_template
from pymongo import MongoClient from pymongo import MongoClient
import pytz
client = MongoClient() client = MongoClient()
db = client.deskmeter db = client.deskmeter
switches = db.switch switches = db.switch
dmbp = Blueprint("deskmeter", __name__, url_prefix="/", template_folder='templates') dmbp = Blueprint("deskmeter", __name__, url_prefix="/", template_folder="templates")
task_file = "/home/mariano/LETRAS/org/task/main"
def extract(line):
if line.rstrip().endswith("*"):
pipe_index = line.find("|")
if pipe_index != -1 and len(line) > pipe_index + 8:
value = line[pipe_index + 1 : pipe_index + 9]
return value
return None
def read_and_extract(file_path):
with open(file_path, "r") as file:
for line in file:
value = extract(line)
if value:
return value
return None
@dmbp.route("/favicon.ico")
def favicon():
return "", 204 # No Content
@dmbp.route("/") @dmbp.route("/")
def index(): @dmbp.route("/<string:task>")
def index(task=None):
""" """
Show total time used in each desktop for today Show total time used in each desktop for today
""" """
if not task:
task = read_and_extract(task_file)
start = datetime.datetime.today().replace(hour=0, if task == "all":
minute=0, task = None
second=0)
end = datetime.datetime.today().replace (hour=23, start = datetime.datetime.today().replace(hour=0, minute=0, second=0)
minute=59,
second=59)
rows = get_period_totals( local_date(start), end = datetime.datetime.today().replace(hour=23, minute=59, second=59)
local_date(end))
return render_template("pages.html", rows=rows) rows = get_period_totals(local_date(start), local_date(end), task)
return render_template("main.html", rows=rows)
@dmbp.route("/day/<int:month>/<int:day>") @dmbp.route("/day/<int:month>/<int:day>")
def oneday(month,day): def oneday(month, day):
start = datetime.datetime(2020, month, day).replace(hour=0, minute=0, second=0)
start = datetime.datetime(2020, month, day).replace(hour=0, end = datetime.datetime(2020, month, day).replace(hour=23, minute=59, second=59)
minute=0,
second=0)
end = datetime.datetime(2020, month, day).replace (hour=23, rows = get_period_totals(local_date(start), local_date(end))
minute=59,
second=59)
rows = get_period_totals( local_date(start),
local_date(end))
return render_template("pages.html", rows=rows) return render_template("pages.html", rows=rows)
@dmbp.route("/period/<start>/<end>") @dmbp.route("/period/<start>/<end>")
def period(start,end): def period(start, end):
start = datetime.datetime(*map(int, start.split("-"))).replace(
hour=0, minute=0, second=0
)
start = datetime.datetime(*map(int, start.split("-"))).replace(hour=0, end = datetime.datetime(*map(int, end.split("-"))).replace(
minute=0, hour=23, minute=59, second=59
second=0) )
end = datetime.datetime(*map(int, end.split("-"))).replace (hour=23, rows = get_period_totals(local_date(start), local_date(end))
minute=59,
second=59)
rows = get_period_totals( local_date(start),
local_date(end))
return render_template("pages.html", rows=rows) return render_template("pages.html", rows=rows)
@@ -70,48 +89,59 @@ def period(start,end):
@dmbp.route("/totals") @dmbp.route("/totals")
def totals(): def totals():
""" """
Show total time used in each desktop for all time Show total time used in each desktop for all time
""" """
pipe = [{'$group': {'_id':"$workspace",'totals': {'$sum': '$delta'}}}, pipe = [
{'$sort': { "_id": 1}}] {"$group": {"_id": "$workspace", "totals": {"$sum": "$delta"}}},
{"$sort": {"_id": 1}},
]
rows = [] rows = []
for total in switches.aggregate(pipeline=pipe): for total in switches.aggregate(pipeline=pipe):
rows.append( {"ws" : total["_id"], rows.append(
"total": str(datetime.timedelta(seconds=total["totals"]))}) {
"ws": total["_id"],
"total": str(datetime.timedelta(seconds=total["totals"])),
}
)
return render_template("pages.html", rows=rows) return render_template("pages.html", rows=rows)
def get_period_totals(start, end): def get_period_totals(start, end, task=None):
""" """
TODOs: refactor to have available the ws array and the active ws function in order to remove TODOs: refactor to have available the ws array and the active ws function in order to remove
the delta = 0 thing the delta = 0 thing
refactor to pass in the timezone and make the variable names clearer refactor to pass in the timezone and make the variable names clearer
""" """
task_query = {"task": task} if task else {}
queries = { queries = {
"period" : {"date": {"$gt" : start, "$lt" : end }}, "period": {"date": {"$gt": start, "$lt": end}},
"previous_doc" : {"date" : {"$lt" : start }} "previous_doc": {"date": {"$lt": start}},
#"next_doc" : {"date":{"$lt":start}} "task": task_query
# "next_doc" : {"date":{"$lt":start}}
} }
length = switches.count_documents(queries["period"]) length = switches.count_documents(queries["period"])
docs = switches.find(queries["period"]).sort([("date", 1)]) docs = switches.find(queries["period"]).sort([("date", 1)])
if not length: if not length:
return [{"ws": "No Data", "total": ""}] return [{"ws": "No Data", "total": ""}]
#next_doc = switches.find_one(queries["next_doc"]) # next_doc = switches.find_one(queries["next_doc"])
last_doc = docs[length-1] last_doc = docs[length - 1]
first_date = local_date(docs[0]["date"], True) first_date = local_date(docs[0]["date"], True)
last_date = local_date(last_doc["date"], True) last_date = local_date(last_doc["date"], True)
pipe = [ {'$match': queries["period"] }, match_query = {**queries["period"], **queries["task"]}
{'$group': { '_id':"$workspace",'totals': {'$sum': '$delta'}}}, pipe = [
{'$sort': { "_id": 1}}] {"$match": match_query},
{"$group": {"_id": "$workspace", "totals": {"$sum": "$delta"}}},
{"$sort": {"_id": 1}},
]
pre_rows = Counter({}) pre_rows = Counter({})
for total in switches.aggregate(pipeline=pipe): for total in switches.aggregate(pipeline=pipe):
@@ -119,45 +149,75 @@ def get_period_totals(start, end):
time_corrections = [] time_corrections = []
if first_date > start: if first_date > start:
#TODO if its the first record it fails write test # TODO if its the first record it fails write test
try: try:
previous_doc = switches.find(queries["previous_doc"]).sort([("date", -1)]).limit(1)[0] previous_doc = (
time_corrections.append(Counter({previous_doc["workspace"] : split_entry(previous_doc, start)})) switches.find(queries["previous_doc"]).sort([("date", -1)]).limit(1)[0]
)
time_corrections.append(
Counter({previous_doc["workspace"]: split_entry(previous_doc, start)})
)
except IndexError: except IndexError:
pass pass
now = local_date(datetime.datetime.now()) now = local_date(datetime.datetime.now())
if task != read_and_extract(task_file):
now = local_date(last_doc["date"]) - datetime.timedelta(hours=3)
if end > now: if end > now:
time_corrections.append(Counter({ last_doc["workspace"] : split_entry(last_doc, now, after=False)})) time_corrections.append(
Counter({last_doc["workspace"]: split_entry(last_doc, now, after=False)})
)
if end > last_date and now > end: if end > last_date and now > end:
time_corrections.append(Counter({ last_doc["workspace"] : split_entry(last_doc, end, after=False)})) time_corrections.append(
Counter({last_doc["workspace"]: split_entry(last_doc, end, after=False)})
)
for correction in time_corrections: for correction in time_corrections:
pre_rows += correction pre_rows += correction
#TODO _1 remove # TODO _1 remove
#day = 0 # day = 0
rows = [] rows = []
active_vs_idle = {"active": 0, "idle": 0}
for ws, total in pre_rows.items(): for ws, total in pre_rows.items():
#TODO _1 remove # parche por comportamiento weird
#day += total if task and ws == "Think":
rows.append( {"ws": ws, total -= 1080
"total" : convert_timedelta(datetime.timedelta(seconds=total)) })
#TODO _1 remove if ws in ["Think", "Plan", "Work"]:
#rows.append({"ws":"sum","total": day}) active_vs_idle["active"] += total
if ws in ["Away", "Other"]:
active_vs_idle["idle"] += total
rows.append(
{"ws": ws, "total": convert_timedelta(datetime.timedelta(seconds=total))}
)
if task == None:
task = "all"
active_vs_idle["active"] = convert_timedelta(
datetime.timedelta(seconds=active_vs_idle["active"])
)
active_vs_idle["idle"] = convert_timedelta(
datetime.timedelta(seconds=active_vs_idle["idle"])
)
rows.append({"ws": "Active", "total": active_vs_idle["active"]})
rows.append({"ws": "Idle", "total": active_vs_idle["idle"]})
# TODO _1 remove
# rows.append({"ws":"sum","total": day})
return rows return rows
def split_entry(entry, split_time, after=True): def split_entry(entry, split_time, after=True):
""" """
entry must have a date an number entry must have a date an number
split_time must be timezone aware split_time must be timezone aware
after bolean to return the time after the split time after bolean to return the time after the split time
""" """
first_half = round((split_time - local_date(entry["date"], True)).total_seconds()) first_half = round((split_time - local_date(entry["date"], True)).total_seconds())
last_half = entry["delta"] - first_half last_half = entry["delta"] - first_half
@@ -178,5 +238,5 @@ def convert_timedelta(duration):
days, seconds = duration.days, duration.seconds days, seconds = duration.days, duration.seconds
hours = days * 24 + seconds // 3600 hours = days * 24 + seconds // 3600
minutes = (seconds % 3600) // 60 minutes = (seconds % 3600) // 60
seconds = (seconds % 60) seconds = seconds % 60
return "{}:{:02d}:{:02d}".format(hours, minutes, seconds) return "{}:{:02d}:{:02d}".format(hours, minutes, seconds)

View File

@@ -1,125 +1,140 @@
import calendar
from datetime import datetime from datetime import datetime
from pprint import pprint from pprint import pprint
from flask import Blueprint, render_template
import pytz import pytz
import calendar
from dmweb.dm import dmbp, get_period_totals, local_date from dmweb.dm import dmbp, get_period_totals, local_date
from flask import Blueprint, render_template
class DMHTMLCalendar(calendar.HTMLCalendar): class DMHTMLCalendar(calendar.HTMLCalendar):
# def formatmonth(self, theyear, themonth, withyear=True): # def formatmonth(self, theyear, themonth, withyear=True):
# self.dmmonth = themonth # self.dmmonth = themonth
# super().formatmonth(self, theyear, themonth) # super().formatmonth(self, theyear, themonth)
def setcalmonth(self, month): def setcalmonth(self, month):
self.dmmonth = month self.dmmonth = month
def setcalyear(self, year): def setcalyear(self, year):
self.dmyear = year self.dmyear = year
def oneday(self,month,day): def settask(self, task):
self.task = task
def oneday(self, month, day):
current_year = datetime.today().year current_year = datetime.today().year
start = datetime(self.dmyear, month, day).replace(hour=0, start = datetime(self.dmyear, month, day).replace(hour=0, minute=0, second=0)
minute=0,
second=0)
end = datetime(self.dmyear, month, day).replace (hour=23, end = datetime(self.dmyear, month, day).replace(hour=23, minute=59, second=59)
minute=59,
second=59)
rows = get_period_totals( local_date(start), rows = get_period_totals(local_date(start), local_date(end), self.task)
local_date(end))
returnstr = "<table class='totaltable'>" returnstr = "<table class='totaltable'>"
for row in rows: for row in rows:
returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(row["ws"],row["total"]) returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(
row["ws"], row["total"]
)
returnstr += "</table>" returnstr += "</table>"
return returnstr return returnstr
def oneweek(self,month,week):
def oneweek(self, month, week):
start_day = None start_day = None
end_day = None end_day = None
for (d, wd) in week: for d, wd in week:
if d == 0: if d == 0:
continue continue
else: else:
start_day = d start_day = d
break break
for d, wd in reversed(week):
for (d, wd) in reversed(week):
if d == 0: if d == 0:
continue continue
else: else:
end_day = d end_day = d
break break
start = datetime(self.dmyear, month, start_day).replace(
hour=0, minute=0, second=0
)
start = datetime(self.dmyear, month, start_day).replace(hour=0, end = datetime(self.dmyear, month, end_day).replace(
minute=0, hour=23, minute=59, second=59
second=0) )
end = datetime(self.dmyear, month, end_day).replace (hour=23, rows = get_period_totals(local_date(start), local_date(end))
minute=59,
second=59)
rows = get_period_totals( local_date(start),
local_date(end))
returnstr = "<table class='totaltable'>" returnstr = "<table class='totaltable'>"
for row in rows: for row in rows:
returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(row["ws"],row["total"]) returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(
row["ws"], row["total"]
)
returnstr += "</table>" returnstr += "</table>"
return returnstr return returnstr
def formatweekheader(self): def formatweekheader(self):
""" """
Return a header for a week as a table row. Return a header for a week as a table row.
""" """
s = ''.join(self.formatweekday(i) for i in self.iterweekdays()) s = "".join(self.formatweekday(i) for i in self.iterweekdays())
s += "<td>Week Totals</td>" s += "<td>Week Totals</td>"
return '<tr>%s</tr>' % s return "<tr>%s</tr>" % s
def formatweek(self, theweek): def formatweek(self, theweek):
""" """
Return a complete week as a table row. Return a complete week as a table row.
""" """
s = ''.join(self.formatday(d, wd) for (d, wd) in theweek) s = "".join(self.formatday(d, wd) for (d, wd) in theweek)
s += "<td>{}</td>".format(self.oneweek(self.dmmonth, theweek)) s += "<td>{}</td>".format(self.oneweek(self.dmmonth, theweek))
return '<tr>%s</tr>' % s return "<tr>%s</tr>" % s
def formatday(self, day, weekday): def formatday(self, day, weekday):
""" """
Return a day as a table cell. Return a day as a table cell.
""" """
if day == 0: if day == 0:
return '<td class="noday">&nbsp;</td>' # day outside month return '<td class="noday">&nbsp;</td>' # day outside month
else: else:
return '<td class="%s">%s</td>' % (self.cssclasses[weekday], self.oneday(self.dmmonth, day)) return '<td class="%s">%s</td>' % (
self.cssclasses[weekday],
self.oneday(self.dmmonth, day),
)
@dmbp.route("/month")
@dmbp.route("/month/<int:month>")
@dmbp.route("/month/<int:month>/<int:year>")
@dmbp.route("/month/task/<string:task>")
@dmbp.route("/month/<int:month>/task/<string:task>")
@dmbp.route("/month/<int:month>/<int:year>/task/<string:task>")
def month(month=None, year=None, task=None):
usemonth = datetime.today().month
useyear = datetime.today().year
@dmbp.route("/calendar") if month:
@dmbp.route("/calendar/<int:month>") usemonth = month
def calmain(month=None):
if year:
useyear = year
cal = DMHTMLCalendar(calendar.SATURDAY)
cal.settask(None)
if task:
cal.settask(task)
cal.setcalmonth(usemonth)
cal.setcalyear(useyear)
return render_template("calendar.html", content=cal.formatmonth(useyear, usemonth))
@dmbp.route("/week")
@dmbp.route("/week/<int:week>")
def week(month=None):
usemonth = datetime.today().month usemonth = datetime.today().month
useyear = datetime.today().year useyear = datetime.today().year
if month: if month:
@@ -129,6 +144,5 @@ def calmain(month=None):
cal.setcalmonth(usemonth) cal.setcalmonth(usemonth)
cal.setcalyear(useyear) cal.setcalyear(useyear)
return render_template("calendar.html", content=cal.formatmonth(useyear,usemonth))
return render_template("calendar.html", content=cal.formatmonth(useyear, usemonth))

View File

@@ -0,0 +1,44 @@
<html>
<head>
<!-- <link rel="stylesheet" href="{{ url_for('static', filename='styles/dm.css') }}"> -->
{% block head %}
{% endblock %}
<style>
body
{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh; /* This ensures that the container takes the full height of the viewport */
margin: 0; /* Remove default margin */
}
table {
font-size: 84pt
}
td {
padding-right: 100px;
}
</style>
</head>
<body>
<!-- agregar función que me diga cuanto tiempo hace que esta activo el escritorio
(calcular el delta con el ultimo switch y pasarlo a mm:ss) -->
{% block content %}
<table>
{% for row in rows %}
<tr>
<td>{{ row["ws"] }}</td>
<td>{{ row["total"] }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}
</body>
</html>

View File

@@ -1,10 +1,10 @@
import subprocess
import os
import datetime import datetime
import os
import subprocess
import time import time
from pprint import pprint
from pymongo import MongoClient from pymongo import MongoClient
from pprint import pprint
client = MongoClient() client = MongoClient()
@@ -14,21 +14,49 @@ db = client.deskmeter
switches = db.switch switches = db.switch
dailies = db.daily dailies = db.daily
desktops = ("Work",
"Work", desktops = ("Plan", "Think", "Work", "Other", "Away")
"Create",
"Other",
"Learn",
"Challenges",
"Idle")
unlabeled = "Idle" task_file = "/home/mariano/LETRAS/org/task/main"
# desktops = ("Admin",
# "Learn",
# "Tasks",
# "Other",
# "Text",
# "Video",
# "Away")
unlabeled = "Away"
def extract(line):
if line.rstrip().endswith("*"):
pipe_index = line.find("|")
if pipe_index != -1 and len(line) > pipe_index + 8:
value = line[pipe_index + 1 : pipe_index + 9]
return value
return None
def read_and_extract(file_path):
with open(file_path, "r") as file:
for line in file:
value = extract(line)
if value:
return value
return None
def active_workspace(): def active_workspace():
workspaces = (
workspaces = subprocess.check_output(["wmctrl", "-d"]) \ subprocess.check_output(["wmctrl", "-d"])
.decode("utf-8").strip("\n").split("\n") .decode("utf-8")
.strip("\n")
.split("\n")
)
for workspace in workspaces: for workspace in workspaces:
if workspace[3] == "*": if workspace[3] == "*":
@@ -41,19 +69,28 @@ def desktop(workspace_index):
except IndexError: except IndexError:
return unlabeled return unlabeled
current_workspace = active_workspace() current_workspace = active_workspace()
current_task = read_and_extract(task_file)
last_switch_time = now() last_switch_time = now()
while True: while True:
if current_workspace != active_workspace(): if current_workspace != active_workspace():
delta = round((now() - last_switch_time).total_seconds())
# task = ""
# if current_workspace in [0, 1, 2]:
switch = {
"workspace": desktop(current_workspace),
"date": last_switch_time,
"delta": delta,
"task": current_task,
}
delta = round((now() - last_switch_time ).total_seconds())
switch = { "workspace": desktop(current_workspace),
"date": last_switch_time,
"delta": delta }
switches.insert_one(switch) switches.insert_one(switch)
current_workspace = active_workspace() current_workspace = active_workspace()
current_task = read_and_extract(task_file)
last_switch_time = now() last_switch_time = now()
time.sleep(1) time.sleep(2)

View File

@@ -1,4 +1,4 @@
sudo systemctl start mongod.service sudo systemctl start mongod.service
. ~/mdir/venvs/deskmeter/bin/activate . ~/mdir/venvs/deskmeter/bin/activate
cd ~/mdir/deskmeter/dmapp cd ~/mdir/python/deskmeter/dmapp
python3 run.py python3 run.py

View File

@@ -0,0 +1,20 @@
app:
build: .
command: python -u app.py
ports:
- "5000:5000"
volumes:
- .:/app
links:
- db
db:
image: mongo:latest
hostname: test_mongodb
environment:
- MONGO_INITDB_DATABASE=<mongo_database>
- MONGO_INITDB_ROOT_USERNAME=<mongo_username>
- MONGO_INITDB_ROOT_PASSWORD=<mongo_password>
volumes:
- ./init-db.js:/docker-entrypoint-initdb.d/init-db.js:ro
ports:
- 27017:27017

3
requirements.txt Normal file
View File

@@ -0,0 +1,3 @@
pymongo
flask
pytz

8
testdbus.py Normal file
View File

@@ -0,0 +1,8 @@
def active_workspace():
workspaces = subprocess.check_output(["wmctrl", "-d"]) \
.decode("utf-8").strip("\n").split("\n")
for workspace in workspaces:
if workspace[3] == "*":
return int(workspace[0])