-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexploit-kwapi-datas.py
More file actions
116 lines (104 loc) · 3.98 KB
/
exploit-kwapi-datas.py
File metadata and controls
116 lines (104 loc) · 3.98 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from pandas import *
import os
import matplotlib.pyplot as plt
import matplotlib.cm as cmx
import matplotlib.colors as colors
import time
import numpy as np
plots = []
def format_matlab(index, plot_list, day = True, colors_list = None):
if not colors_list:
colors_list = []
color_norm = colors.Normalize(vmin=0, vmax=len(plot_list)-1)
scalar_map_day = cmx.ScalarMappable(norm=color_norm, cmap='Greens')
scalar_map_night = cmx.ScalarMappable(norm=color_norm, cmap='Reds')
for i in range(len(plot_list)):
plot_list[i] = [x[0] for x in plot_list[i].values]
if day:
colors_list.append(scalar_map_day.to_rgba(i))
else:
colors_list.append(scalar_map_night.to_rgba(i))
print "Plot"
plt.stackplot(index, plot_list, colors=colors_list)
plt.show()
return colors_list
i = 0
for f in os.listdir("datas/"):
if f.endswith(".json.out"):
print f
try:
plots.append(read_json(path_or_buf="datas/"+f, orient="split"))
except e:
print e
i+=1
print "Unified frequency to 1s"
plots = map(pandas.DataFrame.asfreq, plots, ['1s']*len(plots), ['pad']*len(plots))
print "Streched data from 2015-01-01 to 2015-02-19"
plots = [x['2015-01-28':'2015-02-19'] for x in plots]
print "Resample"
plots = map(pandas.DataFrame.resample, plots, ['1800s']*len(plots), ["mean"]*len(plots))
index = plots[0].index
print "Filter weekends"
weekends = filter(lambda x: x.weekday() >= 5, index)
weekends_data = []
for i in range(len(plots)):
weekends_data.append(plots[i].reindex(weekends).values)
#format_matlab(weekends, weekends_data)
print "weekends mean", np.array(weekends_data).mean()
print "Filter weekends night"
weekends_night = filter(lambda x: x.hour >= 19 or x.hour < 9, weekends)
weekends_data_night = []
for i in range(len(plots)):
weekends_data_night.append(plots[i].reindex(weekends_night).values)
#format_matlab(index, weekends_data_night)
print "weekends night mean", np.array(weekends_data_night).mean()
#print len(read_json(path_or_buf="datas/"+f, orient="split").values)
del weekends_night
del weekends_data_night
print "Filter weekends day"
weekends_day = filter(lambda x: x.hour < 19 and x.hour >= 9, weekends)
weekends_data_day = []
for i in range(len(plots)):
weekends_data_day.append(plots[i].reindex(weekends_day).values)
#format_matlab(index, weekends_data_day)
print "weekends day mean", np.array(weekends_data_day).mean()
del weekends_day
del weekends_data_day
del weekends
del weekends_data
print "Filter weekdays"
weekdays = filter(lambda x: x.weekday() < 5, index)
weekdays_data = []
for i in range(len(plots)):
weekdays_data.append(plots[i].reindex(weekdays).values)
#format_matlab(index, weekdays_data)
print "weekdays mean", np.array(weekdays_data).mean()
print "Filter weekdays night"
weekdays_night = filter(lambda x: x.hour >= 19 or x.hour < 9, weekdays)
weekdays_data_night = []
for i in range(len(plots)):
weekdays_data_night.append(plots[i].reindex(weekdays_night).values)
#colors_night = format_matlab(index, weekdays_data_night, day = False)
print "weekdays night mean", np.array(weekdays_data_night).mean()
del weekdays_night
#del weekdays_data_night
print "Filter weekdays day"
weekdays_day = filter(lambda x: x.hour < 19 and x.hour >= 9, weekdays)
weekdays_data_day = []
for i in range(len(plots)):
weekdays_data_day.append(plots[i].reindex(weekdays_day).values)
#colors_day = format_matlab(index, weekdays_data_day)
print "weekdays days mean", np.array(weekdays_data_day).mean()
#colors_all = colors_night + colors_day
#data_all = weekdays_data_day + weekdays_data_night
#print len(colors_all) , len(data_all), len(weekdays_data_day)
#format_matlab(index, data_all, colors_list= colors_all)
del weekdays_day
del weekdays_data_day
del weekdays
del weekdays_data
print "Format for matplot"
print "Resample"
plots = map(pandas.DataFrame.resample, plots, ['D']*len(plots), ["mean"]*len(plots))
index = plots[0].index
#format_matlab(index, plots)