File size: 3,555 Bytes
64b053f
 
 
 
 
 
6859c68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64b053f
 
 
 
6859c68
 
 
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
import streamlit as st
import pandas as pd
import random
import plotly.graph_objects as go
import plotly.express as px

def health_game():
    # Define the states and conditions of interest
    states = ["Minnesota", "Florida", "California"]
    top_n = 10

    # Define the list dictionary of top 10 health conditions descending by cost, with emojis, treatment recommendation and potential savings
    health_conditions = [
        {"condition": "๐Ÿ’” Heart disease", "emoji": "๐Ÿ’—", "spending": 214.3, "treatment": "Regular checkups with a cardiologist", "savings": "$1000"},
        {"condition": "๐Ÿค• Trauma-related disorders", "emoji": "๐Ÿš‘", "spending": 198.6, "treatment": "Counseling and physical therapy", "savings": "$500"},
        {"condition": "๐Ÿฆ€ Cancer", "emoji": "๐ŸŽ—๏ธ", "spending": 171.0, "treatment": "Early detection and treatment", "savings": "$2000"},
        {"condition": "๐Ÿง  Mental disorders", "emoji": "๐Ÿง˜", "spending": 150.8, "treatment": "Therapy and medication", "savings": "$1500"},
        {"condition": "๐Ÿฆด Osteoarthritis and joint disorders", "emoji": "๐Ÿฅ", "spending": 142.4, "treatment": "Low-impact exercise and physical therapy", "savings": "$800"},
        {"condition": "๐Ÿ’‰ Diabetes", "emoji": "๐Ÿฉธ", "spending": 107.4, "treatment": "Regular checkups and medication", "savings": "$1200"},
        {"condition": "๐Ÿซ Chronic obstructive pulmonary disease and asthma", "emoji": "๐Ÿซ€", "spending": 91.0, "treatment": "Inhalers and breathing exercises", "savings": "$600"},
        {"condition": "๐Ÿฉบ Hypertension", "emoji": "๐Ÿ’‰", "spending": 83.9, "treatment": "Lifestyle changes and medication", "savings": "$900"},
        {"condition": "๐Ÿ”ฌ Hyperlipidemia", "emoji": "๐Ÿ”ฌ", "spending": 83.9, "treatment": "Lifestyle changes and medication", "savings": "$700"},
        {"condition": "๐Ÿฆด Back problems", "emoji": "๐Ÿง", "spending": 67.0, "treatment": "Physical therapy and exercise", "savings": "$400"}
    ]

    # Create a DataFrame from the list dictionary
    df_top_conditions = pd.DataFrame(health_conditions)

    # Calculate the total spending
    total_spending = round(df_top_conditions["spending"].sum(), 1)

    # Define the roll function
    def roll():
        rolls = [random.randint(1, 10) for _ in range(1000)]
        frequencies = [rolls.count(i) for i in range(1, 11)]
        return frequencies

    # Define the sunburst chart
    fig_sunburst = go.Figure(go.Sunburst(
        labels=df_top_conditions["emoji"] + " " + df_top_conditions["condition"],
        parents=[""] * top_n,
        values=df_top_conditions["spending"],
        maxdepth=2
    ))

    # Customize the layout of the sunburst chart
   
    fig_sunburst.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")

    # Display the sunburst chart and variants per condition in the Streamlit app
    st.plotly_chart(fig_sunburst)
    condition_idx = st.selectbox("Select your current health condition", df_top_conditions.index)
    row = df_top_conditions.loc[condition_idx]

    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.")

    frequencies = roll()
    fig_bar = px.bar(x=[f"Variant {i}" for i in range(1, 11)], y=frequencies[:10], labels={'x': 'Variant', 'y': 'Frequency'})
    fig_bar.update_layout(title=f"Variants of {row['condition']} ({row['emoji']})")
    st.plotly_chart(fig_bar)


health_game()