Spaces:
Sleeping
Sleeping
File size: 6,119 Bytes
51fc905 6bed8d7 51fc905 6bed8d7 fc83c17 74711a9 fc83c17 4a1ded9 fc83c17 74711a9 4a1ded9 67a3977 fc83c17 4a1ded9 67a3977 4a1ded9 7825ad6 4a1ded9 fc83c17 4a1ded9 74711a9 67a3977 3621f9d 7eaf733 fc83c17 f4f73fd 7eaf733 f4f73fd 7eaf733 f4f73fd 67a3977 7eaf733 f4f73fd 7eaf733 f4f73fd 7eaf733 f4f73fd 7eaf733 f4f73fd |
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
import streamlit as st
import plotly.graph_objects as go
import random
# Initialize session state
if 'initialized' not in st.session_state:
st.session_state.initialized = False
st.session_state.condition_counts = {}
st.session_state.total_treatments = 0
st.session_state.successful_treatments = 0
st.session_state.unsuccessful_treatments = 0
st.session_state.patients_waiting = 0
st.session_state.doctor_actions = {}
st.session_state.penalties = {}
st.session_state.feedback = {}
# Function to create gauge chart
def create_gauge(title, value, max_value, domain, gauge_color):
fig = go.Figure()
fig.add_trace(go.Indicator(
mode="gauge+number",
value=value,
title={'text': title},
domain=domain,
gauge={'axis': {'range': [0, max_value]}, 'bar': {'color': gauge_color}}
))
fig.update_layout(template='plotly_dark')
return fig
# Generate random patient condition distribution
def distribute_patients():
remaining_patients = 200
conditions = ["Healthy", "Mild Illness", "Chronic Illness", "Emergency"]
condition_counts = {condition: 0 for condition in conditions}
for condition in conditions:
count = random.randint(0, remaining_patients)
condition_counts[condition] = count
remaining_patients -= count
condition_counts[conditions[-1]] += remaining_patients
return condition_counts
# Generate random treatment metrics
def generate_treatment_metrics():
total_treatments = random.randint(50, 150)
successful_treatments = random.randint(0, total_treatments)
unsuccessful_treatments = total_treatments - successful_treatments
patients_waiting = 200 - total_treatments
return total_treatments, successful_treatments, unsuccessful_treatments, patients_waiting
# Generate random doctor actions
def generate_doctor_actions(total_treatments):
actions = ["Prescribe Medication", "Recommend Tests", "Consult Clinician", "Schedule Surgery"]
action_counts = {action: 0 for action in actions}
for _ in range(total_treatments):
action = random.choice(actions)
action_counts[action] += 1
return action_counts
# Generate random penalties
def generate_penalties(total_treatments):
penalties = ["Wrong Medication", "Missed Diagnosis", "Incorrect Test Recommendation", "Stress-Induced Mistake"]
penalty_counts = {penalty: 0 for penalty in penalties}
for _ in range(total_treatments // 6):
penalty = random.choice(penalties)
penalty_counts[penalty] += 1
return penalty_counts
# Generate random patient feedback
def generate_feedback(total_treatments):
feedback = ["Completely Recovered", "Further Treatment Needed", "Complication"]
feedback_counts = {fb: 0 for fb in feedback}
for _ in range(total_treatments):
fb = random.choice(feedback)
feedback_counts[fb] += 1
return feedback_counts
# Streamlit setup
st.title("Interactive Healthcare Metrics")
# Button to run the animations
if st.button("Run Animations"):
st.session_state.condition_counts = distribute_patients()
st.session_state.total_treatments, st.session_state.successful_treatments, st.session_state.unsuccessful_treatments, st.session_state.patients_waiting = generate_treatment_metrics()
st.session_state.doctor_actions = generate_doctor_actions(st.session_state.total_treatments)
st.session_state.penalties = generate_penalties(st.session_state.total_treatments)
st.session_state.feedback = generate_feedback(st.session_state.total_treatments)
st.session_state.initialized = True
if st.session_state.initialized:
# Slider to choose the animation
animation_index = st.slider("Select Animation", min_value=1, max_value=5, value=1)
# Animation 1: Patient Conditions
if animation_index == 1:
st.subheader("Patients by Condition")
for condition, count in st.session_state.condition_counts.items():
fig = create_gauge(f"Patients with {condition}", count, 200, {'x': [0, 1], 'y': [0, 1]}, 'blue')
st.plotly_chart(fig, use_container_width=True)
st.markdown("---")
# Animation 2: Treatment Metrics
elif animation_index == 2:
st.subheader("Treatment Metrics")
fig1 = create_gauge("Total Patients", 200, 200, {'x': [0, 0.5], 'y': [0, 1]}, 'green')
fig2 = create_gauge("Successful Treatments", st.session_state.successful_treatments, st.session_state.total_treatments, {'x': [0.5, 1], 'y': [0, 0.5]}, 'orange')
fig3 = create_gauge("Unsuccessful Treatments", st.session_state.unsuccessful_treatments, st.session_state.total_treatments, {'x': [0.5, 1], 'y': [0.5, 1]}, 'red')
st.plotly_chart(fig1, use_container_width=True)
st.plotly_chart(fig2, use_container_width=True)
st.plotly_chart(fig3, use_container_width=True)
st.markdown("---")
# Animation 3: Doctor Actions
elif animation_index == 3:
st.subheader("Doctor Actions")
for action, count in st.session_state.doctor_actions.items():
fig = create_gauge(f"Doctor Action: {action}", count, st.session_state.total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'purple')
st.plotly_chart(fig, use_container_width=True)
st.markdown("---")
# Animation 4: Penalties
elif animation_index == 4:
st.subheader("Penalties")
for penalty, count in st.session_state.penalties.items():
fig = create_gauge(f"Penalty: {penalty}", count, st.session_state.total_treatments // 6, {'x': [0, 1], 'y': [0, 1]}, 'red')
st.plotly_chart(fig, use_container_width=True)
st.markdown("---")
# Animation 5: Patient Feedback
elif animation_index == 5:
st.subheader("Patient Feedback")
for fb, count in st.session_state.feedback.items():
fig = create_gauge(f"Feedback: {fb}", count, st.session_state.total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'blue')
st.plotly_chart(fig, use_container_width=True)
st.markdown("---")
st.write("**End of Animations.**")
|