unmodified changes from long ago commited to kickstart deskmeter again
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user