-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateChart.py
64 lines (57 loc) · 16.6 KB
/
generateChart.py
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
data= {'choose_db': 'CIM18P1', 'choose_info_type': 'cpu', 'choose_host': ['f18p1cim01', 'f18p1cim02'], 'start_time': '2021-08-16T11:00:00', 'end_time': '2021-08-16T17:00:00', 'userid': '29:13U1SZwem4_t0g4W5kM8yO0fQiKSB52E7eGSc3p9Kr2qOkwdNru7OCN9y7uytQGw3QWl3UJVDRQOpwKLOYdOMpw', 'search_result': {'preview': False, 'init_offset': 0, 'messages': [{'type': 'INFO', 'text': "[gi18asplkidx01] Your timerange was substituted based on your 'where' clause"}, {'type': 'INFO', 'text': "[gi18asplkidx02] Your timerange was substituted based on your 'where' clause"}, {'type': 'INFO', 'text': "[gi18asplkidx03] Your timerange was substituted based on your 'where' clause"}, {'type': 'INFO', 'text': "[gi18asplkidx04] Your timerange was substituted based on your 'where' clause"}, {'type': 'INFO', 'text': "[gi18asplkidx05] Your timerange was substituted based on your 'where' clause"}, {'type': 'INFO', 'text': "[gi18asplkidx06] Your timerange was substituted based on your 'where' clause"}, {'type': 'INFO', 'text': "[gi18asplkidx07] Your timerange was substituted based on your 'where' clause"}, {'type': 'INFO', 'text': "[gi18asplkidx08] Your timerange was substituted based on your 'where' clause"}], 'fields': ['_time', 'f18p1cim01', 'f18p1cim02', '_span'], 'rows': [[1629082800000, '27.57', '4.53', '60'], [1629082860000, '27.59', '4.02', '60'], [1629082920000, '19.91', '3.37', '60'], [1629082980000, '16', '3.36', '60'], [1629083040000, '20.4', '3.95', '60'], [1629083100000, '13.91', '3.27', '60'], [1629083160000, '21.6', '4.89', '60'], [1629083220000, '20.21', '3.16', '60'], [1629083280000, '17.75', '3.14', '60'], [1629083340000, '10.44', '3.84', '60'], [1629083400000, '17.78', '4', '60'], [1629083460000, '22.64', '4.29', '60'], [1629083520000, '22.37', '3.47', '60'], [1629083580000, '11.06', '3.2', '60'], [1629083640000, '16.72', '3.93', '60'], [1629083700000, '10.94', '3.27', '60'], [1629083760000, '23.63', '3.66', '60'], [1629083820000, '21.54', '3.25', '60'], [1629083880000, '10.06', '3.12', '60'], [1629083940000, '9.95', '3.85', '60'], [1629084000000, '19.98', '4.13', '60'], [1629084060000, '24.01', '4.19', '60'], [1629084120000, '14.81', '3.34', '60'], [1629084180000, '10.31', '3.54', '60'], [1629084240000, '20.84', '3.87', '60'], [1629084300000, '13.88', '3.24', '60'], [1629084360000, '21.99', '3.91', '60'], [1629084420000, '14.54', '3.16', '60'], [1629084480000, '20.65', '3.23', '60'], [1629084540000, '8.1', '3.86', '60'], [1629084600000, '20.46', '4.56', '60'], [1629084660000, '21.03', '3.99', '60'], [1629084720000, '25.4', '3.37', '60'], [1629084780000, '8.28', '3.16', '60'], [1629084840000, '16.19', '4.21', '60'], [1629084900000, '12.51', '3.26', '60'], [1629084960000, '24.35', '3.61', '60'], [1629085020000, '17.41', '3.14', '60'], [1629085080000, '12.68', '3.13', '60'], [1629085140000, '11.12', '3.89', '60'], [1629085200000, '22.72', '4.01', '60'], [1629085260000, '23.11', '4.28', '60'], [1629085320000, '17.64', '3.3', '60'], [1629085380000, '13.32', '3.18', '60'], [1629085440000, '20.34', '3.89', '60'], [1629085500000, '13.68', '3.32', '60'], [1629085560000, '19.86', '3.58', '60'], [1629085620000, '18.55', '3.15', '60'], [1629085680000, '17.74', '3.18', '60'], [1629085740000, '13.74', '3.94', '60'], [1629085800000, '19.39', '4.03', '60'], [1629085860000, '27.26', '3.96', '60'], [1629085920000, '23.95', '3.67', '60'], [1629085980000, '10.57', '3.17', '60'], [1629086040000, '17.39', '3.86', '60'], [1629086100000, '12.56', '3.22', '60'], [1629086160000, '22.3', '3.92', '60'], [1629086220000, '21.99', '3.15', '60'], [1629086280000, '11.84', '3.19', '60'], [1629086340000, '9.49', '3.91', '60'], [1629086400000, '31.05', '4.46', '60'], [1629086460000, '22.54', '3.98', '60'], [1629086520000, '17.24', '3.48', '60'], [1629086580000, '14.36', '3.7', '60'], [1629086640000, '12.91', '3.99', '60'], [1629086700000, '15.04', '3.41', '60'], [1629086760000, '24.09', '4.99', '60'], [1629086820000, '16.48', '3.44', '60'], [1629086880000, '16.57', '3.22', '60'], [1629086940000, '10.07', '3.86', '60'], [1629087000000, '18.28', '4.03', '60'], [1629087060000, '23.89', '4.29', '60'], [1629087120000, '26.69', '3.14', '60'], [1629087180000, '12.17', '3.43', '60'], [1629087240000, '16.35', '3.86', '60'], [1629087300000, '12.62', '3.29', '60'], [1629087360000, '25.76', '3.66', '60'], [1629087420000, '17.81', '3.19', '60'], [1629087480000, '10.51', '3.21', '60'], [1629087540000, '12.07', '3.85', '60'], [1629087600000, '23.15', '4.14', '60'], [1629087660000, '23.93', '4.01', '60'], [1629087720000, '26.56', '3.21', '60'], [1629087780000, '9.76', '3.31', '60'], [1629087840000, '15.54', '3.9', '60'], [1629087900000, '10.14', '3.22', '60'], [1629087960000, '19.77', '3.83', '60'], [1629088020000, '19.84', '3.19', '60'], [1629088080000, '15.74', '3.22', '60'], [1629088140000, '9.7', '3.88', '60'], [1629088200000, '19.46', '4.38', '60'], [1629088260000, '27.64', '4.05', '60'], [1629088320000, '23.15', '3.35', '60'], [1629088380000, '9.98', '3.13', '60'], [1629088440000, '16.84', '4.07', '60'], [1629088500000, '14.59', '3.25', '60'], [1629088560000, '21.72', '3.58', '60'], [1629088620000, '18.97', '3.17', '60'], [1629088680000, '12.73', '3.17', '60'], [1629088740000, '11.66', '3.89', '60'], [1629088800000, '24.35', '4.08', '60'], [1629088860000, '23.2', '4.19', '60'], [1629088920000, '15.48', '3.43', '60'], [1629088980000, '11.18', '3.24', '60'], [1629089040000, '19.4', '4.08', '60'], [1629089100000, '11.99', '3.27', '60'], [1629089160000, '22.25', '3.64', '60'], [1629089220000, '19.44', '3.39', '60'], [1629089280000, '17.73', '3.2', '60'], [1629089340000, '17.87', '3.91', '60'], [1629089400000, '19.6', '4.08', '60'], [1629089460000, '24.13', '4', '60'], [1629089520000, '24.8', '3.2', '60'], [1629089580000, '11.21', '3.16', '60'], [1629089640000, '17.35', '3.93', '60'], [1629089700000, '12.11', '3.24', '60'], [1629089760000, '22.28', '3.9', '60'], [1629089820000, '20.1', '3.24', '60'], [1629089880000, '14.13', '3.23', '60'], [1629089940000, '12.55', '3.91', '60'], [1629090000000, '30.95', '4.47', '60'], [1629090060000, '24.58', '4.03', '60'], [1629090120000, '21.72', '3.49', '60'], [1629090180000, '16.29', '3.41', '60'], [1629090240000, '18.33', '3.92', '60'], [1629090300000, '19.04', '3.51', '60'], [1629090360000, '32', '4.97', '60'], [1629090420000, '23.61', '3.19', '60'], [1629090480000, '19.42', '3.22', '60'], [1629090540000, '15.35', '3.89', '60'], [1629090600000, '20.09', '4.07', '60'], [1629090660000, '28.01', '4.18', '60'], [1629090720000, '23.66', '3.49', '60'], [1629090780000, '13.56', '3.23', '60'], [1629090840000, '12.91', '3.91', '60'], [1629090900000, '16.97', '3.52', '60'], [1629090960000, '24.7', '3.59', '60'], [1629091020000, '21.51', '3.18', '60'], [1629091080000, '14.61', '3.35', '60'], [1629091140000, '13.09', '3.97', '60'], [1629091200000, '24.63', '4.1', '60'], [1629091260000, '29.97', '4.06', '60'], [1629091320000, '19.17', '3.47', '60'], [1629091380000, '10.88', '3.34', '60'], [1629091440000, '20.92', '3.94', '60'], [1629091500000, '14.42', '3.26', '60'], [1629091560000, '21.77', '3.79', '60'], [1629091620000, '20.43', '3.15', '60'], [1629091680000, '19.17', '3.19', '60'], [1629091740000, '9.76', '3.86', '60'], [1629091800000, '16.48', '4.12', '60'], [1629091860000, '24.86', '4.06', '60'], [1629091920000, '21', '3.2', '60'], [1629091980000, '12.88', '3.17', '60'], [1629092040000, '11.55', '3.88', '60'], [1629092100000, '12.04', '3.25', '60'], [1629092160000, '22.24', '3.85', '60'], [1629092220000, '19.88', '3.18', '60'], [1629092280000, '11.54', '3.12', '60'], [1629092340000, '11.52', '3.9', '60'], [1629092400000, '20.85', '4.07', '60'], [1629092460000, '31.58', '4.09', '60'], [1629092520000, '18.95', '3.26', '60'], [1629092580000, '10.79', '3.16', '60'], [1629092640000, '18.71', '3.89', '60'], [1629092700000, '16.01', '3.34', '60'], [1629092760000, '19.71', '3.75', '60'], [1629092820000, '19.59', '3.17', '60'], [1629092880000, '16.72', '3.15', '60'], [1629092940000, '14.74', '4.17', '60'], [1629093000000, '20.06', '4.07', '60'], [1629093060000, '29.56', '4.04', '60'], [1629093120000, '21.76', '3.43', '60'], [1629093180000, '12.72', '3.16', '60'], [1629093240000, '17.04', '3.9', '60'], [1629093300000, '13.83', '3.24', '60'], [1629093360000, '24.38', '3.76', '60'], [1629093420000, '18.39', '3.17', '60'], [1629093480000, '11.94', '3.2', '60'], [1629093540000, '10.79', '3.88', '60'], [1629093600000, '24.1', '4.29', '60'], [1629093660000, '20.91', '3.98', '60'], [1629093720000, '19.44', '3.48', '60'], [1629093780000, '11.73', '3.37', '60'], [1629093840000, '16.58', '4.14', '60'], [1629093900000, '10.76', '3.25', '60'], [1629093960000, '25.77', '4.9', '60'], [1629094020000, '19.22', '3.34', '60'], [1629094080000, '12.58', '3.16', '60'], [1629094140000, '15.93', '3.9', '60'], [1629094200000, '24.1', '4.29', '60'], [1629094260000, '24.51', '4.23', '60'], [1629094320000, '22.66', '3.49', '60'], [1629094380000, '14.42', '3.27', '60'], [1629094440000, '17.58', '3.9', '60'], [1629094500000, '14', '3.28', '60'], [1629094560000, '25.46', '3.59', '60'], [1629094620000, '23.34', '3.16', '60'], [1629094680000, '11.39', '3.13', '60'], [1629094740000, '13.29', '3.88', '60'], [1629094800000, '18.72', '4.06', '60'], [1629094860000, '23.55', '3.96', '60'], [1629094920000, '13.32', '3.46', '60'], [1629094980000, '10.2', '3.31', '60'], [1629095040000, '14.15', '3.88', '60'], [1629095100000, '12.04', '3.22', '60'], [1629095160000, '15.27', '3.68', '60'], [1629095220000, '13.51', '3.15', '60'], [1629095280000, '18.71', '3.4', '60'], [1629095340000, '10.99', '3.88', '60'], [1629095400000, '18.24', '4.07', '60'], [1629095460000, '25.71', '4.73', '60'], [1629095520000, '30.36', '3.75', '60'], [1629095580000, '11.77', '3.73', '60'], [1629095640000, '14.45', '4.25', '60'], [1629095700000, '11.96', '3.22', '60'], [1629095760000, '19.22', '3.61', '60'], [1629095820000, '21.12', '3.15', '60'], [1629095880000, '10.48', '3.14', '60'], [1629095940000, '8.68', '3.89', '60'], [1629096000000, '21.91', '4.01', '60'], [1629096060000, '23.64', '4.11', '60'], [1629096120000, '21.05', '3.42', '60'], [1629096180000, '9.89', '3.21', '60'], [1629096240000, '19.32', '3.88', '60'], [1629096300000, '15.83', '3.29', '60'], [1629096360000, '14.96', '3.59', '60'], [1629096420000, '18.76', '3.18', '60'], [1629096480000, '16.72', '3.19', '60'], [1629096540000, '15.5', '4.17', '60'], [1629096600000, '18.82', '4.1', '60'], [1629096660000, '25.19', '4.12', '60'], [1629096720000, '26.13', '3.49', '60'], [1629096780000, '11.99', '3.22', '60'], [1629096840000, '18.95', '3.9', '60'], [1629096900000, '14.66', '3.26', '60'], [1629096960000, '26.47', '3.74', '60'], [1629097020000, '25.01', '3.24', '60'], [1629097080000, '14.79', '3.18', '60'], [1629097140000, '12.88', '3.98', '60'], [1629097200000, '25.02', '4.44', '60'], [1629097260000, '17.18', '4.04', '60'], [1629097320000, '23.1', '3.46', '60'], [1629097380000, '17.19', '3.4', '60'], [1629097440000, '19.58', '4.23', '60'], [1629097500000, '11.96', '3.27', '60'], [1629097560000, '23.3', '4.89', '60'], [1629097620000, '21.53', '3.17', '60'], [1629097680000, '15.84', '3.13', '60'], [1629097740000, '12.34', '3.88', '60'], [1629097800000, '17.13', '4.06', '60'], [1629097860000, '21.74', '4.14', '60'], [1629097920000, '26.64', '3.25', '60'], [1629097980000, '10.89', '3.41', '60'], [1629098040000, '21.03', '3.91', '60'], [1629098100000, '12.02', '3.31', '60'], [1629098160000, '21.99', '3.67', '60'], [1629098220000, None, '3.18', '60'], [1629098280000, '13.29', '3.14', '60'], [1629098340000, None, '3.97', '60'], [1629098400000, '19.49', '4.07', '60'], [1629098460000, None, '4.03', '60'], [1629098520000, '18.04', '3.46', '60'], [1629098580000, None, '3.33', '60'], [1629098640000, '14.41', '3.89', '60'], [1629098700000, None, '3.27', '60'], [1629098760000, '16.54', '3.71', '60'], [1629098820000, None, '3.19', '60'], [1629098880000, '15.489999999999998', '3.19', '60'], [1629098940000, None, '3.94', '60'], [1629099000000, '23.615000000000002', '4.1', '60'], [1629099060000, None, '4.24', '60'], [1629099120000, '17.07', '3.65', '60'], [1629099180000, None, '3.17', '60'], [1629099240000, '14.45', '4.08', '60'], [1629099300000, None, '3.32', '60'], [1629099360000, '19.619999999999997', '3.62', '60'], [1629099420000, None, '3.22', '60'], [1629099480000, '13.57', '3.12', '60'], [1629099540000, '8.74', '3.89', '60'], [1629099600000, '19.95', '4.03', '60'], [1629099660000, '23.92', '4.09', '60'], [1629099720000, '20.68', '3.47', '60'], [1629099780000, '11.17', '3.26', '60'], [1629099840000, '16.51', '3.87', '60'], [1629099900000, '17.03', '3.49', '60'], [1629099960000, '20.23', '3.59', '60'], [1629100020000, '25.61', '3.19', '60'], [1629100080000, '16.16', '3.13', '60'], [1629100140000, '14.51', '3.93', '60'], [1629100200000, '19.98', '4.05', '60'], [1629100260000, '26.49', '4.12', '60'], [1629100320000, '23.91', '3.54', '60'], [1629100380000, '12.78', '3.19', '60'], [1629100440000, '17.38', '4.76', '60'], [1629100500000, '9.72', '3.27', '60'], [1629100560000, '23.05', '3.71', '60'], [1629100620000, '25.06', '3.24', '60'], [1629100680000, '11.74', '3.18', '60'], [1629100740000, '10.07', '3.92', '60'], [1629100800000, '23.48', '4.48', '60'], [1629100860000, '23.6', '3.99', '60'], [1629100920000, '20.87', '3.43', '60'], [1629100980000, '11.55', '3.39', '60'], [1629101040000, '16.32', '3.88', '60'], [1629101100000, '11.93', '3.28', '60'], [1629101160000, '21.27', '5.1', '60'], [1629101220000, '18.35', '3.2', '60'], [1629101280000, '16.95', '3.13', '60'], [1629101340000, '12.02', '3.92', '60'], [1629101400000, '18.83', '4.07', '60'], [1629101460000, '17.75', '4.09', '60'], [1629101520000, '29.41', '3.39', '60'], [1629101580000, '10.97', '3.41', '60'], [1629101640000, '17.55', '3.88', '60'], [1629101700000, '14.01', '3.29', '60'], [1629101760000, '24.12', '3.58', '60'], [1629101820000, '18.2', '3.2', '60'], [1629101880000, '13.88', '3.14', '60'], [1629101940000, '8.81', '3.91', '60'], [1629102000000, '21.67', '4.21', '60'], [1629102060000, '23.58', '4.01', '60'], [1629102120000, '19.18', '3.16', '60'], [1629102180000, '13.64', '3.37', '60'], [1629102240000, '19.12', '3.92', '60'], [1629102300000, '12.01', '3.27', '60'], [1629102360000, '22.57', '3.69', '60'], [1629102420000, '22.42', '3.39', '60'], [1629102480000, '18.56', '3.19', '60']]}}
def dataPreprocess(data):
import json,numpy
# totalData=json.loads(data)
fields=data['search_result']['fields']
fields.remove('_time')
fields.remove('_span')
datetimeValue=[]
allInfo=[[] for i in range(len(fields))]
from datetime import datetime
import pytz
tw = pytz.timezone('Asia/Taipei')
totalData=data['search_result']['rows']
for singleData in totalData:
singleDatetime=datetime.fromtimestamp(singleData[0]/1000)
singleDatetime=pytz.utc.localize(singleDatetime).astimezone(tw)
datetimeValue.append(singleDatetime)
for i in range(len(fields)):
allInfo[i].append(float(singleData[i+1]) if singleData[i+1] else numpy.nan)#numpy.nan
return {'dateTime':datetimeValue,'allInfo':allInfo,'fields':fields,'db':data['choose_db'],'y_name':data['choose_info_type'].upper()+'_util'}
def plotPicAnd2Base64(data):
import matplotlib.pyplot as plt
print(plt.get_backend())
plt.figure(figsize=(6, 2.9), dpi=100)
processedData=dataPreprocess(data)
print('processedData:\n',processedData)
allInfo=processedData['allInfo']
minVal,maxVal=0,0
print('allInfo:\n','len all Info ',len(allInfo),'\n',len(allInfo[0]),allInfo[0],len(allInfo[0]),allInfo[1],sep='\n\n',end='\n\n')
for i in range(len(allInfo)):
plt.plot(processedData['dateTime'],allInfo[i], marker='.', linestyle = '-',label=processedData['fields'][i])
minInItem,maxInItem=min(allInfo[i]),max(allInfo[i])
minVal=minInItem if minVal>minInItem or (minVal==0) else minVal
maxVal=maxInItem if maxVal<maxInItem else maxVal
plt.legend(loc = 'upper left')
plt.xlabel('DateTime', color = 'black')
plt.ylabel(processedData['y_name'], color = 'black')
plt.xticks(rotation=14,fontsize=8)
plt.yticks(fontsize=8)
plt.title(processedData['db'], color = 'black')
plt.ylim(minVal-1, maxVal+10) #if processedData['y_name']=='CPU_util' else None
# plt.show()
import io,base64
plotfig_stringIObytes=io.BytesIO()
plt.savefig(plotfig_stringIObytes,format='jpg',bbox_inches='tight',dpi=1000)#pad_inches=0.0
plotfig_stringIObytes.seek(0)
base64_plotFig = base64.b64encode(plotfig_stringIObytes.read())
return base64_plotFig.decode('utf-8')
# print(plotPicAnd2Base64(data))
# import os,base64
# file = os.path.join(os.getcwd(), "cost.jpg")
# image = open(file, 'rb')
# image_read = image.read()
# # image_64_encode = base64.encodebytes(image_read) #encodestring also works aswell as decodestring
# # encodestring also works aswell as decodestring
# image_64_encode = base64.b64encode(image_read).decode()
# print(image_64_encode)