-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogistics_utils.py
More file actions
147 lines (115 loc) Β· 4.06 KB
/
logistics_utils.py
File metadata and controls
147 lines (115 loc) Β· 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
"""
Logistics and workflow management utilities.
Usage:
python logistics_utils.py <command> [options]
"""
import sys
from pathlib import Path
try:
import codomyrmex
except ImportError:
project_root = Path(__file__).resolve().parent.parent.parent
sys.path.insert(0, str(project_root / "src"))
import argparse
import json
from datetime import datetime, timedelta
def estimate_time(tasks: list) -> dict:
"""Estimate total time for tasks."""
total_hours = 0
breakdown = []
for task in tasks:
hours = task.get("hours", 1)
total_hours += hours
breakdown.append({"name": task.get("name", "Task"), "hours": hours})
return {
"total_hours": total_hours,
"total_days": round(total_hours / 8, 1),
"breakdown": breakdown,
}
def create_schedule(tasks: list, start_date: datetime | None = None) -> list:
"""Create a schedule from tasks."""
start = start_date or datetime.now()
schedule = []
current = start
for task in tasks:
hours = task.get("hours", 1)
end = current + timedelta(hours=hours)
schedule.append(
{
"name": task.get("name", "Task"),
"start": current.isoformat(),
"end": end.isoformat(),
"hours": hours,
}
)
current = end
return schedule
def main():
# Auto-injected: Load configuration
from pathlib import Path
import yaml
config_path = (
Path(__file__).resolve().parent.parent.parent
/ "config"
/ "logistics"
/ "config.yaml"
)
if config_path.exists():
with open(config_path) as f:
yaml.safe_load(f) or {}
print("Loaded config from config/logistics/config.yaml")
parser = argparse.ArgumentParser(description="Logistics utilities")
subparsers = parser.add_subparsers(dest="command")
# Estimate command
estimate = subparsers.add_parser("estimate", help="Estimate time")
estimate.add_argument("file", nargs="?", help="Tasks JSON file")
# Schedule command
schedule = subparsers.add_parser("schedule", help="Create schedule")
schedule.add_argument("file", nargs="?", help="Tasks JSON file")
# Demo command
subparsers.add_parser("demo", help="Demo with sample tasks")
args = parser.parse_args()
if not args.command:
print("π¦ Logistics Utilities\n")
print("Commands:")
print(" estimate - Estimate total time")
print(" schedule - Create schedule")
print(" demo - Demo with sample tasks")
return 0
sample_tasks = [
{"name": "Planning", "hours": 4},
{"name": "Development", "hours": 16},
{"name": "Testing", "hours": 8},
{"name": "Documentation", "hours": 4},
{"name": "Deployment", "hours": 2},
]
if args.command == "estimate":
if args.file:
tasks = json.loads(Path(args.file).read_text())
else:
tasks = sample_tasks
print("π Using sample tasks (provide JSON file for custom)\n")
result = estimate_time(tasks)
print("β±οΈ Time Estimate:\n")
for item in result["breakdown"]:
print(f" {item['name']}: {item['hours']}h")
print(f"\n Total: {result['total_hours']}h ({result['total_days']} days)")
elif args.command == "schedule":
tasks = json.loads(Path(args.file).read_text()) if args.file else sample_tasks
schedule = create_schedule(tasks)
print("π
Schedule:\n")
for item in schedule:
start = datetime.fromisoformat(item["start"])
print(
f" {start.strftime('%Y-%m-%d %H:%M')} - {item['name']} ({item['hours']}h)"
)
elif args.command == "demo":
print("π¦ Sample Tasks:\n")
for t in sample_tasks:
print(f" β’ {t['name']}: {t['hours']}h")
result = estimate_time(sample_tasks)
print(f"\n Total: {result['total_hours']}h")
return 0
if __name__ == "__main__":
sys.exit(main())