-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw_graph
89 lines (78 loc) · 3.07 KB
/
draw_graph
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Drawing a graph based on xlsx content.
"""
import os
import matplotlib.pyplot as plt
import pandas
import openpyxl as op
def draw(protocol, yesterday):
"""Draw a graph based on xlsx content via matplotlib
Args:
protocol (string): protocol to draw graph
yesterday (date): Monitoring date information
"""
xlsx_path = 'C:/Users/xxxxxxxx/OneDrive - HMGNA/Documents/Python_project/crawling/NorthAmerica/xlsx/'
file_path = xlsx_path + 'NorthAmerica' + '.xlsx'
image_path = "C:/Users/xxxxxxxx/OneDrive - HMGNA/Documents/Python_project/crawling/NorthAmerica/images/"
dates = []
successes = []
fails = []
fail_rates = []
workbook = op.load_workbook(file_path)
sheet = workbook[protocol]
for data in sheet.iter_rows(min_row=2, values_only=True):
date, region, success, fail = data
dates.append(date)
success = success.replace(',', '')
successes.append(int(success))
fail = fail.replace(',', '')
fails.append(int(fail))
# 분모가 0일 경우 처리
if float(success) + float(fail) == 0:
fail_rates.append(0)
else :
fail_rate = float(fail) / (float(success) + float(fail)) * 100
fail_rates.append(float(fail_rate))
data_frame = pandas.DataFrame({
'dates':dates,
'successes':successes,
'fails' : fails,
'fail_rates' : fail_rates
})
data_frame['dates'] = pandas.to_datetime(data_frame['dates'])
# 하위 30개. 한 달 치만 출력
data_frame = data_frame.tail(30)
#fig
plt.figure(figsize = (50, 30), facecolor='#e5e5e5')
plt.subplot(3, 1, 1)
plt.plot(data_frame['dates'],data_frame['successes'],color='blue', marker='o', markersize='10', linestyle='solid', linewidth = 4)
plt.xticks(ticks=data_frame['dates'], fontsize=25, rotation=25)
y_range = plt.ylim()
plt.ylim([0, y_range[1]])
plt.yticks(fontsize = 30)
plt.ylabel('Count', fontsize = 30) # y축 이름
plt.title('Number of Successes (' + str(protocol) + ')', fontsize = 40)
plt.ticklabel_format(useOffset=False, style='plain', axis='y')
plt.subplot(3, 1, 2)
plt.plot(data_frame['dates'],data_frame['fails'],color='red', marker='o', markersize='10', linestyle='solid', linewidth = 4)
plt.xticks(ticks=data_frame['dates'], fontsize=25, rotation=25)
plt.yticks(fontsize = 30)
y_range = plt.ylim()
plt.ylim([0, y_range[1]])
plt.ylabel('Count', fontsize = 30) # y축 이름
plt.title('Number of Failures (' + str(protocol) + ')', fontsize = 40)
plt.ticklabel_format(useOffset=False, style='plain', axis='y')
plt.subplot(3, 1, 3)
plt.plot(data_frame['dates'],data_frame['fail_rates'],color='red', marker='o', markersize='10', linestyle='dashed', linewidth = 4)
plt.ticklabel_format(style='plain', axis='y')
plt.xticks(ticks=data_frame['dates'], fontsize=25, rotation=25)
y_range = plt.ylim()
plt.ylim([0, y_range[1]])
plt.yticks(fontsize = 30)
plt.ylabel('Rate', fontsize = 30) # y축 이름
plt.title('Failure Rate (' + str(protocol) + ')', fontsize = 40)
plt.ticklabel_format(useOffset=False, style='plain', axis='y')
plt.tight_layout()
#plt.show()
if os.path.isdir(image_path) is False :
os.makedirs(image_path, exist_ok=True)
plt.savefig(image_path + str(yesterday) + '_' + str(protocol) +'.png')