refactor: update app code for domain-scoped schema migration
Some checks failed
CI / lint-and-test (pull_request) Has been cancelled
Some checks failed
CI / lint-and-test (pull_request) Has been cancelled
- Update dbt model references to use new schema naming (stg_toronto, int_toronto, mart_toronto) - Refactor figure factories to use consistent column naming from new schema - Update callbacks to work with refactored data structures - Add centralized design tokens module for consistent styling - Streamline CLAUDE.md documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,15 @@ from typing import Any
|
||||
import plotly.express as px
|
||||
import plotly.graph_objects as go
|
||||
|
||||
from portfolio_app.design import (
|
||||
CHART_PALETTE,
|
||||
GRID_COLOR,
|
||||
PAPER_BG,
|
||||
PLOT_BG,
|
||||
TEXT_PRIMARY,
|
||||
TEXT_SECONDARY,
|
||||
)
|
||||
|
||||
|
||||
def create_price_time_series(
|
||||
data: list[dict[str, Any]],
|
||||
@@ -38,14 +47,14 @@ def create_price_time_series(
|
||||
x=0.5,
|
||||
y=0.5,
|
||||
showarrow=False,
|
||||
font={"color": "#888888"},
|
||||
font={"color": TEXT_SECONDARY},
|
||||
)
|
||||
fig.update_layout(
|
||||
title=title,
|
||||
height=350,
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
paper_bgcolor=PAPER_BG,
|
||||
plot_bgcolor=PLOT_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
)
|
||||
return fig
|
||||
|
||||
@@ -59,6 +68,7 @@ def create_price_time_series(
|
||||
y=price_column,
|
||||
color=group_column,
|
||||
title=title,
|
||||
color_discrete_sequence=CHART_PALETTE,
|
||||
)
|
||||
else:
|
||||
fig = px.line(
|
||||
@@ -67,6 +77,7 @@ def create_price_time_series(
|
||||
y=price_column,
|
||||
title=title,
|
||||
)
|
||||
fig.update_traces(line_color=CHART_PALETTE[0])
|
||||
|
||||
fig.update_layout(
|
||||
height=350,
|
||||
@@ -76,11 +87,11 @@ def create_price_time_series(
|
||||
yaxis_tickprefix="$",
|
||||
yaxis_tickformat=",",
|
||||
hovermode="x unified",
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
xaxis={"gridcolor": "#333333", "linecolor": "#444444"},
|
||||
yaxis={"gridcolor": "#333333", "linecolor": "#444444"},
|
||||
paper_bgcolor=PAPER_BG,
|
||||
plot_bgcolor=PLOT_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
xaxis={"gridcolor": GRID_COLOR, "linecolor": GRID_COLOR},
|
||||
yaxis={"gridcolor": GRID_COLOR, "linecolor": GRID_COLOR},
|
||||
)
|
||||
|
||||
return fig
|
||||
@@ -118,14 +129,14 @@ def create_volume_time_series(
|
||||
x=0.5,
|
||||
y=0.5,
|
||||
showarrow=False,
|
||||
font={"color": "#888888"},
|
||||
font={"color": TEXT_SECONDARY},
|
||||
)
|
||||
fig.update_layout(
|
||||
title=title,
|
||||
height=350,
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
paper_bgcolor=PAPER_BG,
|
||||
plot_bgcolor=PLOT_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
)
|
||||
return fig
|
||||
|
||||
@@ -140,6 +151,7 @@ def create_volume_time_series(
|
||||
y=volume_column,
|
||||
color=group_column,
|
||||
title=title,
|
||||
color_discrete_sequence=CHART_PALETTE,
|
||||
)
|
||||
else:
|
||||
fig = px.bar(
|
||||
@@ -148,6 +160,7 @@ def create_volume_time_series(
|
||||
y=volume_column,
|
||||
title=title,
|
||||
)
|
||||
fig.update_traces(marker_color=CHART_PALETTE[0])
|
||||
else:
|
||||
if group_column and group_column in df.columns:
|
||||
fig = px.line(
|
||||
@@ -156,6 +169,7 @@ def create_volume_time_series(
|
||||
y=volume_column,
|
||||
color=group_column,
|
||||
title=title,
|
||||
color_discrete_sequence=CHART_PALETTE,
|
||||
)
|
||||
else:
|
||||
fig = px.line(
|
||||
@@ -164,6 +178,7 @@ def create_volume_time_series(
|
||||
y=volume_column,
|
||||
title=title,
|
||||
)
|
||||
fig.update_traces(line_color=CHART_PALETTE[0])
|
||||
|
||||
fig.update_layout(
|
||||
height=350,
|
||||
@@ -172,11 +187,11 @@ def create_volume_time_series(
|
||||
yaxis_title=volume_column.replace("_", " ").title(),
|
||||
yaxis_tickformat=",",
|
||||
hovermode="x unified",
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
xaxis={"gridcolor": "#333333", "linecolor": "#444444"},
|
||||
yaxis={"gridcolor": "#333333", "linecolor": "#444444"},
|
||||
paper_bgcolor=PAPER_BG,
|
||||
plot_bgcolor=PLOT_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
xaxis={"gridcolor": GRID_COLOR, "linecolor": GRID_COLOR},
|
||||
yaxis={"gridcolor": GRID_COLOR, "linecolor": GRID_COLOR},
|
||||
)
|
||||
|
||||
return fig
|
||||
@@ -211,14 +226,14 @@ def create_market_comparison_chart(
|
||||
x=0.5,
|
||||
y=0.5,
|
||||
showarrow=False,
|
||||
font={"color": "#888888"},
|
||||
font={"color": TEXT_SECONDARY},
|
||||
)
|
||||
fig.update_layout(
|
||||
title=title,
|
||||
height=400,
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
paper_bgcolor=PAPER_BG,
|
||||
plot_bgcolor=PLOT_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
)
|
||||
return fig
|
||||
|
||||
@@ -230,8 +245,6 @@ def create_market_comparison_chart(
|
||||
|
||||
fig = make_subplots(specs=[[{"secondary_y": True}]])
|
||||
|
||||
colors = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728"]
|
||||
|
||||
for i, metric in enumerate(metrics[:4]):
|
||||
if metric not in df.columns:
|
||||
continue
|
||||
@@ -242,7 +255,7 @@ def create_market_comparison_chart(
|
||||
x=df[date_column],
|
||||
y=df[metric],
|
||||
name=metric.replace("_", " ").title(),
|
||||
line={"color": colors[i % len(colors)]},
|
||||
line={"color": CHART_PALETTE[i % len(CHART_PALETTE)]},
|
||||
),
|
||||
secondary_y=secondary,
|
||||
)
|
||||
@@ -252,18 +265,18 @@ def create_market_comparison_chart(
|
||||
height=400,
|
||||
margin={"l": 40, "r": 40, "t": 50, "b": 40},
|
||||
hovermode="x unified",
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
plot_bgcolor="rgba(0,0,0,0)",
|
||||
font_color="#c9c9c9",
|
||||
xaxis={"gridcolor": "#333333", "linecolor": "#444444"},
|
||||
yaxis={"gridcolor": "#333333", "linecolor": "#444444"},
|
||||
paper_bgcolor=PAPER_BG,
|
||||
plot_bgcolor=PLOT_BG,
|
||||
font_color=TEXT_PRIMARY,
|
||||
xaxis={"gridcolor": GRID_COLOR, "linecolor": GRID_COLOR},
|
||||
yaxis={"gridcolor": GRID_COLOR, "linecolor": GRID_COLOR},
|
||||
legend={
|
||||
"orientation": "h",
|
||||
"yanchor": "bottom",
|
||||
"y": 1.02,
|
||||
"xanchor": "right",
|
||||
"x": 1,
|
||||
"font": {"color": "#c9c9c9"},
|
||||
"font": {"color": TEXT_PRIMARY},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -290,13 +303,13 @@ def add_policy_markers(
|
||||
if not policy_events:
|
||||
return fig
|
||||
|
||||
# Color mapping for policy categories
|
||||
# Color mapping for policy categories using design tokens
|
||||
category_colors = {
|
||||
"monetary": "#1f77b4", # Blue
|
||||
"tax": "#2ca02c", # Green
|
||||
"regulatory": "#ff7f0e", # Orange
|
||||
"supply": "#9467bd", # Purple
|
||||
"economic": "#d62728", # Red
|
||||
"monetary": CHART_PALETTE[0], # Blue
|
||||
"tax": CHART_PALETTE[3], # Teal/green
|
||||
"regulatory": CHART_PALETTE[1], # Orange
|
||||
"supply": CHART_PALETTE[6], # Pink
|
||||
"economic": CHART_PALETTE[5], # Vermillion
|
||||
}
|
||||
|
||||
# Symbol mapping for expected direction
|
||||
@@ -313,7 +326,7 @@ def add_policy_markers(
|
||||
title = event.get("title", "Policy Event")
|
||||
level = event.get("level", "federal")
|
||||
|
||||
color = category_colors.get(category, "#666666")
|
||||
color = category_colors.get(category, TEXT_SECONDARY)
|
||||
symbol = direction_symbols.get(direction, "circle")
|
||||
|
||||
# Add vertical line for the event
|
||||
@@ -335,7 +348,7 @@ def add_policy_markers(
|
||||
"symbol": symbol,
|
||||
"size": 12,
|
||||
"color": color,
|
||||
"line": {"width": 1, "color": "white"},
|
||||
"line": {"width": 1, "color": TEXT_PRIMARY},
|
||||
},
|
||||
name=title,
|
||||
hovertemplate=(
|
||||
|
||||
Reference in New Issue
Block a user