Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,32 +2,49 @@ import streamlit as st
|
|
| 2 |
import plotly.graph_objects as go
|
| 3 |
import random
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def distribute_patients():
|
| 18 |
-
remaining_patients =
|
|
|
|
|
|
|
| 19 |
for condition in conditions:
|
| 20 |
count = random.randint(0, remaining_patients)
|
| 21 |
condition_counts[condition] = count
|
| 22 |
remaining_patients -= count
|
| 23 |
condition_counts[conditions[-1]] += remaining_patients
|
|
|
|
| 24 |
|
| 25 |
# Generate random treatment metrics
|
| 26 |
def generate_treatment_metrics():
|
| 27 |
total_treatments = random.randint(50, 150)
|
| 28 |
successful_treatments = random.randint(0, total_treatments)
|
| 29 |
unsuccessful_treatments = total_treatments - successful_treatments
|
| 30 |
-
patients_waiting =
|
| 31 |
return total_treatments, successful_treatments, unsuccessful_treatments, patients_waiting
|
| 32 |
|
| 33 |
# Generate random doctor actions
|
|
@@ -57,48 +74,36 @@ def generate_feedback(total_treatments):
|
|
| 57 |
feedback_counts[fb] += 1
|
| 58 |
return feedback_counts
|
| 59 |
|
| 60 |
-
# Function to create gauge chart
|
| 61 |
-
def create_gauge(title, value, max_value, domain, gauge_color):
|
| 62 |
-
fig = go.Figure()
|
| 63 |
-
fig.add_trace(go.Indicator(
|
| 64 |
-
mode="gauge+number",
|
| 65 |
-
value=value,
|
| 66 |
-
title={'text': title},
|
| 67 |
-
domain=domain,
|
| 68 |
-
gauge={'axis': {'range': [0, max_value]}, 'bar': {'color': gauge_color}}
|
| 69 |
-
))
|
| 70 |
-
fig.update_layout(template='plotly_dark')
|
| 71 |
-
return fig
|
| 72 |
-
|
| 73 |
# Streamlit setup
|
| 74 |
st.title("Interactive Healthcare Metrics")
|
| 75 |
|
| 76 |
# Button to run the animations
|
| 77 |
if st.button("Run Animations"):
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
| 85 |
# Slider to choose the animation
|
| 86 |
animation_index = st.slider("Select Animation", min_value=1, max_value=5, value=1)
|
| 87 |
|
| 88 |
# Animation 1: Patient Conditions
|
| 89 |
if animation_index == 1:
|
| 90 |
st.subheader("Patients by Condition")
|
| 91 |
-
for condition, count in condition_counts.items():
|
| 92 |
-
fig = create_gauge(f"Patients with {condition}", count,
|
| 93 |
st.plotly_chart(fig, use_container_width=True)
|
| 94 |
st.markdown("---")
|
| 95 |
|
| 96 |
# Animation 2: Treatment Metrics
|
| 97 |
elif animation_index == 2:
|
| 98 |
st.subheader("Treatment Metrics")
|
| 99 |
-
fig1 = create_gauge("Total Patients",
|
| 100 |
-
fig2 = create_gauge("Successful Treatments", successful_treatments, total_treatments, {'x': [0.5, 1], 'y': [0, 0.5]}, 'orange')
|
| 101 |
-
fig3 = create_gauge("Unsuccessful Treatments", unsuccessful_treatments, total_treatments, {'x': [0.5, 1], 'y': [0.5, 1]}, 'red')
|
| 102 |
st.plotly_chart(fig1, use_container_width=True)
|
| 103 |
st.plotly_chart(fig2, use_container_width=True)
|
| 104 |
st.plotly_chart(fig3, use_container_width=True)
|
|
@@ -107,24 +112,24 @@ if st.button("Run Animations"):
|
|
| 107 |
# Animation 3: Doctor Actions
|
| 108 |
elif animation_index == 3:
|
| 109 |
st.subheader("Doctor Actions")
|
| 110 |
-
for action, count in doctor_actions.items():
|
| 111 |
-
fig = create_gauge(f"Doctor Action: {action}", count, total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'purple')
|
| 112 |
st.plotly_chart(fig, use_container_width=True)
|
| 113 |
st.markdown("---")
|
| 114 |
|
| 115 |
# Animation 4: Penalties
|
| 116 |
elif animation_index == 4:
|
| 117 |
st.subheader("Penalties")
|
| 118 |
-
for penalty, count in penalties.items():
|
| 119 |
-
fig = create_gauge(f"Penalty: {penalty}", count, total_treatments // 6, {'x': [0, 1], 'y': [0, 1]}, 'red')
|
| 120 |
st.plotly_chart(fig, use_container_width=True)
|
| 121 |
st.markdown("---")
|
| 122 |
|
| 123 |
# Animation 5: Patient Feedback
|
| 124 |
elif animation_index == 5:
|
| 125 |
st.subheader("Patient Feedback")
|
| 126 |
-
for fb, count in feedback.items():
|
| 127 |
-
fig = create_gauge(f"Feedback: {fb}", count, total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'blue')
|
| 128 |
st.plotly_chart(fig, use_container_width=True)
|
| 129 |
st.markdown("---")
|
| 130 |
|
|
|
|
| 2 |
import plotly.graph_objects as go
|
| 3 |
import random
|
| 4 |
|
| 5 |
+
# Initialize session state
|
| 6 |
+
if 'initialized' not in st.session_state:
|
| 7 |
+
st.session_state.initialized = False
|
| 8 |
+
st.session_state.condition_counts = {}
|
| 9 |
+
st.session_state.total_treatments = 0
|
| 10 |
+
st.session_state.successful_treatments = 0
|
| 11 |
+
st.session_state.unsuccessful_treatments = 0
|
| 12 |
+
st.session_state.patients_waiting = 0
|
| 13 |
+
st.session_state.doctor_actions = {}
|
| 14 |
+
st.session_state.penalties = {}
|
| 15 |
+
st.session_state.feedback = {}
|
| 16 |
|
| 17 |
+
# Function to create gauge chart
|
| 18 |
+
def create_gauge(title, value, max_value, domain, gauge_color):
|
| 19 |
+
fig = go.Figure()
|
| 20 |
+
fig.add_trace(go.Indicator(
|
| 21 |
+
mode="gauge+number",
|
| 22 |
+
value=value,
|
| 23 |
+
title={'text': title},
|
| 24 |
+
domain=domain,
|
| 25 |
+
gauge={'axis': {'range': [0, max_value]}, 'bar': {'color': gauge_color}}
|
| 26 |
+
))
|
| 27 |
+
fig.update_layout(template='plotly_dark')
|
| 28 |
+
return fig
|
| 29 |
+
|
| 30 |
+
# Generate random patient condition distribution
|
| 31 |
def distribute_patients():
|
| 32 |
+
remaining_patients = 200
|
| 33 |
+
conditions = ["Healthy", "Mild Illness", "Chronic Illness", "Emergency"]
|
| 34 |
+
condition_counts = {condition: 0 for condition in conditions}
|
| 35 |
for condition in conditions:
|
| 36 |
count = random.randint(0, remaining_patients)
|
| 37 |
condition_counts[condition] = count
|
| 38 |
remaining_patients -= count
|
| 39 |
condition_counts[conditions[-1]] += remaining_patients
|
| 40 |
+
return condition_counts
|
| 41 |
|
| 42 |
# Generate random treatment metrics
|
| 43 |
def generate_treatment_metrics():
|
| 44 |
total_treatments = random.randint(50, 150)
|
| 45 |
successful_treatments = random.randint(0, total_treatments)
|
| 46 |
unsuccessful_treatments = total_treatments - successful_treatments
|
| 47 |
+
patients_waiting = 200 - total_treatments
|
| 48 |
return total_treatments, successful_treatments, unsuccessful_treatments, patients_waiting
|
| 49 |
|
| 50 |
# Generate random doctor actions
|
|
|
|
| 74 |
feedback_counts[fb] += 1
|
| 75 |
return feedback_counts
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# Streamlit setup
|
| 78 |
st.title("Interactive Healthcare Metrics")
|
| 79 |
|
| 80 |
# Button to run the animations
|
| 81 |
if st.button("Run Animations"):
|
| 82 |
+
st.session_state.condition_counts = distribute_patients()
|
| 83 |
+
st.session_state.total_treatments, st.session_state.successful_treatments, st.session_state.unsuccessful_treatments, st.session_state.patients_waiting = generate_treatment_metrics()
|
| 84 |
+
st.session_state.doctor_actions = generate_doctor_actions(st.session_state.total_treatments)
|
| 85 |
+
st.session_state.penalties = generate_penalties(st.session_state.total_treatments)
|
| 86 |
+
st.session_state.feedback = generate_feedback(st.session_state.total_treatments)
|
| 87 |
+
st.session_state.initialized = True
|
| 88 |
+
|
| 89 |
+
if st.session_state.initialized:
|
| 90 |
# Slider to choose the animation
|
| 91 |
animation_index = st.slider("Select Animation", min_value=1, max_value=5, value=1)
|
| 92 |
|
| 93 |
# Animation 1: Patient Conditions
|
| 94 |
if animation_index == 1:
|
| 95 |
st.subheader("Patients by Condition")
|
| 96 |
+
for condition, count in st.session_state.condition_counts.items():
|
| 97 |
+
fig = create_gauge(f"Patients with {condition}", count, 200, {'x': [0, 1], 'y': [0, 1]}, 'blue')
|
| 98 |
st.plotly_chart(fig, use_container_width=True)
|
| 99 |
st.markdown("---")
|
| 100 |
|
| 101 |
# Animation 2: Treatment Metrics
|
| 102 |
elif animation_index == 2:
|
| 103 |
st.subheader("Treatment Metrics")
|
| 104 |
+
fig1 = create_gauge("Total Patients", 200, 200, {'x': [0, 0.5], 'y': [0, 1]}, 'green')
|
| 105 |
+
fig2 = create_gauge("Successful Treatments", st.session_state.successful_treatments, st.session_state.total_treatments, {'x': [0.5, 1], 'y': [0, 0.5]}, 'orange')
|
| 106 |
+
fig3 = create_gauge("Unsuccessful Treatments", st.session_state.unsuccessful_treatments, st.session_state.total_treatments, {'x': [0.5, 1], 'y': [0.5, 1]}, 'red')
|
| 107 |
st.plotly_chart(fig1, use_container_width=True)
|
| 108 |
st.plotly_chart(fig2, use_container_width=True)
|
| 109 |
st.plotly_chart(fig3, use_container_width=True)
|
|
|
|
| 112 |
# Animation 3: Doctor Actions
|
| 113 |
elif animation_index == 3:
|
| 114 |
st.subheader("Doctor Actions")
|
| 115 |
+
for action, count in st.session_state.doctor_actions.items():
|
| 116 |
+
fig = create_gauge(f"Doctor Action: {action}", count, st.session_state.total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'purple')
|
| 117 |
st.plotly_chart(fig, use_container_width=True)
|
| 118 |
st.markdown("---")
|
| 119 |
|
| 120 |
# Animation 4: Penalties
|
| 121 |
elif animation_index == 4:
|
| 122 |
st.subheader("Penalties")
|
| 123 |
+
for penalty, count in st.session_state.penalties.items():
|
| 124 |
+
fig = create_gauge(f"Penalty: {penalty}", count, st.session_state.total_treatments // 6, {'x': [0, 1], 'y': [0, 1]}, 'red')
|
| 125 |
st.plotly_chart(fig, use_container_width=True)
|
| 126 |
st.markdown("---")
|
| 127 |
|
| 128 |
# Animation 5: Patient Feedback
|
| 129 |
elif animation_index == 5:
|
| 130 |
st.subheader("Patient Feedback")
|
| 131 |
+
for fb, count in st.session_state.feedback.items():
|
| 132 |
+
fig = create_gauge(f"Feedback: {fb}", count, st.session_state.total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'blue')
|
| 133 |
st.plotly_chart(fig, use_container_width=True)
|
| 134 |
st.markdown("---")
|
| 135 |
|