-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_data.py
50 lines (38 loc) · 1.43 KB
/
change_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
import csv
import os
import random
import numpy as np
name_colors = ['black', 'white', 'red', 'green']
color_mean = [[230, 25, 230]]
def random_data(length = 1000, scope = 25, value = [], name = ""):
# Check parameter length.
if not isinstance(length, int):
raise ValueError(f"Parameter length should be type int.")
assert length > 0, f"Parameter length should bigger than zero"
# Check parameter range.
if not isinstance(scope, int):
raise ValueError(f"Parameter range should be type int.")
assert 30 > scope > 0, f"Parameter range should bigger than zero and smaller than 30."
# Value color
value_scope_color = []
index = 0
while index < length:
# Random value
rd_value = [random.randint(-scope, scope) for i in range(len(value))]
v = list(np.array(value) - np.array(rd_value))
if v not in value_scope_color:
value_scope_color.append(v)
index += 1
return value_scope_color
# Write data
def write_data(path = "", dataset = None):
assert os.path.isfile(path), f"Not found file {path}."
with open(path, 'w', newline="") as file:
write = csv.writer(file)
write.writerows(dataset)
if __name__ == '__main__':
data = []
for i, i_color in enumerate(color_mean):
value = random_data(1000, 25, i_color, name_colors[i])
data += value
write_data(path = './data_max.csv',dataset = data)