Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
generate graph, start first day of current month
Browse files Browse the repository at this point in the history
  • Loading branch information
grewn0uille committed Feb 23, 2018
1 parent 97b8411 commit dd59de0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sherlog/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def gen_graph(data, date_range, title):

def compute_ok_percent(data, occurences):
ok_true = [x.ok for x in data].count(True)
return ok_true * 100 / occurences
return '%.2f'%(ok_true * 100 / occurences)


def build_list_ping(data):
Expand Down Expand Up @@ -60,15 +60,19 @@ def get_data(server_name, ping_service, start):

def build_graph(server_name, interval, ping_service):
current_date = datetime.datetime.now()
tmp_date = datetime.datetime(2018, 1, 5, 14, 13, 37, 903083)
data = get_data(server_name, ping_service, tmp_date)
begin_month = datetime.datetime.today().replace(
day=1, hour=0, minute=0, second=0, microsecond=0)
data = get_data(server_name, ping_service, begin_month)
if 'ping' in ping_service:
build_data = build_list_ping(data)
else:
build_data = build_list_service(data)
build_data.sort(key=lambda data: data.start.day)
grouped_by_days = groupby(build_data, lambda data:data.start.day)
data = []
data_range = []
for key,group in grouped_by_days:
group = list(group)
res = compute_ok_percent(group, len(group))
print(res)
data.append(float(compute_ok_percent(group, len(group))))
data_range.append(key)
return gen_graph(data, data_range, server_name + ping_service)

0 comments on commit dd59de0

Please sign in to comment.