Spaces:
Sleeping
Sleeping
DrishtiSharma
commited on
Update mylab/fixed_font_issue.py
Browse files- mylab/fixed_font_issue.py +53 -0
mylab/fixed_font_issue.py
CHANGED
@@ -179,6 +179,59 @@ def create_text_report_with_viz_temp(report, conclusion, visualizations):
|
|
179 |
return temp_txt.name
|
180 |
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
# Function to create PDF with report text and visualizations
|
183 |
def create_pdf_report_with_viz(report, conclusion, visualizations):
|
184 |
pdf = FPDF()
|
|
|
179 |
return temp_txt.name
|
180 |
|
181 |
|
182 |
+
def add_stats_to_figure(fig, df, y_axis, chart_type):
|
183 |
+
# Calculate statistics
|
184 |
+
min_val = df[y_axis].min()
|
185 |
+
max_val = df[y_axis].max()
|
186 |
+
avg_val = df[y_axis].mean()
|
187 |
+
median_val = df[y_axis].median()
|
188 |
+
std_dev_val = df[y_axis].std()
|
189 |
+
|
190 |
+
# Stats summary text
|
191 |
+
stats_text = (
|
192 |
+
f"π **Statistics**\n\n"
|
193 |
+
f"- **Min:** ${min_val:,.2f}\n"
|
194 |
+
f"- **Max:** ${max_val:,.2f}\n"
|
195 |
+
f"- **Average:** ${avg_val:,.2f}\n"
|
196 |
+
f"- **Median:** ${median_val:,.2f}\n"
|
197 |
+
f"- **Std Dev:** ${std_dev_val:,.2f}"
|
198 |
+
)
|
199 |
+
|
200 |
+
# Charts suitable for stats annotations
|
201 |
+
if chart_type in ["bar", "line", "scatter"]:
|
202 |
+
# Add annotation box
|
203 |
+
fig.add_annotation(
|
204 |
+
text=stats_text,
|
205 |
+
xref="paper", yref="paper",
|
206 |
+
x=1.05, y=1,
|
207 |
+
showarrow=False,
|
208 |
+
align="left",
|
209 |
+
font=dict(size=12, color="black"),
|
210 |
+
bordercolor="black",
|
211 |
+
borderwidth=1,
|
212 |
+
bgcolor="rgba(255, 255, 255, 0.8)"
|
213 |
+
)
|
214 |
+
|
215 |
+
# Add horizontal lines for min, median, avg, max
|
216 |
+
fig.add_hline(y=min_val, line_dash="dot", line_color="red", annotation_text="Min", annotation_position="bottom right")
|
217 |
+
fig.add_hline(y=median_val, line_dash="dash", line_color="orange", annotation_text="Median", annotation_position="top right")
|
218 |
+
fig.add_hline(y=avg_val, line_dash="dashdot", line_color="green", annotation_text="Avg", annotation_position="top right")
|
219 |
+
fig.add_hline(y=max_val, line_dash="dot", line_color="blue", annotation_text="Max", annotation_position="top right")
|
220 |
+
|
221 |
+
elif chart_type == "box":
|
222 |
+
# Box plots already show distribution (no extra stats needed)
|
223 |
+
pass
|
224 |
+
|
225 |
+
elif chart_type == "pie":
|
226 |
+
# Pie charts don't need statistical overlays
|
227 |
+
st.info("π Pie charts focus on proportions. No additional stats displayed.")
|
228 |
+
|
229 |
+
else:
|
230 |
+
st.warning(f"β οΈ No stats added for unsupported chart type: {chart_type}")
|
231 |
+
|
232 |
+
return fig
|
233 |
+
|
234 |
+
|
235 |
# Function to create PDF with report text and visualizations
|
236 |
def create_pdf_report_with_viz(report, conclusion, visualizations):
|
237 |
pdf = FPDF()
|