-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathHome.py
More file actions
116 lines (95 loc) · 3.66 KB
/
Home.py
File metadata and controls
116 lines (95 loc) · 3.66 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""IQB Streamlit Prototype - Main Entry Point"""
import streamlit as st
from session_state import initialize_app_state
from utils.calculation_utils import build_data_for_calculate
from visualizations.sunburst_data import (
prepare_complete_hierarchy_sunburst_data,
prepare_requirements_sunburst_data,
prepare_use_cases_sunburst_data,
)
from visualizations.sunburst_figure import (
add_iqb_score_annotation,
create_sunburst_figure,
)
from visualizations.ui_components import (
render_calculation_details,
render_config_editor,
render_measurement_inputs,
)
def initialize_session_state() -> None:
"""Initialize all session state variables using the IQBAppState dataclass."""
if "app_state" not in st.session_state:
st.session_state.app_state = initialize_app_state()
def render_sunburst(data, title: str, iqb_score: float, hierarchy_levels: int = 2):
"""Render a sunburst chart from SunburstData."""
fig = create_sunburst_figure(
data.labels,
data.parents,
data.values,
data.colors,
data.ids,
data.hover_text,
title=title,
hierarchy_levels=hierarchy_levels,
)
add_iqb_score_annotation(fig, iqb_score)
st.plotly_chart(fig, use_container_width=True, config={"staticPlot": True})
def main():
"""Main application entry point."""
st.set_page_config(page_title="IQB Prototype", page_icon="📊", layout="wide")
initialize_session_state()
state = st.session_state.app_state
st.title("Internet Quality Barometer (IQB)")
st.write("Phase 1 Prototype - Streamlit Dashboard")
st.markdown("""
### Welcome to the IQB Prototype
This dashboard implements the Internet Quality Barometer framework, which assesses
Internet quality beyond simple "speed" measurements by considering multiple use cases
and their specific network requirements.
**Current status**: Under active development
""")
# Create two-column layout
left_col, right_col = st.columns([1, 3])
# Left column - Manual measurement input
with left_col:
render_measurement_inputs(state)
# Right column - Sunburst diagrams
with right_col:
try:
data_for_calculation = build_data_for_calculate(state)
iqb_score = state.iqb.calculate_iqb_score(
data=data_for_calculation, print_details=False
)
tab1, tab2, tab3 = st.tabs(["Requirements", "Use Cases", "Full Hierarchy"])
with tab1:
render_sunburst(
prepare_requirements_sunburst_data(state),
title="Requirements → Datasets",
iqb_score=iqb_score,
)
with tab2:
render_sunburst(
prepare_use_cases_sunburst_data(state),
title="Use Cases → Datasets",
iqb_score=iqb_score,
)
with tab3:
render_sunburst(
prepare_complete_hierarchy_sunburst_data(state),
title="Use Cases → Requirements → Datasets",
iqb_score=iqb_score,
hierarchy_levels=3,
)
except KeyError as e:
st.error(f"Configuration error - missing required key: {str(e)}")
except ValueError as e:
st.error(f"Invalid configuration value: {str(e)}")
except Exception as e:
st.error(f"Error calculating IQB: {str(e)}")
st.exception(e)
# Show calculation details
render_calculation_details(state)
# Show config editor
render_config_editor(state)
if __name__ == "__main__":
main()