Spaces:
Running
Running
File size: 2,735 Bytes
4862c84 |
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 |
"""Logic for the **Debug Data** tab."""
from __future__ import annotations
from .state import app_state
__all__ = ["debug_data_structure"]
def debug_data_structure() -> str:
if app_state["clustered_df"] is None:
return "<p style='color: #e74c3c;'>β No data loaded</p>"
df = app_state["clustered_df"]
n_rows = len(df)
n_cols = len(df.columns)
# Check for both naming patterns
has_fine_clusters = ("property_description_fine_cluster_id" in df.columns or
"fine_cluster_id" in df.columns)
has_coarse_clusters = ("property_description_coarse_cluster_id" in df.columns or
"coarse_cluster_id" in df.columns)
sample_rows = min(3, len(df))
sample_data = df.head(sample_rows).to_html(
escape=False,
classes="table table-striped",
table_id="debug-table",
)
html = f"""
<div style="max-width: 1200px; margin: 0 auto;">
<h3>π Data Structure Debug Info</h3>
<div style="background: #f8f9fa; padding: 15px; border-radius: 8px; margin: 15px 0;">
<h4>Basic Statistics</h4>
<ul>
<li><strong>Rows:</strong> {n_rows:,}</li>
<li><strong>Columns:</strong> {n_cols}</li>
<li><strong>Fine Clusters Available:</strong> {'β
Yes' if has_fine_clusters else 'β No'}</li>
<li><strong>Coarse Clusters Available:</strong> {'β
Yes' if has_coarse_clusters else 'β No'}</li>
</ul>
</div>
<div style="background: #f8f9fa; padding: 15px; border-radius: 8px; margin: 15px 0;">
<h4>Available Columns</h4>
<div style="max-height: 200px; overflow-y: auto; background: white; padding: 10px; border-radius: 4px;">
<ul>
"""
for col in sorted(df.columns):
unique_values = df[col].nunique() if df[col].dtype == "object" else "N/A"
html += f"<li><code>{col}</code> - {df[col].dtype} (unique values: {unique_values})</li>"
html += f"""
</ul>
</div>
</div>
<div style="background: #f8f9fa; padding: 15px; border-radius: 8px; margin: 15px 0;">
<h4>Sample Data (First {sample_rows} rows)</h4>
<div style="max-height: 400px; overflow: auto; background: white; padding: 10px; border-radius: 4px;">
{sample_data}
</div>
</div>
</div>
<style>
#debug-table {{
font-size: 12px;
width: 100%;
}}
#debug-table th, #debug-table td {{
padding: 4px 8px;
border: 1px solid #ddd;
}}
#debug-table th {{
background: #f1f1f1;
}}
</style>
"""
return html |