-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_batch_data.py
81 lines (59 loc) · 2.18 KB
/
send_batch_data.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
80
81
import argparse
import requests
import pandas as pd
import numpy as np
def get_bad_data(path: str) -> np.ndarray:
"""Generate bad data
Args:
path (str): Path to dataset
Returns:
np.ndarray: Array of bad data
"""
data = pd.read_pickle(path).drop(columns=['quality'])
data["volatile acidity"] = 3 + data["volatile acidity"]
data["citric acid"] = 5 + data["citric acid"]
data["alcohol"] = 20
return data.values
def get_good_data(path: str) -> np.ndarray:
"""Generate normal data
Args:
path (str): Path to dataset
Returns:
np.ndarray: Array of normal data
"""
data = pd.read_pickle(path).drop(columns=['quality'])
return data.values
def get_noisy_data(path: str) -> np.ndarray:
"""Generate noisy data
Args:
path (str): Path to dataset
Returns:
np.ndarray: Array of noisy data
"""
data = pd.read_pickle(path).drop(columns=['quality'])
data[:data.shape[0] // 2] = data[:data.shape[0] // 2] + np.random.normal(0.1, 0.01, (data.shape[0] // 2, data.shape[1]))
return data.values
def send_data(data: np.ndarray):
"""Send data to backend
Args:
data (np.ndarray): Array of data
"""
json = {"data": data.tolist()}
requests.post("http://localhost:80/batch", json=json)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Send a batch of data to the backend.")
parser.add_argument("data_type", choices=["corrupted", "normal", "noisy"],
help="""Type of data to process:
- corrupted: data that do not respect the initial distribution
- normal: data that respect the initial distribution
- noisy: data that respect the initial distribution but with noise
""")
args = parser.parse_args()
path = "./data/training/wine.pkl"
if args.data_type == "corrupted":
data = get_bad_data(path)
elif args.data_type == "normal":
data = get_good_data(path)
elif args.data_type == "noisy":
data = get_noisy_data(path)
send_data(data)