-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomData.py
More file actions
115 lines (99 loc) · 2.99 KB
/
randomData.py
File metadata and controls
115 lines (99 loc) · 2.99 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/python3
from common import PATH
from random import choice, randint, shuffle
import json
# value range and target path value
targetRangeBegin = 50
targetRangeEnd = 650
targetMaxEnd1 = 660 # difficult
targetMaxEnd2 = 1200 # easy
def getRandomTargetData():
data = []
for _ in range(12):
targetName = choice(PATH)
if _ % 2 == 0:
targetValue = targetMaxEnd1
else:
targetValue = targetMaxEnd2
# Paths other than the target path
easyPath = []
difficultPath = []
for item in PATH:
easy = {}
difficult = {}
if item != targetName:
# easy data
easy['name'] = item
easy['value'] = randint(targetRangeBegin, targetRangeEnd)
easyPath.append(easy)
else:
# difficult data
difficult['name'] = targetName
difficult['value'] = targetValue
difficultPath.append(difficult)
d = {
'target_name': targetName,
'target_value': targetValue,
'easy': easyPath,
'difficult': difficultPath
}
typeAndColor(_, d)
data.append(d)
return data
def typeAndColor(index, data):
if index == 0:
data['image_type'] = 'column'
data['color'] = 'text'
if index == 1:
data['image_type'] = 'column'
data['color'] = 'text'
if index == 2:
data['image_type'] = 'column'
data['color'] = 'color'
if index == 3:
data['image_type'] = 'column'
data['color'] = 'color'
if index == 4:
data['image_type'] = 'bar'
data['color'] = 'text'
if index == 5:
data['image_type'] = 'bar'
data['color'] = 'text'
if index == 6:
data['image_type'] = 'bar'
data['color'] = 'color'
if index == 7:
data['image_type'] = 'bar'
data['color'] = 'color'
if index == 8:
data['image_type'] = 'pie'
data['color'] = 'color'
if index == 9:
data['image_type'] = 'pie'
data['color'] = 'color'
if index == 10:
data['image_type'] = 'pie'
data['color'] = 'none'
if index == 11:
data['image_type'] = 'pie'
data['color'] = 'none'
def getData():
serializeData = []
targetData = getRandomTargetData()
for item in targetData:
data_list = item.get('easy') + item.get('difficult')
shuffle(data_list)
_data = {
'data_type': 'easy' if item.get('target_value') == targetMaxEnd2 else 'difficult',
'target_name': item.get('target_name'),
'target_value': item.get('target_value'),
'image_type': item.get('image_type'),
'color': item.get('color'),
'data': data_list
}
serializeData.append(_data)
shuffle(serializeData)
return serializeData
if __name__ == "__main__":
data = getData()
print(json.dumps(data))