Spaces:
Build error
Build error
Create dummy_funcs.py
Browse files- dummy_funcs.py +51 -0
dummy_funcs.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def add_stats_to_figure(fig, df, y_axis, chart_type):
|
| 2 |
+
# Calculate statistics
|
| 3 |
+
min_val = df[y_axis].min()
|
| 4 |
+
max_val = df[y_axis].max()
|
| 5 |
+
avg_val = df[y_axis].mean()
|
| 6 |
+
median_val = df[y_axis].median()
|
| 7 |
+
std_dev_val = df[y_axis].std()
|
| 8 |
+
|
| 9 |
+
# Stats summary text
|
| 10 |
+
stats_text = (
|
| 11 |
+
f"π **Statistics**\n\n"
|
| 12 |
+
f"- **Min:** ${min_val:,.2f}\n"
|
| 13 |
+
f"- **Max:** ${max_val:,.2f}\n"
|
| 14 |
+
f"- **Average:** ${avg_val:,.2f}\n"
|
| 15 |
+
f"- **Median:** ${median_val:,.2f}\n"
|
| 16 |
+
f"- **Std Dev:** ${std_dev_val:,.2f}"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Charts suitable for stats annotations
|
| 20 |
+
if chart_type in ["bar", "line", "scatter"]:
|
| 21 |
+
# Add annotation box
|
| 22 |
+
fig.add_annotation(
|
| 23 |
+
text=stats_text,
|
| 24 |
+
xref="paper", yref="paper",
|
| 25 |
+
x=1.05, y=1,
|
| 26 |
+
showarrow=False,
|
| 27 |
+
align="left",
|
| 28 |
+
font=dict(size=12, color="black"),
|
| 29 |
+
bordercolor="black",
|
| 30 |
+
borderwidth=1,
|
| 31 |
+
bgcolor="rgba(255, 255, 255, 0.8)"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Add horizontal lines for min, median, avg, max
|
| 35 |
+
fig.add_hline(y=min_val, line_dash="dot", line_color="red", annotation_text="Min", annotation_position="bottom right")
|
| 36 |
+
fig.add_hline(y=median_val, line_dash="dash", line_color="orange", annotation_text="Median", annotation_position="top right")
|
| 37 |
+
fig.add_hline(y=avg_val, line_dash="dashdot", line_color="green", annotation_text="Avg", annotation_position="top right")
|
| 38 |
+
fig.add_hline(y=max_val, line_dash="dot", line_color="blue", annotation_text="Max", annotation_position="top right")
|
| 39 |
+
|
| 40 |
+
elif chart_type == "box":
|
| 41 |
+
# Box plots already show distribution (no extra stats needed)
|
| 42 |
+
pass
|
| 43 |
+
|
| 44 |
+
elif chart_type == "pie":
|
| 45 |
+
# Pie charts don't need statistical overlays
|
| 46 |
+
st.info("π Pie charts focus on proportions. No additional stats displayed.")
|
| 47 |
+
|
| 48 |
+
else:
|
| 49 |
+
st.warning(f"β οΈ No stats added for unsupported chart type: {chart_type}")
|
| 50 |
+
|
| 51 |
+
return fig
|