File size: 4,980 Bytes
fdfcd02
f28151c
1d136fa
f28151c
 
fdfcd02
ab34103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f28151c
ab34103
 
 
 
 
 
1d136fa
f28151c
ab34103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f28151c
1d136fa
f28151c
ab34103
 
 
 
 
 
 
 
 
 
 
f28151c
1d136fa
f28151c
ab34103
 
c94158d
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
import streamlit as st
import pandas as pd
import random
import plotly.graph_objects as go
import plotly.express as px

def generate_health_conditions():
    return [
        {"condition": "๐Ÿ’” Heart disease", "emoji": "๐Ÿ’—", "spending": {"Minnesota": 100, "Florida": 150, "California": 200, "New York": 120, "Texas": 180}, "treatment": "Regular checkups with a cardiologist", "savings": "$1000"},
        {"condition": "๐Ÿค• Trauma-related disorders", "emoji": "๐Ÿš‘", "spending": {"Minnesota": 90, "Florida": 110, "California": 150, "New York": 100, "Texas": 130}, "treatment": "Counseling and physical therapy", "savings": "$500"},
        {"condition": "๐Ÿฆ€ Cancer", "emoji": "๐ŸŽ—๏ธ", "spending": {"Minnesota": 80, "Florida": 120, "California": 180, "New York": 100, "Texas": 150}, "treatment": "Early detection and treatment", "savings": "$2000"},
        {"condition": "๐Ÿง  Mental disorders", "emoji": "๐Ÿง˜", "spending": {"Minnesota": 70, "Florida": 100, "California": 140, "New York": 90, "Texas": 120}, "treatment": "Therapy and medication", "savings": "$1500"},
        {"condition": "๐Ÿฆด Osteoarthritis and joint disorders", "emoji": "๐Ÿฅ", "spending": {"Minnesota": 60, "Florida": 90, "California": 120, "New York": 80, "Texas": 100}, "treatment": "Low-impact exercise and physical therapy", "savings": "$800"},
        {"condition": "๐Ÿ’‰ Diabetes", "emoji": "๐Ÿฉธ", "spending": {"Minnesota": 50, "Florida": 80, "California": 100, "New York": 60, "Texas": 90}, "treatment": "Regular checkups and medication", "savings": "$1200"},
        {"condition": "๐Ÿซ Chronic obstructive pulmonary disease and asthma", "emoji": "๐Ÿซ€", "spending": {"Minnesota": 40, "Florida": 70, "California": 90, "New York": 50, "Texas": 80}, "treatment": "Inhalers and breathing exercises", "savings": "$600"},
        {"condition": "๐Ÿฉบ Hypertension", "emoji": "๐Ÿ’‰", "spending": {"Minnesota": 30, "Florida": 60, "California": 80, "New York": 40, "Texas": 70}, "treatment": "Lifestyle changes and medication", "savings": "$900"},
        {"condition": "๐Ÿ”ฌ Hyperlipidemia", "emoji": "๐Ÿ”ฌ", "spending": {"Minnesota": 20, "Florida": 50, "California": 70, "New York": 30, "Texas": 60}, "treatment": "Lifestyle changes and medication", "savings": "$700"},
        {"condition": "๐Ÿฆด Back problems", "emoji": "๐Ÿง", "spending": {"Minnesota": 10, "Florida": 40,

                                                                    def calculate_total_spending(health_conditions):
    total_spending = 0
    for condition in health_conditions:
        for state, spending in condition["spending"].items():
            total_spending += spending
    return round(total_spending, 1)

def generate_sunburst_chart(health_conditions, total_spending):
    fig_sunburst = go.Figure(go.Treemap(
        labels=[f"{condition['emoji']} {condition['condition']} ({state})" for condition in health_conditions for state in condition['spending'].keys()],
        parents=[f"{condition['condition']} ({state})" for condition in health_conditions for state in condition['spending'].keys()],
        values=[spending for condition in health_conditions for spending in condition['spending'].values()],
        branchvalues="total",
    ))

    fig_sunburst.update_layout(
        title=f"Top Health Conditions in Different States by Spending (Total: ${total_spending}B)",
        margin=dict(l=0, r=0, t=50, b=0),
    )
    return fig_sunburst

def roll(state, condition):
    frequencies = [random.randint(1, 10) for _ in range(1000)]
    spending = condition["spending"][state]
    frequencies = [round(frequency * spending / 100, 1) for frequency in frequencies]
    return frequencies

def generate_bar_chart(state, condition, frequencies):
    fig_bar = px.bar(
        x=[f"Variant {i}" for i in range(1, 11)],
        y=frequencies[:10],
        labels={'x': 'Variant', 'y': 'Cost'},
        title=f"Variants of {condition['condition']} ({condition['emoji']}) in {state}",
    )
    return fig_bar

def generate_recommendation(condition):
    return f"Based on the severity of your {condition['condition']}, we recommend {condition['treatment']} for early treatment. This could save you up to {condition['savings']} in healthcare costs."

def main():
    states = ["Minnesota", "Florida", "California", "New York", "Texas"]
    top_n = 10

    health_conditions = generate_health_conditions()

    total_spending = calculate_total_spending(health_conditions)

    fig_sunburst = generate_sunburst_chart(health_conditions, total_spending)

    st.plotly_chart(fig_sunburst)

    condition_idx = st.selectbox("Select your current health condition", range(top_n))

    condition = health_conditions[condition_idx]

    st.write(generate_recommendation(condition))

    state = st.selectbox("Select your state", states)

    frequencies = roll(state, condition)

    fig_bar = generate_bar_chart(state, condition, frequencies)

    st.plotly_chart(fig_bar)

if __name__ == "__main__":
    main()