-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresources_generate_notesradar.py
179 lines (143 loc) · 6.58 KB
/
resources_generate_notesradar.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
from os.path import join,exists
import json
from define import define
from resources import resource
from resources_generate import Report,save_resource_serialized,registries_dirname,report_dirname
resource_filename = f'notesradar{define.notesradar_version}.res'
filenames = {
'SP': join(registries_dirname, 'notesradardata_sp.csv'),
'DP': join(registries_dirname, 'notesradardata_dp.csv')
}
ignore_filepath = join(registries_dirname, 'notesradar_ignore.json')
difficulties = {
'B': 'BEGINNER',
'N': 'NORMAL',
'H': 'HYPER',
'A': 'ANOTHER',
'L': 'LEGGENDARIA'
}
report_name = 'notesradar'
def load_musictable():
resource.load_resource_musictable()
return resource.musictable
def import_csv():
csv = {}
for key, filename in filenames.items():
if exists(filename):
with open(filename, 'r', encoding='utf-8') as f:
csvdata = f.read().split('\n')
splitted = [line.split(',') for line in csvdata]
csv[key] = [[
s[1],
s[2].replace('""', '"'),
difficulties[s[4]],
s[5],
int(s[6]),
{
'NOTES': float(s[13]),
'CHORD': float(s[15]),
'PEAK': float(s[17]),
'CHARGE': float(s[19]),
'SCRATCH': float(s[21]),
'SOF-LAN': float(s[23])
}
] for s in splitted if len(s[1]) > 0 and s[1] != 'バージョン' and s[6].isdigit()]
return csv
def output_attributevalues(resource: dict, output_dirpath: str):
for playmode, targets1 in resource.items():
for attribute, targets2 in targets1['attributes'].items():
output = []
for target in targets2:
musicname = target['musicname']
difficulty = target['difficulty']
value = resource[playmode]['musics'][musicname][difficulty]['radars'][attribute]
output.append(f'{value:>6.2f}: {musicname}({difficulty})')
filename = f'{playmode}_{attribute}.txt'
filepath = join(output_dirpath, filename)
with open(filepath, 'w', encoding='UTF-8') as f:
f.write('\n'.join(output))
def output_not_in_notesradar(added: dict, musics: dict, output_dirpath: str):
not_in_notesradar_music_filepath = join(output_dirpath, 'not_in_notesradar.csv')
output = []
output.append('Music')
output.append('\n'.join([f'- {musicname}' for musicname in musics.keys() if not musicname in added.keys()]))
output.append('')
for playmode in define.value_list['play_modes']:
output.append(f'Difficulty {playmode}')
for musicname in musics.keys():
if musicname in added.keys() and playmode in added[musicname].keys():
for difficulty in musics[musicname][playmode].keys():
if not difficulty in added[musicname][playmode]:
output.append(f'- {musicname} {difficulty}')
output.append('')
with open(not_in_notesradar_music_filepath, 'w', encoding='UTF-8') as f:
f.write('\n'.join(output))
def generate(musics, csv):
report = Report(report_name)
if exists(ignore_filepath):
with open(ignore_filepath, 'r', encoding='UTF-8') as f:
ignore = json.load(f)
else:
ignore = {}
resource: dict[str, dict[str, dict[str, dict[str, int | dict[str, float]]]| dict[str, list[dict[str, str | int]]]]] = {}
for playmode in define.value_list['play_modes']:
resource[playmode] = {'musics': {}, 'attributes': {}}
duplicate_difficulty = []
added = {}
for playmode in define.value_list['play_modes']:
attribute_list = {}
for attribute in define.value_list['notesradar_attributes']:
attribute_list[attribute] = []
for line in csv[playmode]:
musicname = line[1]
difficulty = line[2]
notes = line[4]
radars = line[5]
if not musicname in musics.keys():
continue
if not difficulty in musics[musicname][playmode].keys():
continue
if musicname in ignore.keys() and playmode in ignore[musicname].keys() and difficulty in ignore[musicname][playmode]:
report.append_log(f'Ignore {playmode} {musicname} {difficulty}')
continue
if musicname in added.keys() and playmode in added[musicname].keys() and difficulty in added[musicname][playmode]:
duplicate_difficulty.append(f'{playmode} {musicname} {difficulty}')
continue
if not musicname in resource[playmode]['musics'].keys():
resource[playmode]['musics'][musicname] = {}
if not difficulty in resource[playmode]['musics'][musicname].keys():
resource[playmode]['musics'][musicname][difficulty] = {
'notes': notes,
'radars': radars
}
for attribute, value in radars.items():
if value != 0:
attribute_list[attribute].append({
'musicname': musicname,
'difficulty': difficulty,
'max': radars[attribute]
})
if not musicname in added.keys():
added[musicname] = {}
if not playmode in added[musicname].keys():
added[musicname][playmode] = []
added[musicname][playmode].append(difficulty)
for attribute in attribute_list.keys():
attribute_list[attribute].sort(key=lambda t: t['max'], reverse=True)
sorted_attributevalues = [{'musicname': t['musicname'], 'difficulty': t['difficulty']} for t in attribute_list[attribute]]
resource[playmode]['attributes'][attribute] = sorted_attributevalues
if len(duplicate_difficulty) > 0:
report.error(f'Find duplicate difficulty: {len(duplicate_difficulty)}')
for line in duplicate_difficulty:
report.error(line)
report.report()
output_attributevalues(resource, report.report_dirpath)
output_not_in_notesradar(added, musics, report.report_dirpath)
return resource
def generate_notesradar():
musictable = load_musictable()
csv = import_csv()
resource = generate(musictable['musics'], csv)
save_resource_serialized(resource_filename, resource)
if __name__ == '__main__':
generate_notesradar()