-
Notifications
You must be signed in to change notification settings - Fork 0
/
skew.py
76 lines (66 loc) · 2.7 KB
/
skew.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
from FlokAlgorithmLocal import FlokAlgorithmLocal, FlokDataFrame
import math
import pandas as pd
class skew(FlokAlgorithmLocal):
def run(self, inputDataSets, params):
input_data = inputDataSets.get(0)
timeseries = params.get("timeseries", None)
if timeseries:
timeseries_list = timeseries.split(',')
output_data = input_data[timeseries_list]
column = timeseries_list[1]
output_data.dropna(inplace=True)
mean = sum(output_data[column])/len(output_data[column])
std = math.sqrt(sum((output_data[column]-mean) **
2)/len(output_data[column]))
skew = sum(((output_data[column]-mean)/std)** 3)/len(output_data[column])
j = 'skew({})'.format(column)
data = {'Time': output_data['Time'][0], j: skew}
output_data = pd.DataFrame(data, index=[0])
else:
output_data = input_data
result = FlokDataFrame()
result.addDF(output_data)
return result
if __name__ == "__main__":
algorithm = skew()
all_info_1 = {
"input": ["./test_in.csv"],
"inputFormat": ["csv"],
"inputLocation": ["local_fs"],
"output": ["./test_out_1.csv"],
"outputFormat": ["csv"],
"outputLocation": ["local_fs"],
"parameters": {}
}
params = all_info_1["parameters"]
inputPaths = all_info_1["input"]
inputTypes = all_info_1["inputFormat"]
inputLocation = all_info_1["inputLocation"]
outputPaths = all_info_1["output"]
outputTypes = all_info_1["outputFormat"]
outputLocation = all_info_1["outputLocation"]
dataSet = algorithm.read(inputPaths, inputTypes,
inputLocation, outputPaths, outputTypes)
result = algorithm.run(dataSet, params)
algorithm.write(outputPaths, result, outputTypes, outputLocation)
all_info_2 = {
"input": ["./test_in.csv"],
"inputFormat": ["csv"],
"inputLocation": ["local_fs"],
"output": ["./test_out_2.csv"],
"outputFormat": ["csv"],
"outputLocation": ["local_fs"],
"parameters": {"timeseries": "Time,root.test.d2.s2"}
}
params = all_info_2["parameters"]
inputPaths = all_info_2["input"]
inputTypes = all_info_2["inputFormat"]
inputLocation = all_info_2["inputLocation"]
outputPaths = all_info_2["output"]
outputTypes = all_info_2["outputFormat"]
outputLocation = all_info_2["outputLocation"]
dataSet = algorithm.read(inputPaths, inputTypes,
inputLocation, outputPaths, outputTypes)
result = algorithm.run(dataSet, params)
algorithm.write(outputPaths, result, outputTypes, outputLocation)