Skip to content

Commit 8aa42b9

Browse files
committed
Put units back in names to match arc
1 parent f462d9b commit 8aa42b9

File tree

1 file changed

+26
-32
lines changed

1 file changed

+26
-32
lines changed

schemas/isaric_schema.py

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,32 +72,33 @@ def attrs_with_lists(arc, types: list[str]):
7272
return rules, arc[~arc_filter]
7373

7474

75-
def attrs_with_units(arc, types: list[str]):
76-
rules = []
77-
arc_filter = arc["Type"].isin(types)
78-
vars_with_units = arc[arc_filter]["Variable"]
79-
arc_vars_to_remove = vars_with_units.copy().to_list()
75+
# Currently not used
76+
# def attrs_with_units(arc, types: list[str]):
77+
# rules = []
78+
# arc_filter = arc["Type"].isin(types)
79+
# vars_with_units = arc[arc_filter]["Variable"]
80+
# arc_vars_to_remove = vars_with_units.copy().to_list()
8081

81-
for var in vars_with_units:
82-
unit_options = arc[arc["Variable"].str.startswith(var + "_")][
83-
"Variable"
84-
].to_list()
85-
arc_vars_to_remove += unit_options
82+
# for var in vars_with_units:
83+
# unit_options = arc[arc["Variable"].str.startswith(var + "_")][
84+
# "Variable"
85+
# ].to_list()
86+
# arc_vars_to_remove += unit_options
8687

87-
units = [u.removeprefix(var + "_") for u in unit_options]
88+
# units = [u.removeprefix(var + "_") for u in unit_options]
8889

89-
rule = {
90-
"properties": {
91-
"attribute": {"const": var},
92-
"attribute_unit": {"enum": units},
93-
"value_num": {"type": "number"},
94-
},
95-
"required": ["value_num", "attribute_unit"],
96-
}
90+
# rule = {
91+
# "properties": {
92+
# "attribute": {"const": var},
93+
# "attribute_unit": {"enum": units},
94+
# "value_num": {"type": "number"},
95+
# },
96+
# "required": ["value_num", "attribute_unit"],
97+
# }
9798

98-
rules.append(rule)
99+
# rules.append(rule)
99100

100-
return rules, arc[~arc["Variable"].isin(arc_vars_to_remove)]
101+
# return rules, arc[~arc["Variable"].isin(arc_vars_to_remove)]
101102

102103

103104
def numeric_attrs(arc, types: list[str]):
@@ -171,9 +172,9 @@ def generate_long_schema(version):
171172
template_long = json.load(f)
172173

173174
# Drop the core properties from the long schema
174-
# Don't include descriptive or file types (unwanted as stored attributes)
175+
# Don't include descriptive, file types or NaN's (unwanted as stored attributes)
175176
arc_long = arc[~arc.Variable.isin(template_core["properties"].keys())]
176-
arc_long = arc_long[~(arc_long.Type.isin(["descriptive", "file"]))]
177+
arc_long = arc_long[~(arc_long.Type.isin(["descriptive", "file", np.nan]))]
177178

178179
# Generate rules for each type of attribute
179180
enum_rules, arc_no_enums = attrs_with_enums(arc_long, ["radio", "checkbox"])
@@ -182,9 +183,7 @@ def generate_long_schema(version):
182183
arc_no_enums, ["list", "user_list", "multi_list"]
183184
)
184185

185-
unit_rules, arc_no_units = attrs_with_units(arc_no_lists, [np.nan])
186-
187-
numeric_rules, arc_no_numbers = numeric_attrs(arc_no_units, ["number", "calc"])
186+
numeric_rules, arc_no_numbers = numeric_attrs(arc_no_lists, ["number", "calc"])
188187

189188
date_rules, arc_no_dates = date_attrs(arc_no_numbers, ["date_dmy", "datetime_dmy"])
190189

@@ -194,12 +193,7 @@ def generate_long_schema(version):
194193

195194
# Combine all rules into one list
196195
one_of_rules = (
197-
enum_rules
198-
+ list_rules
199-
+ unit_rules
200-
+ numeric_rules
201-
+ date_rules
202-
+ other_str_rules
196+
enum_rules + list_rules + numeric_rules + date_rules + other_str_rules
203197
)
204198

205199
# check no types have been missed

0 commit comments

Comments
 (0)