Skip to content

Commit

Permalink
Add handling for ZeroDivisionError
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-weinberg committed Mar 14, 2024
1 parent 5f88429 commit 66641c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ MANIFEST

# Per-project virtualenvs
.venv*/
venv*/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ It is suggested to use a venv to install and run touchstone.
```shell
python -m venv /virtual/environment
source /virtual/environment/bin/activate
git clone https://github.com/cloud-bulldozer/touchstone
cd touchstone
git clone https://github.com/cloud-bulldozer/benchmark-comparison
cd benchmark-comparison
python setup.py develop
touchstone_compare -h
usage: touchstone_compare [-h] [--version] [--database {elasticsearch}] [--identifier-key IDENTIFIER] -u UUID [UUID ...] [-a ALIASES [ALIASES ...]] [-o {json,yaml,csv}] --config CONFIG [--output-file OUTPUT_FILE]
Expand Down
25 changes: 16 additions & 9 deletions src/touchstone/decision_maker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@ def _compare(self, input_dict, compare_dict):
for u, v in input_dict.items():
if u == self.baseline_uuid:
continue
metric_percent = v * 100 / input_dict[self.baseline_uuid]
# If percentage is greater than 100, sustract 100 from it else substract it from 100
deviation = metric_percent - 100 if metric_percent > 100 else 100 - metric_percent
deviation = -deviation if v < input_dict[self.baseline_uuid] else deviation
if (self.tolerancy >= 0 and v > base_val) or (self.tolerancy < 0 and v < base_val):
result = "Fail"
self.passed = False
self.fails += 1
else:
try:
metric_percent = v * 100 / input_dict[self.baseline_uuid]
# ZeroDivisionError means baseline value was 0, no comparison to be made here
except ZeroDivisionError:
result = "Pass"
deviation = 0
pass
else:
# If percentage is greater than 100, sustract 100 from it else substract it from 100
deviation = metric_percent - 100 if metric_percent > 100 else 100 - metric_percent
deviation = -deviation if v < input_dict[self.baseline_uuid] else deviation
if (self.tolerancy >= 0 and v > base_val) or (self.tolerancy < 0 and v < base_val):
result = "Fail"
self.passed = False
self.fails += 1
else:
result = "Pass"
if result not in compare_dict:
compare_dict[result] = {}
compare_dict[result] = {
Expand Down

0 comments on commit 66641c7

Please sign in to comment.