-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
74 lines (61 loc) · 2.91 KB
/
example.py
File metadata and controls
74 lines (61 loc) · 2.91 KB
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
from pandemic_cost import PandemicCost
from policy_functions.policy import Policy
from pandemic_functions.pandemic import Pandemic_Factory
import locale
locale.setlocale(locale.LC_ALL, 'en_US')
import sys
import itertools
import pandas as pd
from datetime import datetime
pandemic_simulator = Pandemic_Factory()
country = "DE"
start_date = "2020-03-15"
policy_length = 3
def simulate_actual():
# create a policy that uses the current policy for Germany, length 3 months starting in 2020-03-01,
policy = Policy(policy_type = "actual", start_date = start_date, policy_length = policy_length)
# simulate the pandemic using such policy
pandemic = pandemic_simulator.compute_delphi(policy,region=country)
cost_of_pandemic = PandemicCost(pandemic)
return cost_of_pandemic
# Should have 5 items in the dict, each representing costs. Economic costs and death costs should be on the order of billions to tens of billions at least.
def simulate_policy(policy_vect):
# create a policy that a hypothetical policy for Germany, length 3 months starting in 2020-03-01,
policy2 = Policy(policy_type = "hypothetical", start_date = start_date, policy_vector = policy_vect)
# simulate the pandemic using such policy
pandemic2 = pandemic_simulator.compute_delphi(policy2,region=country)
cost_of_pandemic2 = PandemicCost(pandemic2)
return cost_of_pandemic2
d_scenarii_simulations = {}
d_scenarii_simulations['actual'] = simulate_actual().__dict__
future_policies = [
'No_Measure',
'Restrict_Mass_Gatherings',
# 'Mass_Gatherings_Authorized_But_Others_Restricted',
'Restrict_Mass_Gatherings_and_Schools',
'Authorize_Schools_but_Restrict_Mass_Gatherings_and_Others',
'Restrict_Mass_Gatherings_and_Schools_and_Others',
'Lockdown'
]
scenarios = [list(t) for t in itertools.product(future_policies, repeat=policy_length)]
for scenario in scenarios:
print("testing - " + str(scenario) + " ", end='')
try:
d_scenarii_simulations['-'.join(scenario)] = simulate_policy(scenario).__dict__
print("OK")
except :
print("Unexpected error:", sys.exc_info())
print("NOK")
output_df = pd.DataFrame.from_dict(d_scenarii_simulations, orient="index")
del output_df["policy"]
output_df.reset_index(inplace=True)
output_df = output_df.rename(columns = {'index':'policy'})
output_df["country"] = country
output_df["start_date"] = start_date
output_df["policy_length"] = policy_length
output_df = output_df[["country","start_date","policy_length","policy","st_economic_costs","lt_economic_costs",
"d_costs","h_costs","mh_costs","num_cases","num_deaths","hospitalization_days","icu_days","ventilated_days"]]
time_stamp = datetime.now().strftime("%Y%m%d_%H%M%S")
output_df.to_csv('simulation_results/test_result_' + time_stamp + '.csv')
# for k in cost_of_pandemic.__dict__:
# print(k, " ", locale.format_string("%d", cost_of_pandemic.__dict__[k], grouping=True))