Skip to content

Commit

Permalink
Merge pull request #337 from payerle/has_usage_gauge_divby0
Browse files Browse the repository at this point in the history
Fix for #336 - Divide-by-zero error for Attrib value=0 and has_usage
  • Loading branch information
aebruno authored Dec 23, 2021
2 parents 4c61ed2 + 72bdfbb commit 87804e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions coldfront/core/allocation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def get_information(self):
percent = 'Invalid Value'
logger.error("Allocation attribute '%s' is not an int but has a usage",
attribute.allocation_attribute_type.name)
except ZeroDivisionError:
percent = 100
logger.error("Allocation attribute '%s' == 0 but has a usage",
attribute.allocation_attribute_type.name)

string = '{}: {}/{} ({} %) <br>'.format(
attribute.allocation_attribute_type.name,
Expand Down
7 changes: 6 additions & 1 deletion coldfront/core/allocation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def generate_guauge_data_from_usage(name, value, usage):

label = "%s: %.2f of %.2f" % (name, usage, value)

percent = (usage/value)*100
try:
percent = (usage/value)*100
except ZeroDivisionError:
percent = 100
except ValueError:
percent = 100

if percent < 80:
color = "#6da04b"
Expand Down

0 comments on commit 87804e5

Please sign in to comment.