Spaces:
Sleeping
Sleeping
Fix: correct field names and model construction in all four views
Browse files- app.py +2 -11
- views/gantt.py +20 -15
- views/heatmap.py +16 -13
- views/raci.py +2 -2
app.py
CHANGED
|
@@ -315,18 +315,9 @@ async def on_generate(objective, tasks, start_date, end_date, start_ai, end_ai,
|
|
| 315 |
|
| 316 |
# --- Step 6: Build ProjectPlan and render charts ---
|
| 317 |
try:
|
| 318 |
-
project_plan = ProjectPlan(
|
| 319 |
except Exception:
|
| 320 |
-
project_plan = ProjectPlan(
|
| 321 |
-
phases=plan_data.get("phases", []),
|
| 322 |
-
raci=plan_data.get("raci", []),
|
| 323 |
-
risks=plan_data.get("risks", []),
|
| 324 |
-
workload=plan_data.get("workload", []),
|
| 325 |
-
estimated_start_date=plan_data.get("estimated_start_date"),
|
| 326 |
-
estimated_end_date=plan_data.get("estimated_end_date"),
|
| 327 |
-
timeline_note=plan_data.get("timeline_note"),
|
| 328 |
-
timeline_warning=plan_data.get("timeline_warning"),
|
| 329 |
-
)
|
| 330 |
|
| 331 |
try:
|
| 332 |
gantt_fig = gantt.render(project_plan)
|
|
|
|
| 315 |
|
| 316 |
# --- Step 6: Build ProjectPlan and render charts ---
|
| 317 |
try:
|
| 318 |
+
project_plan = ProjectPlan.model_validate(plan_data)
|
| 319 |
except Exception:
|
| 320 |
+
project_plan = ProjectPlan()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
try:
|
| 323 |
gantt_fig = gantt.render(project_plan)
|
views/gantt.py
CHANGED
|
@@ -25,23 +25,23 @@ def _get_team_colors(phases: list[Phase]) -> dict[str, str]:
|
|
| 25 |
"""Assign a distinct color to each unique team, cycling through a palette of 8 colors."""
|
| 26 |
teams: list[str] = []
|
| 27 |
for phase in phases:
|
| 28 |
-
if phase.
|
| 29 |
-
teams.append(phase.
|
| 30 |
return {team: _TEAM_PALETTE[i % len(_TEAM_PALETTE)] for i, team in enumerate(teams)}
|
| 31 |
|
| 32 |
|
| 33 |
def _phase_to_bar(phase: Phase, base_date: date, color: str) -> dict:
|
| 34 |
"""Convert one phase to a Plotly bar dict."""
|
| 35 |
-
start = base_date + timedelta(days=phase.
|
| 36 |
-
end = base_date + timedelta(days=phase.
|
| 37 |
-
label = f"⭐ {phase.name}" if phase.
|
| 38 |
hover = (
|
| 39 |
f"<b>{phase.name}</b><br>"
|
| 40 |
f"Start: {start}<br>"
|
| 41 |
f"End: {end}<br>"
|
| 42 |
-
f"Owner: {phase.
|
| 43 |
f"Slack: {phase.slack_days} day(s)<br>"
|
| 44 |
-
f"Critical Path: {'Yes' if phase.
|
| 45 |
)
|
| 46 |
return {"x0": start, "x1": end, "label": label, "hover": hover, "color": color, "name": phase.name}
|
| 47 |
|
|
@@ -66,7 +66,7 @@ def render(plan: ProjectPlan) -> go.Figure:
|
|
| 66 |
base_date = date.today()
|
| 67 |
|
| 68 |
team_colors = _get_team_colors(plan.phases)
|
| 69 |
-
bars = [_phase_to_bar(p, base_date, team_colors.get(p.
|
| 70 |
y_labels = [b["label"] for b in bars]
|
| 71 |
|
| 72 |
for i, bar in enumerate(bars):
|
|
@@ -83,13 +83,18 @@ def render(plan: ProjectPlan) -> go.Figure:
|
|
| 83 |
))
|
| 84 |
|
| 85 |
today_str = date.today().isoformat()
|
| 86 |
-
fig.
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
)
|
| 94 |
|
| 95 |
fig.update_layout(
|
|
|
|
| 25 |
"""Assign a distinct color to each unique team, cycling through a palette of 8 colors."""
|
| 26 |
teams: list[str] = []
|
| 27 |
for phase in phases:
|
| 28 |
+
if phase.owner_team and phase.owner_team not in teams:
|
| 29 |
+
teams.append(phase.owner_team)
|
| 30 |
return {team: _TEAM_PALETTE[i % len(_TEAM_PALETTE)] for i, team in enumerate(teams)}
|
| 31 |
|
| 32 |
|
| 33 |
def _phase_to_bar(phase: Phase, base_date: date, color: str) -> dict:
|
| 34 |
"""Convert one phase to a Plotly bar dict."""
|
| 35 |
+
start = base_date + timedelta(days=phase.start_offset_days)
|
| 36 |
+
end = base_date + timedelta(days=phase.start_offset_days + phase.duration_days)
|
| 37 |
+
label = f"⭐ {phase.name}" if phase.is_critical_path else phase.name
|
| 38 |
hover = (
|
| 39 |
f"<b>{phase.name}</b><br>"
|
| 40 |
f"Start: {start}<br>"
|
| 41 |
f"End: {end}<br>"
|
| 42 |
+
f"Owner: {phase.owner_team or 'N/A'}<br>"
|
| 43 |
f"Slack: {phase.slack_days} day(s)<br>"
|
| 44 |
+
f"Critical Path: {'Yes' if phase.is_critical_path else 'No'}"
|
| 45 |
)
|
| 46 |
return {"x0": start, "x1": end, "label": label, "hover": hover, "color": color, "name": phase.name}
|
| 47 |
|
|
|
|
| 66 |
base_date = date.today()
|
| 67 |
|
| 68 |
team_colors = _get_team_colors(plan.phases)
|
| 69 |
+
bars = [_phase_to_bar(p, base_date, team_colors.get(p.owner_team, _TEAM_PALETTE[0])) for p in plan.phases]
|
| 70 |
y_labels = [b["label"] for b in bars]
|
| 71 |
|
| 72 |
for i, bar in enumerate(bars):
|
|
|
|
| 83 |
))
|
| 84 |
|
| 85 |
today_str = date.today().isoformat()
|
| 86 |
+
fig.add_shape(
|
| 87 |
+
type="line",
|
| 88 |
+
x0=today_str, x1=today_str,
|
| 89 |
+
y0=0, y1=1,
|
| 90 |
+
yref="paper",
|
| 91 |
+
line=dict(dash="dash", color=COLORS["green"], width=2),
|
| 92 |
+
)
|
| 93 |
+
fig.add_annotation(
|
| 94 |
+
x=today_str, y=1, yref="paper",
|
| 95 |
+
text="Today", showarrow=False,
|
| 96 |
+
font=dict(color=COLORS["green"], size=11),
|
| 97 |
+
yanchor="bottom",
|
| 98 |
)
|
| 99 |
|
| 100 |
fig.update_layout(
|
views/heatmap.py
CHANGED
|
@@ -17,29 +17,32 @@ COLORS = {
|
|
| 17 |
|
| 18 |
|
| 19 |
def _build_matrix(plan: ProjectPlan) -> tuple[list[str], list[str], list[list[float]]]:
|
| 20 |
-
"""Return (team_names, week_labels, z_matrix) for the workload heatmap.
|
|
|
|
|
|
|
| 21 |
if not plan.workload:
|
| 22 |
return [], [], []
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
for entry in plan.workload:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
load_map: dict[tuple[str, str], float] = {
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
z_matrix = [
|
| 39 |
[load_map.get((team, week), 0.0) for week in weeks_sorted]
|
| 40 |
for team in teams
|
| 41 |
]
|
| 42 |
-
|
| 43 |
return teams, weeks_sorted, z_matrix
|
| 44 |
|
| 45 |
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
def _build_matrix(plan: ProjectPlan) -> tuple[list[str], list[str], list[list[float]]]:
|
| 20 |
+
"""Return (team_names, week_labels, z_matrix) for the workload heatmap.
|
| 21 |
+
Model: plan.workload is list[TeamWorkload]; each has team_name and weeks: list[WorkloadWeek].
|
| 22 |
+
"""
|
| 23 |
if not plan.workload:
|
| 24 |
return [], [], []
|
| 25 |
|
| 26 |
+
# Collect all unique week labels across all teams
|
| 27 |
+
weeks_set: list[str] = []
|
|
|
|
| 28 |
for entry in plan.workload:
|
| 29 |
+
for w in entry.weeks:
|
| 30 |
+
if w.week_label not in weeks_set:
|
| 31 |
+
weeks_set.append(w.week_label)
|
| 32 |
+
weeks_sorted = sorted(weeks_set)
|
| 33 |
+
|
| 34 |
+
teams = [entry.team_name for entry in plan.workload]
|
| 35 |
|
| 36 |
+
# Build load lookup: (team_name, week_label) -> load_score
|
| 37 |
+
load_map: dict[tuple[str, str], float] = {}
|
| 38 |
+
for entry in plan.workload:
|
| 39 |
+
for w in entry.weeks:
|
| 40 |
+
load_map[(entry.team_name, w.week_label)] = w.load_score
|
| 41 |
|
| 42 |
z_matrix = [
|
| 43 |
[load_map.get((team, week), 0.0) for week in weeks_sorted]
|
| 44 |
for team in teams
|
| 45 |
]
|
|
|
|
| 46 |
return teams, weeks_sorted, z_matrix
|
| 47 |
|
| 48 |
|
views/raci.py
CHANGED
|
@@ -36,7 +36,7 @@ def _get_all_teams(raci: list[RACIEntry]) -> list[str]:
|
|
| 36 |
"""Collect unique team names from all R/A/C/I fields."""
|
| 37 |
seen: list[str] = []
|
| 38 |
for entry in raci:
|
| 39 |
-
for team in (entry.responsible + entry.accountable + entry.consulted + entry.informed):
|
| 40 |
if team and team not in seen:
|
| 41 |
seen.append(team)
|
| 42 |
return seen
|
|
@@ -46,7 +46,7 @@ def _build_cell(entry: RACIEntry, team: str) -> tuple[str, str]:
|
|
| 46 |
"""Return (letter, color) for a given team in a RACI entry."""
|
| 47 |
if team in entry.responsible:
|
| 48 |
return ("R", _RACI_COLORS["R"])
|
| 49 |
-
if team
|
| 50 |
return ("A", _RACI_COLORS["A"])
|
| 51 |
if team in entry.consulted:
|
| 52 |
return ("C", _RACI_COLORS["C"])
|
|
|
|
| 36 |
"""Collect unique team names from all R/A/C/I fields."""
|
| 37 |
seen: list[str] = []
|
| 38 |
for entry in raci:
|
| 39 |
+
for team in (entry.responsible + [entry.accountable] + entry.consulted + entry.informed):
|
| 40 |
if team and team not in seen:
|
| 41 |
seen.append(team)
|
| 42 |
return seen
|
|
|
|
| 46 |
"""Return (letter, color) for a given team in a RACI entry."""
|
| 47 |
if team in entry.responsible:
|
| 48 |
return ("R", _RACI_COLORS["R"])
|
| 49 |
+
if team == entry.accountable:
|
| 50 |
return ("A", _RACI_COLORS["A"])
|
| 51 |
if team in entry.consulted:
|
| 52 |
return ("C", _RACI_COLORS["C"])
|