Spaces:
Runtime error
Runtime error
File size: 1,580 Bytes
c145eab 17a347d 1cc60af 17a347d c145eab 1cc60af c145eab 1cc60af 17a347d c145eab |
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 |
import json
from collections import defaultdict
from utils.parser import COLUMNS
DELIMITER = "-"
COMMA = ","
SEMICOLON = ";"
def serialize(records):
result = {}
for player_id in records:
result[player_id] = records[player_id][COLUMNS].to_dict(orient="records")
return result
def unserialize(data: dict):
records = defaultdict(lambda: defaultdict(lambda: defaultdict(dict)))
for player_id in data:
for target_id in data[player_id]:
for skill, status in data[player_id][target_id].items():
skill = tuple(int(e) for e in skill.split(DELIMITER))
for status_set, timeline in status.items():
current_status, snapshot_status, target_status = status_set.split(SEMICOLON)
current_status = tuple(
tuple(int(e) for e in buffs.split(DELIMITER)) for buffs in current_status.split(COMMA)
) if current_status else tuple()
snapshot_status = tuple(
tuple(int(e) for e in buffs.split(DELIMITER)) for buffs in snapshot_status.split(COMMA)
) if snapshot_status else tuple()
target_status = tuple(
tuple(int(e) for e in buffs.split(DELIMITER)) for buffs in target_status.split(COMMA)
) if target_status else tuple()
concat_status = (current_status, snapshot_status, target_status)
records[player_id][target_id][skill][concat_status] = timeline
return records
|