forked from Ridepad/uwu-logs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs_player_spec.py
90 lines (75 loc) · 3.04 KB
/
logs_player_spec.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
from c_player_classes import CLASS_FROM_HTML, SPECS_LIST, SPELL_BOOK_SPEC
from h_debug import running_time
CLASSES = list(CLASS_FROM_HTML)
# def get_spec_info(player_class: str, spec_index: int=0):
# classi = CLASSES.index(player_class)
# return SPECS_LIST[classi*4+spec_index]
def get_spec_info(spec_index):
return SPECS_LIST[spec_index]
# 40% faster to slice 3 times, if check and slice 4 more times, than to slice every loop 8 times
def specs_gen(logs: list[str], players: dict[str, str], classes: dict[str, str]):
class_spells = {guid: SPELL_BOOK_SPEC[classes[guid]] for guid in players if guid in classes}
for line in logs:
_, _, guid, etc = line.split(',', 3)
if guid not in class_spells:
continue
try:
_spell_id = etc.split(',', 4)[3]
if _spell_id not in class_spells[guid]:
continue
except IndexError:
continue
_spells = class_spells.pop(guid)
spec_index = _spells[_spell_id]
yield guid, spec_index
if not class_spells:
break
@running_time
def get_specs(logs: list[str], players: dict[str, str], classes: dict[str, str], cut=True):
if cut:
logs = logs[:100_000]
SPECS = {}
for guid, spec_index in specs_gen(logs, players, classes):
player_class = classes[guid]
classi = CLASSES.index(player_class)
SPECS[guid] = classi*4+spec_index
for player_guid, player_class in classes.items():
if player_guid not in SPECS:
SPECS[player_guid] = CLASSES.index(player_class) * 4
return SPECS
# def convert_specs_to_full_info(specs: dict[str, int], classes: dict[str, str]):
# new_data: dict[str, tuple[str, str]] = {}
# for guid, spec_index in specs.items():
# player_class = classes[guid]
# new_data[guid] = get_spec_info(player_class, spec_index)
# return new_data
# def convert_specs_to_spec_index(specs: dict[str, int], classes: dict[str, str]):
# new_data: dict[str, int] = {}
# for guid, spec_index in specs.items():
# player_class = classes[guid]
# classi = CLASSES.index(player_class)
# new_data[guid] = classi*4+spec_index
# return new_data
# TODO: change to bytes for 10% speed improvement
# _SPELL_BOOK_SPEC = {
# q.encode(): {
# k.encode(): v
# for k,v in w.items()
# }
# for q,w in SPELL_BOOK_SPEC.items()
# }
# def specs_gen_bytes(logs: list[bytes], players: dict[bytes, str], classes: dict[bytes, str]):
# class_spells = {guid: _SPELL_BOOK_SPEC[classes[guid]] for guid in players if guid in classes}
# for line in logs:
# _, _, guid, line = line.split(b',', 3)
# if guid not in class_spells:
# continue
# try:
# _spell_id = line.split(b',', 4)[3]
# spec_index = class_spells[guid][_spell_id]
# del class_spells[guid]
# yield guid, spec_index
# if not class_spells:
# break
# except (IndexError, KeyError):
# continue