remove duplications

This commit is contained in:
buenosairesam
2025-08-03 09:13:26 -03:00
parent 8710a140f8
commit 7666917c13
4 changed files with 127 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ utctz = ZoneInfo("UTC")
client = MongoClient()
db = client.deskmeter
switches = db.switch
tasks = db.task
task_file = "/home/mariano/LETRAS/adm/task/main"
@@ -61,6 +62,70 @@ def read_and_extract(file_path):
return None
def get_work_projects():
"""Get dict of work projects with their task IDs."""
work_tasks = list(
tasks.find(
{"path": {"$regex": "^work/"}, "task_id": {"$exists": True}},
{"path": 1, "task_id": 1, "_id": 0},
)
)
projects = {}
for task in work_tasks:
# Extract project name from path like "work/cal" -> "cal"
path_parts = task["path"].split("/")
if len(path_parts) >= 2:
project_name = path_parts[1]
if project_name not in projects:
projects[project_name] = []
projects[project_name].append(task["task_id"])
return projects
def get_work_project_tasks():
"""Get comma-separated string of all task IDs under work/* paths."""
projects = get_work_projects()
all_task_ids = []
for task_ids in projects.values():
all_task_ids.extend(task_ids)
return ",".join(all_task_ids) if all_task_ids else None
def get_work_period_totals(start, end):
"""Get period totals grouped by work project."""
projects = get_work_projects()
combined_rows = []
for project_name, task_ids in projects.items():
if not task_ids:
continue
task_string = ",".join(task_ids)
rows = get_period_totals(start, end, task_string)
# Sum up all time for this project (looking for "Work" workspace)
total_seconds = 0
for row in rows:
if row["ws"] == "Work":
# Convert time string back to seconds to sum properly
time_parts = row["total"].split(":")
if len(time_parts) == 3:
hours, minutes, seconds = map(int, time_parts)
total_seconds += hours * 3600 + minutes * 60 + seconds
if total_seconds > 0:
combined_rows.append({
"ws": project_name,
"total": convert_seconds(total_seconds)
})
# Sort by project name for consistency
combined_rows.sort(key=lambda x: x["ws"])
return combined_rows
def get_period_totals(start, end, task=None):
task_query = {"$in": task.split(",")} if task else {}