awacke1 commited on
Commit
6859c68
Β·
1 Parent(s): f8e9ef8

Update backupapp.py

Browse files
Files changed (1) hide show
  1. backupapp.py +53 -46
backupapp.py CHANGED
@@ -4,53 +4,60 @@ import random
4
  import plotly.graph_objects as go
5
  import plotly.express as px
6
 
7
- # Define the states and conditions of interest
8
- states = ["Minnesota", "Florida", "California"]
9
- top_n = 10
10
-
11
- # Define the list dictionary of top 10 health conditions descending by cost, with emojis
12
- health_conditions = [
13
- {"condition": "πŸ’” Heart disease", "emoji": "πŸ’—", "spending": 214.3},
14
- {"condition": "πŸ€• Trauma-related disorders", "emoji": "πŸš‘", "spending": 198.6},
15
- {"condition": "πŸ¦€ Cancer", "emoji": "πŸŽ—οΈ", "spending": 171.0},
16
- {"condition": "🧠 Mental disorders", "emoji": "🧘", "spending": 150.8},
17
- {"condition": "🦴 Osteoarthritis and joint disorders", "emoji": "πŸ₯", "spending": 142.4},
18
- {"condition": "πŸ’‰ Diabetes", "emoji": "🩸", "spending": 107.4},
19
- {"condition": "🫁 Chronic obstructive pulmonary disease and asthma", "emoji": "πŸ«€", "spending": 91.0},
20
- {"condition": "🩺 Hypertension", "emoji": "πŸ’‰", "spending": 83.9},
21
- {"condition": "πŸ”¬ Hyperlipidemia", "emoji": "πŸ”¬", "spending": 83.9},
22
- {"condition": "🦴 Back problems", "emoji": "🧍", "spending": 67.0}
23
- ]
24
-
25
- # Create a DataFrame from the list dictionary
26
- df_top_conditions = pd.DataFrame(health_conditions)
27
-
28
- # Calculate the total spending
29
- total_spending = round(df_top_conditions["spending"].sum(), 1)
30
-
31
- # Define the roll function
32
- def roll():
33
- # Generate a thousand 10-sided dice rolls for each health condition
34
- rolls = [random.randint(1, 10) for _ in range(1000)]
35
- # Calculate the frequency of each variant
36
- frequencies = [rolls.count(i) for i in range(1, 11)]
37
- return frequencies
38
-
39
- # Define the sunburst chart
40
- fig_sunburst = go.Figure(go.Sunburst(
41
- labels=df_top_conditions["emoji"] + " " + df_top_conditions["condition"],
42
- parents=[""] * top_n,
43
- values=df_top_conditions["spending"],
44
- maxdepth=2
45
- ))
46
-
47
- # Customize the layout of the sunburst chart
48
- fig_sunburst.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
49
-
50
- # Display the sunburst chart and variants per condition in the Streamlit app
51
- st.plotly_chart(fig_sunburst)
52
- for index, row in df_top_conditions.iterrows():
 
 
 
 
53
  frequencies = roll()
54
  fig_bar = px.bar(x=[f"Variant {i}" for i in range(1, 11)], y=frequencies[:10], labels={'x': 'Variant', 'y': 'Frequency'})
55
  fig_bar.update_layout(title=f"Variants of {row['condition']} ({row['emoji']})")
56
  st.plotly_chart(fig_bar)
 
 
 
 
4
  import plotly.graph_objects as go
5
  import plotly.express as px
6
 
7
+ def health_game():
8
+ # Define the states and conditions of interest
9
+ states = ["Minnesota", "Florida", "California"]
10
+ top_n = 10
11
+
12
+ # Define the list dictionary of top 10 health conditions descending by cost, with emojis, treatment recommendation and potential savings
13
+ health_conditions = [
14
+ {"condition": "πŸ’” Heart disease", "emoji": "πŸ’—", "spending": 214.3, "treatment": "Regular checkups with a cardiologist", "savings": "$1000"},
15
+ {"condition": "πŸ€• Trauma-related disorders", "emoji": "πŸš‘", "spending": 198.6, "treatment": "Counseling and physical therapy", "savings": "$500"},
16
+ {"condition": "πŸ¦€ Cancer", "emoji": "πŸŽ—οΈ", "spending": 171.0, "treatment": "Early detection and treatment", "savings": "$2000"},
17
+ {"condition": "🧠 Mental disorders", "emoji": "🧘", "spending": 150.8, "treatment": "Therapy and medication", "savings": "$1500"},
18
+ {"condition": "🦴 Osteoarthritis and joint disorders", "emoji": "πŸ₯", "spending": 142.4, "treatment": "Low-impact exercise and physical therapy", "savings": "$800"},
19
+ {"condition": "πŸ’‰ Diabetes", "emoji": "🩸", "spending": 107.4, "treatment": "Regular checkups and medication", "savings": "$1200"},
20
+ {"condition": "🫁 Chronic obstructive pulmonary disease and asthma", "emoji": "πŸ«€", "spending": 91.0, "treatment": "Inhalers and breathing exercises", "savings": "$600"},
21
+ {"condition": "🩺 Hypertension", "emoji": "πŸ’‰", "spending": 83.9, "treatment": "Lifestyle changes and medication", "savings": "$900"},
22
+ {"condition": "πŸ”¬ Hyperlipidemia", "emoji": "πŸ”¬", "spending": 83.9, "treatment": "Lifestyle changes and medication", "savings": "$700"},
23
+ {"condition": "🦴 Back problems", "emoji": "🧍", "spending": 67.0, "treatment": "Physical therapy and exercise", "savings": "$400"}
24
+ ]
25
+
26
+ # Create a DataFrame from the list dictionary
27
+ df_top_conditions = pd.DataFrame(health_conditions)
28
+
29
+ # Calculate the total spending
30
+ total_spending = round(df_top_conditions["spending"].sum(), 1)
31
+
32
+ # Define the roll function
33
+ def roll():
34
+ rolls = [random.randint(1, 10) for _ in range(1000)]
35
+ frequencies = [rolls.count(i) for i in range(1, 11)]
36
+ return frequencies
37
+
38
+ # Define the sunburst chart
39
+ fig_sunburst = go.Figure(go.Sunburst(
40
+ labels=df_top_conditions["emoji"] + " " + df_top_conditions["condition"],
41
+ parents=[""] * top_n,
42
+ values=df_top_conditions["spending"],
43
+ maxdepth=2
44
+ ))
45
+
46
+ # Customize the layout of the sunburst chart
47
+
48
+ fig_sunburst.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
49
+
50
+ # Display the sunburst chart and variants per condition in the Streamlit app
51
+ st.plotly_chart(fig_sunburst)
52
+ condition_idx = st.selectbox("Select your current health condition", df_top_conditions.index)
53
+ row = df_top_conditions.loc[condition_idx]
54
+
55
+ st.write(f"Based on the severity of your {row['condition']}, we recommend {row['treatment']} for early treatment. This could save you up to {row['savings']} in healthcare costs.")
56
+
57
  frequencies = roll()
58
  fig_bar = px.bar(x=[f"Variant {i}" for i in range(1, 11)], y=frequencies[:10], labels={'x': 'Variant', 'y': 'Frequency'})
59
  fig_bar.update_layout(title=f"Variants of {row['condition']} ({row['emoji']})")
60
  st.plotly_chart(fig_bar)
61
+
62
+
63
+ health_game()