-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation_profiles.py
124 lines (101 loc) · 3.48 KB
/
validation_profiles.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
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
116
117
118
119
120
121
122
123
124
import random
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import pandas as pd
from collections import defaultdict
from pprint import pprint
import utils
SIZE = 6
AMPLITUDE = 10
profiles = {
'.........XXXXXX...': 'mountain',
'......XXXXXX......': 'constant',
'....XX...X..XXX...': 'mitigated raise',
'....XX..XX..XX....': 'bounded rise',
'...X......X.XXX..X': 'failed soar',
'...X......XXXXX...': 'mountain',
'...X...X..X.X.X..X': 'fall',
'...XX.......XXX..X': 'falling unstable',
'...XX......XXXX...': 'constant unstable',
'...XX..X....X.X..X': 'mitigated fall',
'...XX..XX..XX.....': 'trench',
'...XXX......XXX...': 'raising unstable',
'...XXX..X...XX....': 'raising unstable',
}
counts = defaultdict(int)
def create_curve():
max, min = random.randint(0, AMPLITUDE), random.randint(0, AMPLITUDE)
if min > max:
min, max = max, min
start = random.randint(min, max)
stop = random.randint(min, max)
series = [start] + [None] * (SIZE-2) + [stop]
idx_min, idx_max = random.sample(list(range(1, SIZE-1)), k=2)
series[idx_max], series[idx_min] = max, min
return [random.randint(min, max) if elem is None else elem for elem in series]
def create_and_show_curve():
df = pd.DataFrame({'step': list(range(SIZE)), 'score':list(create_curve())})
profile = utils.get_series_profile(list(df['score']))
profile_name = utils.profile_name_from(profile, names=profiles)
print(profile)
print(utils.get_series_profile(list(df['score']), human_readable=True))
print(profile_name)
df.plot(x='step', y=['score'])
# plt.show()
plt.savefig('test.png')
return df, profile, profile_name
def ask_profile_name(df, profile, profile_name):
profrepr = ''.join('X' if v else '.' for v in profile)
if profile_name == '?':
prop = input(f'How should i name {profrepr} ?\n?> ').strip()
if prop:
profile_name = profiles[profrepr] = prop.lower()
counts['?'] += 1 # also count number of newly found profiles
pprint(profiles)
else:
print(f'I would name {profrepr} "{profile_name}"')
counts[profile_name] += 1
try:
while True:
c = create_and_show_curve()
try:
ask_profile_name(*c)
except (EOFError, KeyboardInterrupt):
break
except (EOFError, KeyboardInterrupt):
pass
print()
pprint(profiles)
pprint(counts)
FOUND = """
{'.........XXXXXX...': 'mountain',
'......XXXXXX......': 'constant',
'....X....X.XXXX...': 'mountain',
'....XX...X..XXX...': 'mitigated raise',
'....XX..XX..XX....': 'bounded rise',
'...X......X.XXX..X': 'failed soar',
'...X......XXXXX...': 'mountain',
'...X...X..X.X.X..X': 'fall',
'...XX.......XXX..X': 'falling unstable',
'...XX......XXXX...': 'constant unstable',
'...XX...X..XXX....': 'trench',
'...XX..X....X.X..X': 'mitigated fall',
'...XX..X...XX.X...': 'trench',
'...XX..XX..XX.....': 'trench',
'...XXX......XXX...': 'raising unstable',
'...XXX..X...XX....': 'raising unstable'}
defaultdict(<class 'int'>,
{'?': 3,
'bounded rise': 66,
'constant': 35,
'constant unstable': 339,
'failed soar': 278,
'fall': 56,
'falling unstable': 1418,
'mitigated fall': 257,
'mitigated raise': 261,
'mountain': 89,
'raising unstable': 1684,
'trench': 79})
"""