unmodified changes from long ago commited to kickstart deskmeter again
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
from flask import Blueprint, render_template, jsonify
|
||||
|
||||
from .get_period_times import get_period_totals, task_or_none, timezone, get_work_period_totals, get_current_task_info, convert_seconds, get_task_time_seconds
|
||||
|
||||
@@ -33,11 +33,33 @@ def index(task=None):
|
||||
if total_seconds > 0:
|
||||
current_task_time = convert_seconds(total_seconds)
|
||||
|
||||
print(rows)
|
||||
|
||||
return render_template("main.html", rows=rows, current_task_path=current_task_path, current_task_time=current_task_time, auto_refresh=True)
|
||||
|
||||
|
||||
@dmbp.route("/api/today")
|
||||
@dmbp.route("/api/today/<string:task>")
|
||||
def api_today(task=None):
|
||||
"""
|
||||
HTML fragment API endpoint for today's data (for AJAX updates)
|
||||
"""
|
||||
task = task_or_none(task)
|
||||
|
||||
start = datetime.today().replace(hour=0, minute=0, second=0, tzinfo=timezone)
|
||||
end = datetime.today().replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||
|
||||
rows = get_period_totals(start, end, task)
|
||||
|
||||
# Get current task info
|
||||
current_task_id, current_task_path = get_current_task_info()
|
||||
current_task_time = None
|
||||
if current_task_id:
|
||||
total_seconds = get_task_time_seconds(start, end, current_task_id)
|
||||
if total_seconds > 0:
|
||||
current_task_time = convert_seconds(total_seconds)
|
||||
|
||||
return render_template("main_content.html", rows=rows, current_task_path=current_task_path, current_task_time=current_task_time)
|
||||
|
||||
|
||||
@dmbp.route("/day/<int:month>/<int:day>")
|
||||
@dmbp.route("/day/<string:task>/<int:month>/<int:day>")
|
||||
def oneday(
|
||||
@@ -84,7 +106,6 @@ def work():
|
||||
end = datetime.today().replace(hour=23, minute=59, second=59, tzinfo=timezone)
|
||||
|
||||
rows = get_work_period_totals(start, end)
|
||||
print(rows)
|
||||
|
||||
return render_template("main.html", rows=rows, auto_refresh=False)
|
||||
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
from collections import Counter, defaultdict
|
||||
from datetime import datetime, timedelta
|
||||
from pprint import pprint
|
||||
import logging
|
||||
|
||||
from pymongo import MongoClient
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
# Setup logging for debugging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
timezone = ZoneInfo("America/Argentina/Buenos_Aires")
|
||||
utctz = ZoneInfo("UTC")
|
||||
|
||||
@@ -286,9 +280,6 @@ def get_period_totals(start, end, task=None):
|
||||
# If time_since_bfirst > bfirst["delta"], the switch ended before the period started
|
||||
if time_since_bfirst <= bfirst["delta"]:
|
||||
start_delta = time_since_bfirst
|
||||
logger.debug(f"start_delta: {start_delta}s (bfirst crosses into period)")
|
||||
else:
|
||||
logger.debug(f"start_delta: 0s (bfirst ended before period start: {time_since_bfirst}s > {bfirst['delta']}s)")
|
||||
|
||||
ldoc = aux_results[0]["last_doc"]
|
||||
lastdate = ldoc["date"].replace(tzinfo=utctz)
|
||||
@@ -297,20 +288,12 @@ def get_period_totals(start, end, task=None):
|
||||
rows = []
|
||||
active_vs_idle = {"Active": 0, "Idle": 0}
|
||||
|
||||
# Debug logging
|
||||
logger.debug(f"Processing results for period {start} to {end}")
|
||||
logger.debug(f"bfirst workspace: {bfirst['workspace'] if bfirst else 'None'}")
|
||||
logger.debug(f"ldoc workspace: {ldoc['workspace']}")
|
||||
|
||||
for result in results:
|
||||
original_total = result["total"]
|
||||
|
||||
if bfirst:
|
||||
if result["_id"] == bfirst["workspace"]:
|
||||
# Safety: ensure start_delta doesn't exceed total
|
||||
adjustment = min(start_delta, result["total"])
|
||||
result["total"] -= adjustment
|
||||
logger.debug(f"{result['_id']}: adjusted start by -{adjustment}s (was {original_total}s, now {result['total']}s)")
|
||||
|
||||
if end < now():
|
||||
if result["_id"] == ldoc["workspace"]:
|
||||
@@ -318,9 +301,6 @@ def get_period_totals(start, end, task=None):
|
||||
adjustment = ldoc["delta"] - end_delta
|
||||
safe_adjustment = min(adjustment, result["total"])
|
||||
result["total"] -= safe_adjustment
|
||||
logger.debug(f"{result['_id']}: adjusted end by -{safe_adjustment}s (was {original_total}s, now {result['total']}s)")
|
||||
|
||||
logger.debug(f"{result['_id']}: final total = {result['total']}s ({convert_seconds(result['total'])})")
|
||||
|
||||
for result in results:
|
||||
if result["total"] > 0:
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- <link rel="stylesheet" href="{{ url_for('static', filename='styles/dm.css') }}"> -->
|
||||
{% if auto_refresh %}
|
||||
<meta http-equiv="refresh" content="5">
|
||||
{% endif %}
|
||||
{% block head %}
|
||||
{% endblock %}
|
||||
|
||||
<style>
|
||||
body
|
||||
body
|
||||
{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -34,35 +31,34 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
{% if auto_refresh %}
|
||||
<script>
|
||||
function refreshData() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '/api/today', true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
document.getElementById('content-container').innerHTML = xhr.responseText;
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
// Auto-refresh every 5 seconds using AJAX
|
||||
setInterval(refreshData, 5000);
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
</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) -->
|
||||
|
||||
|
||||
<div id="content-container">
|
||||
{% block content %}
|
||||
{% if current_task_path and current_task_time %}
|
||||
<div style="font-size: 48pt; margin-bottom: 40px; text-align: center;">
|
||||
<div style="color: #333;">{{ current_task_path }}</div>
|
||||
<div style="color: #666; font-size: 36pt;">{{ current_task_time }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<table>
|
||||
{% for row in rows %}
|
||||
{% if row["ws"] in ['Away', 'Other'] %}
|
||||
{% set my_class = 'grey' %}
|
||||
{% elif row["ws"] in ['Active', 'Idle'] %}
|
||||
{% set my_class = 'blue' %}
|
||||
{% else %}
|
||||
{% set my_class = '' %}
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td class="{{my_class}}" >{{ row["ws"] }}</td>
|
||||
<td class="{{my_class}}" >{{ row["total"] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% include 'main_content.html' %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
23
dmapp/dmweb/templates/main_content.html
Normal file
23
dmapp/dmweb/templates/main_content.html
Normal file
@@ -0,0 +1,23 @@
|
||||
{% if current_task_path and current_task_time %}
|
||||
<div id="current-task-info" style="font-size: 48pt; margin-bottom: 40px; text-align: center;">
|
||||
<div style="color: #333;">{{ current_task_path }}</div>
|
||||
<div style="color: #666; font-size: 36pt;">{{ current_task_time }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<table>
|
||||
<tbody>
|
||||
{% for row in rows %}
|
||||
{% if row["ws"] in ['Away', 'Other'] %}
|
||||
{% set my_class = 'grey' %}
|
||||
{% elif row["ws"] in ['Active', 'Idle'] %}
|
||||
{% set my_class = 'blue' %}
|
||||
{% else %}
|
||||
{% set my_class = '' %}
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td class="{{my_class}}" >{{ row["ws"] }}</td>
|
||||
<td class="{{my_class}}" >{{ row["total"] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
Reference in New Issue
Block a user