-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
141 lines (109 loc) · 3.21 KB
/
main.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
from re import search
from typing import TypedDict
from polars import DataFrame
from uvloop import run
from app.api import MyGamatoto
from app.models.enemy_info import EnemyInfo
class RestructuredEnemyInfo(TypedDict):
"""
Summary
-------
the restructured enemy info
"""
name: str
health: int
type: int
knockbacks: int
speed: int
total_attack_power: int
damage_per_second: int
range: int
min_range: int
max_range: int
money: int
time_between_attacks: str
def get_type_flags(enemy_info: EnemyInfo) -> int:
"""
Summary
-------
get the type flags
"""
flag = 0
if enemy_info.white:
flag |= 0b0000000000000
if enemy_info.red:
flag |= 0b0000000000001
if enemy_info.black:
flag |= 0b0000000000010
if enemy_info.angel:
flag |= 0b0000000000100
if enemy_info.alien:
flag |= 0b0000000001000
if enemy_info.zombie:
flag |= 0b0000000010000
if enemy_info.relic:
flag |= 0b0000000100000
if enemy_info.aku:
flag |= 0b0000001000000
if enemy_info.dojo_base:
flag |= 0b0000010000000
if enemy_info.baron:
flag |= 0b0001000000000
if enemy_info.beast:
flag |= 0b0010000000000
if enemy_info.witch:
flag |= 0b0100000000000
if enemy_info.eva:
flag |= 0b1000000000000
return flag
def get_long_distance_ranges(enemy_range: int, special_attack_description: str) -> tuple[int, int]:
"""
Summary
-------
get the long distance ranges
"""
range_numbers = search(r"Effective range (\d+)~(\d+)", special_attack_description)
return (
(int(range_numbers.group(1)), int(range_numbers.group(2)))
if range_numbers else (0, enemy_range)
)
def restructure_enemy_info(enemy_info: EnemyInfo) -> RestructuredEnemyInfo:
"""
Summary
-------
restructure the enemy info
"""
min_range, max_range = get_long_distance_ranges(enemy_info.range, enemy_info.special_attack_description)
return RestructuredEnemyInfo(
name = enemy_info.name,
health = enemy_info.health,
type = get_type_flags(enemy_info),
knockbacks = enemy_info.knockbacks,
speed = enemy_info.speed,
total_attack_power = enemy_info.attack_power1 + enemy_info.attack_power2 + enemy_info.attack_power3,
damage_per_second = enemy_info.damage_per_second,
range = enemy_info.range,
min_range = min_range,
max_range = max_range,
money = enemy_info.money,
time_between_attacks = enemy_info.time_between_attacks
)
async def build_data(client: MyGamatoto):
"""
build the data
"""
enemy_names = await client.get_enemy_names()
enemy_infos = [await client.get_enemy_info(name) for name in enemy_names]
restructured_enemy_info = [restructure_enemy_info(enemy_info) for enemy_info in enemy_infos]
df = DataFrame(restructured_enemy_info)
df.write_csv('enemy_infos.csv')
async def main():
"""
Summary
-------
the main entrypoint
"""
async with MyGamatoto('https://onestoppress.com/api') as client:
await build_data(client)
if __name__ == "__main__":
run(main())