-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathbaseline.py
38 lines (29 loc) · 1.03 KB
/
baseline.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
import argparse
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
import json
import sys
class AlgorithmArgs(argparse.Namespace):
@property
def ts_length(self) -> int:
return self.df.shape[0]
@property
def df(self) -> pd.DataFrame:
return pd.read_csv(self.dataInput)
@staticmethod
def from_sys_args() -> 'AlgorithmArgs':
args: dict = json.loads(sys.argv[1])
return AlgorithmArgs(**args)
def execute(args: AlgorithmArgs):
indices = np.arange(args.ts_length)
anomaly_scores = MinMaxScaler().fit_transform(indices.reshape(-1, 1)).reshape(-1)
anomaly_scores.tofile(args.dataOutput, sep="\n")
if __name__ == "__main__":
args = AlgorithmArgs.from_sys_args()
if args.executionType == "train":
print("This algorithm does not need to be trained!")
elif args.executionType == "execute":
execute(args)
else:
raise ValueError(f"No executionType '{args.executionType}' available! Choose either 'train' or 'execute'.")