claude unstested update for moving from wp to project -> wp to task

This commit is contained in:
buenosairesam
2025-10-03 04:47:13 -03:00
parent 72f9e9d9a7
commit 71752c7d76
10 changed files with 237 additions and 146 deletions

View File

@@ -17,6 +17,52 @@ tasks = db.task
task_file = "/home/mariano/LETRAS/adm/task/main"
def get_current_task_info():
"""Get current task ID and path from state and tasks collection"""
states = db.state
current_doc = states.find_one({"_id": "current"})
if not current_doc or "task" not in current_doc:
return None, None
task_id = current_doc["task"]
task_doc = tasks.find_one({"task_id": task_id})
if task_doc and "path" in task_doc:
return task_id, task_doc["path"]
return task_id, None
def get_task_time_seconds(start, end, task_id, workspaces=None):
"""Get total seconds for a task within a time period using MongoDB aggregation."""
if workspaces is None:
workspaces = ["Plan", "Think", "Work"]
pipeline = [
{
"$match": {
"date": {"$gte": start, "$lte": end},
"task": task_id,
"workspace": {"$in": workspaces}
}
},
{
"$group": {
"_id": None,
"total_seconds": {"$sum": "$delta"}
}
}
]
result = list(switches.aggregate(pipeline))
if result and len(result) > 0:
return result[0]["total_seconds"]
return 0
def task_or_none(task=None):
if not task:
task = read_and_extract(task_file)
@@ -62,66 +108,43 @@ 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()
"""Get period totals grouped by task with full path."""
# Get all tasks with time in the period
pipeline = [
{
"$match": {
"date": {"$gte": start, "$lte": end},
"workspace": {"$in": ["Plan", "Think", "Work"]},
"task": {"$exists": True, "$ne": None}
}
},
{
"$group": {
"_id": "$task",
"total_seconds": {"$sum": "$delta"}
}
}
]
results = list(switches.aggregate(pipeline))
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
for result in results:
task_id = result["_id"]
total_seconds = result["total_seconds"]
if total_seconds > 0:
# Get task path from tasks collection
task_doc = tasks.find_one({"task_id": task_id})
task_path = task_doc["path"] if task_doc and "path" in task_doc else task_id
combined_rows.append({
"ws": project_name,
"ws": task_path,
"total": convert_seconds(total_seconds)
})
# Sort by project name for consistency
# Sort by path for consistency
combined_rows.sort(key=lambda x: x["ws"])
return combined_rows