Skip to content

Commit

Permalink
Fail analysis if error rate is too high
Browse files Browse the repository at this point in the history
  • Loading branch information
Javex committed Nov 3, 2024
1 parent df1e6a5 commit 2cb8c81
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions hotprices_au/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@
from . import output, sites


# 1% error rate for parsing is fine
ERROR_RATE_MAX = 0.01


def get_canoncial_for(store, raw_items, category_map, today):
canonical_items = []
store_module = sites.sites[store]
err_count = 0
total_parsed = 0
for raw_item in raw_items:
total_parsed += 1
try:
canonical_item = store_module.get_canonical(raw_item, today)
except Exception:
logger.exception(f"Unable to process store '{store}' item: {raw_item}")
err_count += 1
# import pprint
# pprint.pprint(raw_item)
# Skip parsing errors and move on to next item
Expand All @@ -29,6 +37,11 @@ def get_canoncial_for(store, raw_items, category_map, today):
except KeyError:
canonical_item["category"] = None
canonical_items.append(canonical_item)
error_rate = float(err_count) / total_parsed
if error_rate > ERROR_RATE_MAX:
raise RuntimeError(
f"Error rate of {error_rate} greater than max error rate of {ERROR_RATE_MAX}. Total errors: {err_count}, total parsed: {total_parsed}"
)
return canonical_items


Expand Down

0 comments on commit 2cb8c81

Please sign in to comment.