-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDISTINCT.py
71 lines (62 loc) · 2.5 KB
/
DISTINCT.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
from FlokAlgorithmLocal import FlokAlgorithmLocal, FlokDataFrame
import pandas as pd
class distinct(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]
q = len(set(output_data[timeseries_list[1]]))
j = 'distinct({})'.format([timeseries_list[1]])
data = {'Time': (output_data['Time'][0:q]), j: list(
set(output_data[timeseries_list[1]]))}
output_data = pd.DataFrame(data)
else:
output_data = input_data
# print(type(output_data))
result = FlokDataFrame()
result.addDF(output_data)
return result
if __name__ == "__main__":
algorithm = distinct()
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)