-
Notifications
You must be signed in to change notification settings - Fork 3
/
EPUtils.py
executable file
·79 lines (61 loc) · 2.7 KB
/
EPUtils.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# @Time : Jul. 10, 2020 19:45
# @Author : Zhen Zhang
# @Email : [email protected]
# @FileName : EPUtils.py
# @Version : 1.0
# @IDE : VSCode
import pyecharts.options as opts
from pyecharts.charts import Line
import uuid
import arrow
import json
import numpy as np
def drawMetricChart(title,timeAxis,lines):
chart = (Line(init_opts=opts.InitOpts(width="1400px", height="660px"))
.set_global_opts(
# datazoom_opts=opts.DataZoomOpts(range_start = 5,
# range_end = 10),
title_opts=opts.TitleOpts(title=title),
legend_opts=opts.LegendOpts(is_show=True,
orient = "vertical",
pos_left = "10%",
pos_top = "20%",
type_ = "scroll"),
)
)
chart.add_xaxis(timeAxis)
for lineName in lines:
chart.add_yaxis(lineName, lines[lineName],is_smooth=True,is_symbol_show=False,is_selected = True)
return chart
def drawResult(filePath):
config = None
with open(filePath) as json_file:
config = json.load(json_file)
if config is not None:
timeAxis = [ arrow.get("2017-01-01 00:00:00").shift(seconds=+(config["predictionOffests"][x]*config["interval"]*60)).format("HH:mm") for x in np.arange(len(config["predictionOffests"])).tolist()]
mae_lines = {}
rmse_lines = {}
r2_lines = {}
for uuid in config["results"]:
model = config["experiences"][uuid]["model"]
mae = []
rmse = []
r2 = []
b = {}
for e in range(len(config["predictionOffests"])):
ts = dict(config["results"][uuid][e])
for x in ts.keys():
#print(x)
b[x] = ts[x]
#print(b)
for i in config["predictionOffests"]:
print(b["t"+str(i)])
mae.append(b["t"+str(i)]["mae"])
rmse.append(b["t"+str(i)]["rmse"])
#if "r2" in config["results"][uuid]["t"+str(i)]:
r2.append(b["t"+str(i)]["r2"])
mae_lines[model+" ["+uuid[:8]+"]"]=mae
rmse_lines[model+" ["+uuid[:8]+"]"]=rmse
#if len(r2) > 0:
r2_lines[model+" ["+uuid[:8]+"]"]=r2
return drawMetricChart("MAE",timeAxis,mae_lines),drawMetricChart("RMSE",timeAxis,rmse_lines),drawMetricChart("R2",timeAxis,r2_lines)