Jiranuwat commited on
Commit
6469332
·
1 Parent(s): 6d7abe9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -9,13 +9,25 @@ warnings.filterwarnings("ignore")
9
  #dowload file
10
 
11
  #read files
12
- data = pd.read_csv('myfile.csv')
13
- data = data[['location','date','new_cases','total_cases','new_deaths','total_deaths']]
14
 
 
15
  #preprocessiong data
16
  all_location = {}
17
- for i in data['location'].unique():
18
- all_location[i] = data[data['location'] == i].reset_index(drop=True)
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  # SIR model differential equations.
21
  def deriv(x, t, beta, gamma):
@@ -70,17 +82,16 @@ def plotdata(t, s, i,r,R0, e=None):
70
  #final model
71
  def SIR(country,t_infective):
72
  # parameter values
73
- R0 = (all_location[country]['new_cases'].sum()/len(all_location[country]['date'].unique()))/t_infective
74
  t_infective = t_infective
 
 
 
75
 
76
  # initial number of infected and recovered individuals
77
- i_initial = 1/20000
78
  r_initial = 0.00
79
  s_initial = 1 - i_initial - r_initial
80
-
81
- gamma = 1/t_infective
82
- beta = R0*gamma
83
-
84
  t = np.linspace(0, 100, 1000)
85
  x_initial = s_initial, i_initial, r_initial
86
  soln = odeint(deriv, x_initial, t, args=(beta, gamma))
@@ -96,14 +107,11 @@ def main():
96
  with st.form("questionaire"):
97
  country = st.selectbox("Country",data['location'].unique())# user's input
98
  recovery = st.slider("How long Monkeypox recover?", 21, 31, 21)# user's input
99
-
100
  # clicked==True only when the button is clicked
101
  clicked = st.form_submit_button("Show Graph")
102
  if clicked:
103
-
104
- #show total cases graph
105
- all_location[country]['total_cases'].plot()
106
-
107
  # Show SIR
108
  SIR_param = SIR(country,recovery)
109
 
 
9
  #dowload file
10
 
11
  #read files
12
+ data = pd.read_csv('owid-monkeypox-data.csv')
13
+ data = data[['location','iso_code','date','new_cases','total_cases','new_deaths','total_deaths']]
14
 
15
+ pop = pd.read_csv('API_SP.POP.TOTL_DS2_en_csv_v2_4578059.csv')
16
  #preprocessiong data
17
  all_location = {}
18
+ for i in data['iso_code'].unique():
19
+ all_location[i] = data[data['iso_code'] == i].reset_index(drop=True)
20
+
21
+ popu = pop[['Country Code','2021']].to_dict('index')
22
+ pop_dict = {}
23
+ for i in popu.values():
24
+ pop_dict[i['Country Code']] = i['2021']
25
+
26
+ pop_dict['GLP'] = 400000
27
+ pop_dict['MTQ'] = 376480
28
+ pop_dict['OWID_WRL'] = 7836630792
29
+
30
+ code = dict(data.groupby('location')['iso_code'].unique())
31
 
32
  # SIR model differential equations.
33
  def deriv(x, t, beta, gamma):
 
82
  #final model
83
  def SIR(country,t_infective):
84
  # parameter values
 
85
  t_infective = t_infective
86
+ gamma = 1/t_infective
87
+ beta = (all_location[country]['new_cases'].sum()/pop_dict[country])/len(all_location[country]['date'].unique())
88
+ R0 = beta/gamma
89
 
90
  # initial number of infected and recovered individuals
91
+ i_initial = all_location[country]['new_cases'].sum()/pop_dict[country]
92
  r_initial = 0.00
93
  s_initial = 1 - i_initial - r_initial
94
+
 
 
 
95
  t = np.linspace(0, 100, 1000)
96
  x_initial = s_initial, i_initial, r_initial
97
  soln = odeint(deriv, x_initial, t, args=(beta, gamma))
 
107
  with st.form("questionaire"):
108
  country = st.selectbox("Country",data['location'].unique())# user's input
109
  recovery = st.slider("How long Monkeypox recover?", 21, 31, 21)# user's input
110
+ country = code[country][0]
111
  # clicked==True only when the button is clicked
112
  clicked = st.form_submit_button("Show Graph")
113
  if clicked:
114
+
 
 
 
115
  # Show SIR
116
  SIR_param = SIR(country,recovery)
117