Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,35 +5,37 @@ import random
|
|
| 5 |
|
| 6 |
# Data
|
| 7 |
agents = {
|
| 8 |
-
"Doctors":
|
| 9 |
-
"Nurses":
|
| 10 |
-
"Clinicians":
|
| 11 |
"Patients": 200
|
| 12 |
}
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
doctor_unsuccessful_treatments = random.randint(0, 10)
|
| 23 |
-
total_treatments = doctor_successful_treatments + doctor_unsuccessful_treatments
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
def
|
| 27 |
-
|
| 28 |
-
"Healthy": random.randint(0, 100),
|
| 29 |
-
"Mild Illness": random.randint(0, 100),
|
| 30 |
-
"Chronic Illness": random.randint(0, 100),
|
| 31 |
-
"Emergency": random.randint(0, 100)
|
| 32 |
-
}
|
| 33 |
-
total = sum(conditions.values())
|
| 34 |
for condition in conditions:
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# Create the gauge chart
|
| 39 |
def create_gauge(title, value, max_value):
|
|
@@ -47,18 +49,6 @@ def create_gauge(title, value, max_value):
|
|
| 47 |
fig.update_layout(template='plotly_dark')
|
| 48 |
return fig
|
| 49 |
|
| 50 |
-
# Create a function to update the gauge with different metrics
|
| 51 |
-
def create_metrics_gauge(title, value, max_value):
|
| 52 |
-
fig = go.Figure()
|
| 53 |
-
fig.add_trace(go.Indicator(
|
| 54 |
-
mode="gauge+number",
|
| 55 |
-
value=value,
|
| 56 |
-
title={'text': title},
|
| 57 |
-
gauge={'axis': {'range': [0, max_value]}}
|
| 58 |
-
))
|
| 59 |
-
fig.update_layout(template='plotly_dark')
|
| 60 |
-
return fig
|
| 61 |
-
|
| 62 |
# Button to start the animation
|
| 63 |
start_button = st.button("Start Animation")
|
| 64 |
|
|
@@ -66,45 +56,59 @@ if start_button:
|
|
| 66 |
# Placeholder for dynamic updates
|
| 67 |
placeholder = st.empty()
|
| 68 |
|
| 69 |
-
# Animation
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
for condition, count in conditions.items():
|
| 75 |
-
fig = create_gauge(f"{condition} Patients", count, agents['Patients'])
|
| 76 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 77 |
-
time.sleep(2)
|
| 78 |
-
|
| 79 |
-
# Animation for doctor emotions
|
| 80 |
-
for _ in range(1):
|
| 81 |
-
with placeholder.container():
|
| 82 |
-
st.subheader("Doctor Emotions")
|
| 83 |
-
for emotion in doctor_emotions:
|
| 84 |
-
fig = create_gauge(f"Doctor Emotion: {emotion}", random.randint(0, 100), 100)
|
| 85 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 86 |
-
time.sleep(2)
|
| 87 |
-
|
| 88 |
-
# Animation for nurse emotions
|
| 89 |
-
for _ in range(1):
|
| 90 |
-
with placeholder.container():
|
| 91 |
-
st.subheader("Nurse Emotions")
|
| 92 |
-
for emotion in nurse_emotions:
|
| 93 |
-
fig = create_gauge(f"Nurse Emotion: {emotion}", random.randint(0, 100), 100)
|
| 94 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 95 |
-
time.sleep(2)
|
| 96 |
-
|
| 97 |
-
# Animation for successful and unsuccessful treatments
|
| 98 |
-
for _ in range(1):
|
| 99 |
-
with placeholder.container():
|
| 100 |
-
st.subheader("Doctor Treatments")
|
| 101 |
-
fig = create_metrics_gauge("Successful Treatments", doctor_successful_treatments, total_treatments)
|
| 102 |
st.plotly_chart(fig, use_container_width=True)
|
| 103 |
time.sleep(2)
|
| 104 |
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
st.plotly_chart(fig, use_container_width=True)
|
| 107 |
time.sleep(2)
|
| 108 |
|
| 109 |
-
#
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Data
|
| 7 |
agents = {
|
| 8 |
+
"Doctors": 10,
|
| 9 |
+
"Nurses": 4,
|
| 10 |
+
"Clinicians": 5,
|
| 11 |
"Patients": 200
|
| 12 |
}
|
| 13 |
|
| 14 |
+
# Patient conditions and distribution
|
| 15 |
+
conditions = ["Healthy", "Mild Illness", "Chronic Illness", "Emergency"]
|
| 16 |
+
condition_counts = {
|
| 17 |
+
"Healthy": 0,
|
| 18 |
+
"Mild Illness": 0,
|
| 19 |
+
"Chronic Illness": 0,
|
| 20 |
+
"Emergency": 0
|
| 21 |
+
}
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Create random patient condition distribution
|
| 24 |
+
def distribute_patients():
|
| 25 |
+
remaining_patients = agents["Patients"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
for condition in conditions:
|
| 27 |
+
count = random.randint(0, remaining_patients)
|
| 28 |
+
condition_counts[condition] = count
|
| 29 |
+
remaining_patients -= count
|
| 30 |
+
condition_counts[conditions[-1]] += remaining_patients # Add remaining patients to last condition
|
| 31 |
+
|
| 32 |
+
# Randomly generate metrics for treatment
|
| 33 |
+
def generate_treatment_metrics():
|
| 34 |
+
total_treatments = random.randint(50, 150)
|
| 35 |
+
successful_treatments = random.randint(0, total_treatments)
|
| 36 |
+
unsuccessful_treatments = total_treatments - successful_treatments
|
| 37 |
+
patients_waiting = agents["Patients"] - total_treatments
|
| 38 |
+
return total_treatments, successful_treatments, unsuccessful_treatments, patients_waiting
|
| 39 |
|
| 40 |
# Create the gauge chart
|
| 41 |
def create_gauge(title, value, max_value):
|
|
|
|
| 49 |
fig.update_layout(template='plotly_dark')
|
| 50 |
return fig
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
# Button to start the animation
|
| 53 |
start_button = st.button("Start Animation")
|
| 54 |
|
|
|
|
| 56 |
# Placeholder for dynamic updates
|
| 57 |
placeholder = st.empty()
|
| 58 |
|
| 59 |
+
# Animation 1: Total Number of Agents
|
| 60 |
+
with placeholder.container():
|
| 61 |
+
st.subheader("Total Number of Agents")
|
| 62 |
+
for agent_type, count in agents.items():
|
| 63 |
+
fig = create_gauge(f"{agent_type}", count, 200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
st.plotly_chart(fig, use_container_width=True)
|
| 65 |
time.sleep(2)
|
| 66 |
|
| 67 |
+
# Animation 2: Distribution of Patients by Condition
|
| 68 |
+
distribute_patients()
|
| 69 |
+
with placeholder.container():
|
| 70 |
+
st.subheader("Patient Conditions Distribution")
|
| 71 |
+
for condition, count in condition_counts.items():
|
| 72 |
+
fig = create_gauge(f"Patients with {condition}", count, agents["Patients"])
|
| 73 |
st.plotly_chart(fig, use_container_width=True)
|
| 74 |
time.sleep(2)
|
| 75 |
|
| 76 |
+
# Animation 3: Number of Patients Treated
|
| 77 |
+
total_treatments, successful_treatments, unsuccessful_treatments, patients_waiting = generate_treatment_metrics()
|
| 78 |
+
with placeholder.container():
|
| 79 |
+
st.subheader("Patients Treated by Doctors")
|
| 80 |
+
fig = create_gauge("Total Treatments", total_treatments, agents["Patients"])
|
| 81 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 82 |
+
time.sleep(2)
|
| 83 |
+
|
| 84 |
+
# Animation 4: Number of Successful Treatments
|
| 85 |
+
with placeholder.container():
|
| 86 |
+
st.subheader("Successful Treatments")
|
| 87 |
+
fig = create_gauge("Successful Treatments", successful_treatments, total_treatments)
|
| 88 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 89 |
+
time.sleep(2)
|
| 90 |
+
|
| 91 |
+
# Animation 5: Number of Unsuccessful Treatments
|
| 92 |
+
with placeholder.container():
|
| 93 |
+
st.subheader("Unsuccessful Treatments")
|
| 94 |
+
fig = create_gauge("Unsuccessful Treatments", unsuccessful_treatments, total_treatments)
|
| 95 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 96 |
+
time.sleep(2)
|
| 97 |
+
|
| 98 |
+
# Animation 6: Number of Patients Waiting for Treatment
|
| 99 |
+
with placeholder.container():
|
| 100 |
+
st.subheader("Patients Waiting for Treatment")
|
| 101 |
+
fig = create_gauge("Patients Waiting", patients_waiting, agents["Patients"])
|
| 102 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 103 |
+
time.sleep(2)
|
| 104 |
+
|
| 105 |
+
# Animation 7: Remaining Metrics (Optional)
|
| 106 |
+
remaining_metrics = agents["Patients"] - (total_treatments + patients_waiting)
|
| 107 |
+
with placeholder.container():
|
| 108 |
+
st.subheader("Remaining Metrics")
|
| 109 |
+
fig = create_gauge("Remaining Metrics", remaining_metrics, agents["Patients"])
|
| 110 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 111 |
+
time.sleep(2)
|
| 112 |
+
|
| 113 |
+
# Final summary
|
| 114 |
+
st.write("**All animations complete: Healthcare metrics have been updated.**")
|