Simplify average code and account for when any of the values are 0.

master
Simon Quigley 4 years ago
parent 0792e9d9f1
commit d950c9f8c7

@ -157,15 +157,14 @@ class JenkinsModule:
_data["total"].append(row[3]) _data["total"].append(row[3])
# Get human-readable averages and throw it in a dict # Get human-readable averages and throw it in a dict
_nonpassing = sum(_data["nonpassing"]) / len(_data["nonpassing"]) average = {}
_nonpassing = format(_nonpassing, ".1f") for datatype in ("nonpassing", "failing", "total"):
_failing = sum(_data["failing"]) / len(_data["failing"]) try:
_failing = format(_failing, ".1f") num = sum(_data[datatype]) / len(_data[datatype])
_total = sum(_data["total"]) / len(_data["total"]) num = format(num, ".1f")
_total = format(_total, ".1f") except ZeroDivisionError:
average = {"nonpassing": _nonpassing, num = 0
"failing": _failing, average[datatype] = num
"total": _total}
# Assign data to the dict Jinja2 is actually going to use # Assign data to the dict Jinja2 is actually going to use
jenkins = {"nonpassing": zip(_data["date"], _data["nonpassing"]), jenkins = {"nonpassing": zip(_data["date"], _data["nonpassing"]),

Loading…
Cancel
Save