Ashar086 commited on
Commit
67a3977
·
verified ·
1 Parent(s): 3621f9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -63
app.py CHANGED
@@ -1,9 +1,8 @@
1
  import streamlit as st
2
  import plotly.graph_objects as go
3
- import time
4
  import random
5
 
6
- # Data
7
  agents = {
8
  "Doctors": 10,
9
  "Nurses": 4,
@@ -11,25 +10,19 @@ agents = {
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)
@@ -37,80 +30,100 @@ def generate_treatment_metrics():
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):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  fig = go.Figure()
43
  fig.add_trace(go.Indicator(
44
  mode="gauge+number",
45
  value=value,
46
  title={'text': title},
47
- gauge={'axis': {'range': [0, max_value]}}
 
48
  ))
49
  fig.update_layout(template='plotly_dark')
50
  return fig
51
 
52
- # Data Preparation
53
  distribute_patients()
54
  total_treatments, successful_treatments, unsuccessful_treatments, patients_waiting = generate_treatment_metrics()
 
 
 
55
 
56
  # Streamlit setup
57
  st.title("Interactive Healthcare Metrics")
58
 
59
  # Slider to choose the animation
60
- animation_index = st.slider("Select Animation", min_value=1, max_value=7, value=1)
61
 
62
- # Animation 1: Total Number of Agents
63
  if animation_index == 1:
64
- st.subheader("Total Number of Agents")
65
- for agent_type, count in agents.items():
66
- fig = create_gauge(f"{agent_type}", count, 200)
67
- st.plotly_chart(fig, use_container_width=True)
68
- time.sleep(2)
69
-
70
- # Animation 2: Distribution of Patients by Condition
71
- elif animation_index == 2:
72
- st.subheader("Patient Conditions Distribution")
73
  for condition, count in condition_counts.items():
74
- fig = create_gauge(f"Patients with {condition}", count, agents["Patients"])
75
  st.plotly_chart(fig, use_container_width=True)
76
- time.sleep(2)
77
 
78
- # Animation 3: Number of Patients Treated
 
 
 
 
 
 
 
 
 
 
 
79
  elif animation_index == 3:
80
- st.subheader("Patients Treated by Doctors")
81
- fig = create_gauge("Total Treatments", total_treatments, agents["Patients"])
82
- st.plotly_chart(fig, use_container_width=True)
83
- time.sleep(2)
 
84
 
85
- # Animation 4: Number of Successful Treatments
86
  elif animation_index == 4:
87
- st.subheader("Successful Treatments")
88
- fig = create_gauge("Successful Treatments", successful_treatments, total_treatments)
89
- st.plotly_chart(fig, use_container_width=True)
90
- time.sleep(2)
 
91
 
92
- # Animation 5: Number of Unsuccessful Treatments
93
  elif animation_index == 5:
94
- st.subheader("Unsuccessful Treatments")
95
- fig = create_gauge("Unsuccessful Treatments", unsuccessful_treatments, total_treatments)
96
- st.plotly_chart(fig, use_container_width=True)
97
- time.sleep(2)
98
-
99
- # Animation 6: Number of Patients Waiting for Treatment
100
- elif animation_index == 6:
101
- st.subheader("Patients Waiting for Treatment")
102
- fig = create_gauge("Patients Waiting", patients_waiting, agents["Patients"])
103
- st.plotly_chart(fig, use_container_width=True)
104
- time.sleep(2)
105
-
106
- # Animation 7: Remaining Metrics (Optional)
107
- elif animation_index == 7:
108
- remaining_metrics = agents["Patients"] - (total_treatments + patients_waiting)
109
- st.subheader("Remaining Metrics")
110
- fig = create_gauge("Remaining Metrics", remaining_metrics, agents["Patients"])
111
- st.plotly_chart(fig, use_container_width=True)
112
- time.sleep(2)
113
-
114
- # Final summary
115
- if animation_index == 7:
116
- st.write("**All animations complete: Healthcare metrics have been updated.**")
 
1
  import streamlit as st
2
  import plotly.graph_objects as go
 
3
  import random
4
 
5
+ # Data Initialization
6
  agents = {
7
  "Doctors": 10,
8
  "Nurses": 4,
 
10
  "Patients": 200
11
  }
12
 
13
+ # Distribute patients into conditions
14
  conditions = ["Healthy", "Mild Illness", "Chronic Illness", "Emergency"]
15
+ condition_counts = {condition: 0 for condition in conditions}
 
 
 
 
 
16
 
 
17
  def distribute_patients():
18
  remaining_patients = agents["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)
 
30
  patients_waiting = agents["Patients"] - total_treatments
31
  return total_treatments, successful_treatments, unsuccessful_treatments, patients_waiting
32
 
33
+ # Generate random doctor actions
34
+ def generate_doctor_actions(total_treatments):
35
+ actions = ["Prescribe Medication", "Recommend Tests", "Consult Clinician", "Schedule Surgery"]
36
+ action_counts = {action: 0 for action in actions}
37
+ for _ in range(total_treatments):
38
+ action = random.choice(actions)
39
+ action_counts[action] += 1
40
+ return action_counts
41
+
42
+ # Generate random penalties
43
+ def generate_penalties(total_treatments):
44
+ penalties = ["Wrong Medication", "Missed Diagnosis", "Incorrect Test Recommendation", "Stress-Induced Mistake"]
45
+ penalty_counts = {penalty: 0 for penalty in penalties}
46
+ for _ in range(total_treatments // 6):
47
+ penalty = random.choice(penalties)
48
+ penalty_counts[penalty] += 1
49
+ return penalty_counts
50
+
51
+ # Generate random patient feedback
52
+ def generate_feedback(total_treatments):
53
+ feedback = ["Completely Recovered", "Further Treatment Needed", "Complication"]
54
+ feedback_counts = {fb: 0 for fb in feedback}
55
+ for _ in range(total_treatments):
56
+ fb = random.choice(feedback)
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
+ # Prepare data
74
  distribute_patients()
75
  total_treatments, successful_treatments, unsuccessful_treatments, patients_waiting = generate_treatment_metrics()
76
+ doctor_actions = generate_doctor_actions(total_treatments)
77
+ penalties = generate_penalties(total_treatments)
78
+ feedback = generate_feedback(total_treatments)
79
 
80
  # Streamlit setup
81
  st.title("Interactive Healthcare Metrics")
82
 
83
  # Slider to choose the animation
84
+ animation_index = st.slider("Select Animation", min_value=1, max_value=5, value=1)
85
 
86
+ # Animation 1: Patient Conditions
87
  if animation_index == 1:
88
+ st.subheader("Patients by Condition")
 
 
 
 
 
 
 
 
89
  for condition, count in condition_counts.items():
90
+ fig = create_gauge(f"Patients with {condition}", count, agents["Patients"], {'x': [0, 1], 'y': [0, 1]}, 'blue')
91
  st.plotly_chart(fig, use_container_width=True)
92
+ st.markdown("---")
93
 
94
+ # Animation 2: Treatment Metrics
95
+ elif animation_index == 2:
96
+ st.subheader("Treatment Metrics")
97
+ fig1 = create_gauge("Total Patients", agents["Patients"], agents["Patients"], {'x': [0, 0.5], 'y': [0, 1]}, 'green')
98
+ fig2 = create_gauge("Successful Treatments", successful_treatments, total_treatments, {'x': [0.5, 1], 'y': [0, 0.5]}, 'orange')
99
+ fig3 = create_gauge("Unsuccessful Treatments", unsuccessful_treatments, total_treatments, {'x': [0.5, 1], 'y': [0.5, 1]}, 'red')
100
+ st.plotly_chart(fig1, use_container_width=True)
101
+ st.plotly_chart(fig2, use_container_width=True)
102
+ st.plotly_chart(fig3, use_container_width=True)
103
+ st.markdown("---")
104
+
105
+ # Animation 3: Doctor Actions
106
  elif animation_index == 3:
107
+ st.subheader("Doctor Actions")
108
+ for action, count in doctor_actions.items():
109
+ fig = create_gauge(f"Doctor Action: {action}", count, total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'purple')
110
+ st.plotly_chart(fig, use_container_width=True)
111
+ st.markdown("---")
112
 
113
+ # Animation 4: Penalties
114
  elif animation_index == 4:
115
+ st.subheader("Penalties")
116
+ for penalty, count in penalties.items():
117
+ fig = create_gauge(f"Penalty: {penalty}", count, total_treatments // 6, {'x': [0, 1], 'y': [0, 1]}, 'red')
118
+ st.plotly_chart(fig, use_container_width=True)
119
+ st.markdown("---")
120
 
121
+ # Animation 5: Patient Feedback
122
  elif animation_index == 5:
123
+ st.subheader("Patient Feedback")
124
+ for fb, count in feedback.items():
125
+ fig = create_gauge(f"Feedback: {fb}", count, total_treatments, {'x': [0, 1], 'y': [0, 1]}, 'blue')
126
+ st.plotly_chart(fig, use_container_width=True)
127
+ st.markdown("---")
128
+
129
+ st.write("**End of Animations.**")