-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_inpatients_mitigators.py
65 lines (47 loc) · 1.24 KB
/
generate_inpatients_mitigators.py
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
# Databricks notebook source
# MAGIC %md
# MAGIC
# MAGIC # Generate inpatient mitigators
# MAGIC
# COMMAND ----------
# MAGIC %pip install tqdm
# COMMAND ----------
import importlib
import os
from databricks.connect import DatabricksSession
from tqdm.auto import tqdm
import mitigators
spark = DatabricksSession.builder.getOrCreate()
# COMMAND ----------
path = ["mitigators", "ip"]
for i in ["activity_avoidance", "efficiency"]:
for j in sorted(os.listdir("/".join(path + [i]))):
if j == "__init__.py":
continue
module = ".".join(path + [i, j])[:-3]
try:
importlib.import_module(module)
except: # pylint: disable=bare-except
print(f"Error: {module}")
# COMMAND ----------
all_mitigators = [
v2
for v1 in mitigators.__registered_mitigators.values() # pylint: disable=protected-access
for v2 in v1.values()
]
errors = {}
for m in (pbar := tqdm(all_mitigators)):
pbar.set_description(f"Processing {m}:")
try:
m.save()
except Exception as e:
errors[str(m)] = e
errors
# COMMAND ----------
(
spark.read.table("su_data.nhp.apc_mitigators")
.groupBy("type", "strategy")
.count()
.orderBy("type", "strategy")
.display()
)