fixed division by zero problem
This commit is contained in:
parent
22ce8e9632
commit
b17bd93438
1 changed files with 26 additions and 9 deletions
|
@ -16,7 +16,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
from time import timezone
|
from time import timezone
|
||||||
import git
|
import git
|
||||||
from typing import Dict
|
from typing import Dict, Optional
|
||||||
from google.cloud import monitoring_v3
|
from google.cloud import monitoring_v3
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -32,21 +32,35 @@ class RepoStats:
|
||||||
self.reviewed = 0 # type: int
|
self.reviewed = 0 # type: int
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def percent_reverted(self) -> float:
|
def percent_reverted(self) -> Optional[float]:
|
||||||
return 100.0 * self.reverts / self.commits
|
try:
|
||||||
|
return 100.0 * self.reverts / self.commits
|
||||||
|
except ZeroDivisionError:
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def percent_reviewed(self) -> float:
|
def percent_reviewed(self) -> Optional[float]:
|
||||||
return 100.0 * self.reviewed / (self.commits - self.reverts)
|
try:
|
||||||
|
return 100.0 * self.reviewed / (self.commits - self.reverts)
|
||||||
|
except ZeroDivisionError:
|
||||||
|
return None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "\n".join([
|
results = [
|
||||||
"commits: {}".format(self.commits),
|
"commits: {}".format(self.commits),
|
||||||
"reverts: {}".format(self.reverts),
|
"reverts: {}".format(self.reverts),
|
||||||
"reviewed: {}".format(self.reviewed),
|
"reviewed: {}".format(self.reviewed),
|
||||||
"percent reverted: {:0.1f}".format(self.percent_reverted),
|
]
|
||||||
"percent reviewed: {:0.1f}".format(self.percent_reviewed),
|
try:
|
||||||
])
|
results.append("percent reverted: {:0.1f}".format(self.percent_reverted))
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
results.append("percent reverted: {:0.1f}".format(self.percent_reverted))
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return "\n".join(results)
|
||||||
|
|
||||||
def get_reverts_per_day(repo_path: str, max_age: datetime.datetime) -> RepoStats:
|
def get_reverts_per_day(repo_path: str, max_age: datetime.datetime) -> RepoStats:
|
||||||
stats = RepoStats()
|
stats = RepoStats()
|
||||||
|
@ -78,6 +92,9 @@ def gcp_write_data(project_id: str, stats: RepoStats, now:datetime.datetime):
|
||||||
["reviewed", stats.reviewed],
|
["reviewed", stats.reviewed],
|
||||||
["percent_reviewed", stats.percent_reviewed],
|
["percent_reviewed", stats.percent_reviewed],
|
||||||
]:
|
]:
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
|
||||||
series = monitoring_v3.types.TimeSeries()
|
series = monitoring_v3.types.TimeSeries()
|
||||||
series.metric.type = 'custom.googleapis.com/repository_{}'.format(desc_type)
|
series.metric.type = 'custom.googleapis.com/repository_{}'.format(desc_type)
|
||||||
series.resource.type = 'global'
|
series.resource.type = 'global'
|
||||||
|
|
Loading…
Reference in a new issue