Skip to content

Commit

Permalink
Add property measure class method defaults (#4778)
Browse files Browse the repository at this point in the history
* property measure class method defaults

programatically retrieve default

* update tests for default

---------

Co-authored-by: Ross Perry <[email protected]>
Co-authored-by: Katherine Fleming <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2024
1 parent c646212 commit 6ced1ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 51 deletions.
28 changes: 4 additions & 24 deletions seed/audit_template/audit_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,9 @@ def _batch_get_city_submission_xml(org_id, city_id, view_ids, progress_key):
# however that could return multiple views across many cycles
# filtering by custom_id and 'updated_at' will require looping through results to query views

property_views = PropertyView.objects.filter(id__in=view_ids) if view_ids else PropertyView.objects
# for development use
found_views = 0
no_text_key = 0
property_views = PropertyView.objects.filter(state__organization_id=org_id)
if view_ids:
property_views = property_views.filter(id__in=view_ids)

xml_data_by_cycle = {}
for sub in submissions:
Expand All @@ -415,7 +414,6 @@ def _batch_get_city_submission_xml(org_id, city_id, view_ids, progress_key):

progress_data.step("Getting XML for submissions...")
if view:
found_views += 1 # for development use
xml, _ = audit_template.get_submission(sub["id"], "xml")

if hasattr(xml, "text"):
Expand All @@ -425,28 +423,10 @@ def _batch_get_city_submission_xml(org_id, city_id, view_ids, progress_key):
xml_data_by_cycle[view.cycle.id].append(
{"property_view": view.id, "matching_field": custom_id_1, "xml": xml.text, "updated_at": sub["updated_at"]}
)
else: # for development use
no_text_key += 1

property_view_set = PropertyViewSet()
# Update is cycle based, going to have update in cycle specific batches
combined_results = {
"success": 0,
"failure": 0,
"data": [],
# for development use
"cycles": list(xml_data_by_cycle.keys()),
"property_views": str(type(property_views)),
"view_count": property_views.count(),
"found_views": found_views,
"no_text_key": no_text_key,
"submissions": len(submissions),
"org_id": org_id,
"city_id": city_id,
"view_ids": view_ids,
"status_types": status_types,
"progress_data.total": progress_data.total,
}
combined_results = {"success": 0, "failure": 0, "data": []}
try:
for cycle, xmls in xml_data_by_cycle.items():
# does progress_data need to be recursively passed?
Expand Down
36 changes: 15 additions & 21 deletions seed/models/property_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,48 +151,42 @@ class Meta:

@classmethod
def str_to_impl_status(cls, impl_status):
default = cls._meta.get_field("implementation_status").default
if not impl_status:
return None
return default

if isinstance(impl_status, int):
if impl_status in [(t[0]) for t in cls.IMPLEMENTATION_TYPES]:
return impl_status
return None
return default

value = [y[0] for x, y in enumerate(cls.IMPLEMENTATION_TYPES) if y[1] == impl_status]
if len(value) == 1:
return value[0]
else:
return None
value = next((y[0] for x, y in enumerate(cls.IMPLEMENTATION_TYPES) if y[1] == impl_status), default)
return value

@classmethod
def str_to_category_affected(cls, category):
default = cls._meta.get_field("category_affected").default
if not category:
return None
return default

if isinstance(category, int):
if category in [(t[0]) for t in cls.CATEGORY_AFFECTED_TYPE]:
return category
return None
return default

value = [y[0] for x, y in enumerate(cls.CATEGORY_AFFECTED_TYPE) if y[1] == category]
if len(value) == 1:
return value[0]
else:
return None
value = next((y[0] for x, y in enumerate(cls.CATEGORY_AFFECTED_TYPE) if y[1] == category), default)
return value

@classmethod
def str_to_application_scale(cls, app_scale):
default = cls._meta.get_field("application_scale").default
if not app_scale:
return None
return default

if isinstance(app_scale, int):
if app_scale in [(t[0]) for t in cls.APPLICATION_SCALE_TYPES]:
return app_scale
return None
return default

value = [y[0] for x, y in enumerate(cls.APPLICATION_SCALE_TYPES) if y[1] == app_scale]
if len(value) == 1:
return value[0]
else:
return None
value = next((y[0] for x, y in enumerate(cls.APPLICATION_SCALE_TYPES) if y[1] == app_scale), default)
return value
12 changes: 6 additions & 6 deletions seed/tests/test_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ def setUp(self):

def test_lookups(self):
self.assertEqual(PropertyMeasure.str_to_impl_status(PropertyMeasure.MEASURE_DISCARDED), 5)
self.assertEqual(PropertyMeasure.str_to_impl_status("measure discarded"), None)
self.assertEqual(PropertyMeasure.str_to_impl_status("measure discarded"), 1)
self.assertEqual(PropertyMeasure.str_to_impl_status("Discarded"), 5)
self.assertEqual(PropertyMeasure.str_to_impl_status(None), None)
self.assertEqual(PropertyMeasure.str_to_impl_status(None), 1)

self.assertEqual(PropertyMeasure.str_to_category_affected(PropertyMeasure.CATEGORY_DOMESTIC_HOT_WATER), 5)
self.assertEqual(PropertyMeasure.str_to_category_affected("domestic nothing"), None)
self.assertEqual(PropertyMeasure.str_to_category_affected("domestic nothing"), 27)
self.assertEqual(PropertyMeasure.str_to_category_affected("Domestic Hot Water"), 5)
self.assertEqual(PropertyMeasure.str_to_category_affected(None), None)
self.assertEqual(PropertyMeasure.str_to_category_affected(None), 27)

self.assertEqual(PropertyMeasure.str_to_application_scale(PropertyMeasure.SCALE_ENTIRE_FACILITY), 5)
self.assertEqual(PropertyMeasure.str_to_application_scale("Nothing entirely"), None)
self.assertEqual(PropertyMeasure.str_to_application_scale("Nothing entirely"), 5)
self.assertEqual(PropertyMeasure.str_to_application_scale("Entire facility"), 5)
self.assertEqual(PropertyMeasure.str_to_application_scale(None), None)
self.assertEqual(PropertyMeasure.str_to_application_scale(None), 5)

def test_populate_measures(self):
self.assertEqual(Measure.objects.count(), 222)
Expand Down

0 comments on commit 6ced1ff

Please sign in to comment.