Skip to content

Commit 4cc80ee

Browse files
committed
move bf1 blaze
1 parent b435965 commit 4cc80ee

File tree

1 file changed

+187
-0
lines changed
  • global_mapping/readability

1 file changed

+187
-0
lines changed

global_mapping/readability/bf1.py

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import asyncio
2+
import datetime
3+
from global_mapping.readability.shared import format_percentage_value
4+
from global_mapping import bf1 as BF1
5+
6+
7+
async def get_weapons(stats_dict: dict, format_values: bool = True):
8+
weapons = []
9+
for _id, extra in BF1.WEAPONS_STATS.items():
10+
weapon: dict[str, str | int | float] = {**extra}
11+
12+
kills = stats_dict.get(f"{_id}__kw_g", 0)
13+
shots_hit = stats_dict.get(f"{_id}__shw_g", 0)
14+
shots_fired = stats_dict.get(f"{_id}__sfw_g", 0)
15+
headshots = stats_dict.get(f"{_id.replace('_', '__')}_hsh_g", 0)
16+
seconds = stats_dict.get(f"{_id}__sw_g", 0)
17+
18+
try:
19+
accuracy = round((shots_hit / shots_fired) * 100, 2)
20+
except ZeroDivisionError:
21+
accuracy = 0.0
22+
23+
try:
24+
kills_per_minute = round(kills / (seconds / 60), 2)
25+
except (ZeroDivisionError, KeyError):
26+
kills_per_minute = 0.0
27+
28+
try:
29+
hits_per_kill = round(shots_hit / kills, 2)
30+
except ZeroDivisionError:
31+
hits_per_kill = 0.0
32+
33+
try:
34+
headshot_rate = round((headshots / kills) * 100, 2)
35+
except ZeroDivisionError:
36+
headshot_rate = 0.0
37+
38+
weapon["id"] = _id
39+
weapon["kills"] = kills
40+
weapon["accuracy"] = format_percentage_value(accuracy, format_values)
41+
weapon["headshots"] = headshots
42+
weapon["headshot_rate"] = format_percentage_value(headshot_rate, format_values)
43+
weapon["killsPerMinute"] = kills_per_minute
44+
weapon["hitVKills"] = hits_per_kill
45+
weapon["shotsHit"] = shots_hit
46+
weapon["shotsFired"] = shots_fired
47+
weapon["timeEquipped"] = seconds
48+
weapons.append(weapon)
49+
return weapons
50+
51+
52+
async def get_gamemodes(stats_dict: dict, format_values: bool = False):
53+
gamemodes = []
54+
for _id, extra in BF1.STATS_GAMEMODE.items():
55+
wins = stats_dict.get(f"c_mwin_{_id}", 0)
56+
losses = stats_dict.get(f"c_mlos_{_id}", 0)
57+
# try:
58+
# win_percent = round(wins / (wins + losses) * 100, 2)
59+
# except ZeroDivisionError:
60+
# win_percent = 0.0
61+
62+
gamemode: dict[str, str | int | float] = {**extra}
63+
gamemode["id"] = _id
64+
# gamemode["wins"] = wins
65+
# gamemode["losses"] = losses
66+
gamemode["score"] = stats_dict.get(BF1.GAMEMODE_SCORE.get(_id, ""), 0)
67+
# gamemode["winPercent"] = format_percentage_value(win_percent, format_values)
68+
gamemodes.append(gamemode)
69+
return gamemodes
70+
71+
72+
async def get_classes(stats_dict: dict):
73+
kits = []
74+
for kit_id, extra in BF1.STATS_CLASSES.items():
75+
kills = stats_dict.get(f"{kit_id}_ks_g", 0)
76+
# deaths = stats_dict.get(f"deaths_char_{kit_id}", 0)
77+
seconds = stats_dict.get(f"{kit_id}_sa_g", 0)
78+
# try:
79+
# kill_death = round(kills / deaths, 2)
80+
# except ZeroDivisionError:
81+
# kill_death = 0.0
82+
try:
83+
kills_per_minute = round(kills / (seconds / 60), 2)
84+
except (ZeroDivisionError, KeyError):
85+
kills_per_minute = 0.0
86+
kit: dict[str, str | int | float] = {**extra}
87+
kit["id"] = kit_id
88+
kit["kills"] = kills
89+
kit["kpm"] = kills_per_minute
90+
kit["secondsPlayed"] = seconds
91+
kit["score"] = stats_dict.get(BF1.CLASSES_SCORE.get(kit_id, ""), 0)
92+
kit["image"] = (
93+
f"https://cdn.gametools.network/classes/bf1/white/{kit['className']}.png"
94+
)
95+
kit["altImage"] = (
96+
f"https://cdn.gametools.network/classes/bf1/black/{kit['className']}.png"
97+
)
98+
kit["timePlayed"] = str(datetime.timedelta(seconds=kit["secondsPlayed"]))
99+
kits.append(kit)
100+
return kits
101+
102+
103+
async def get_main_stats(stats_dict: dict, format_values: bool = True):
104+
result: dict[str, str | int | float] = {}
105+
wins = stats_dict.get("c_mwin__roo_g", 0)
106+
losses = stats_dict.get("c_mlos__roo_g", 0)
107+
kills = stats_dict.get("c___k_g", 0)
108+
deaths = stats_dict.get("c___d_g", 0)
109+
shots_fired = stats_dict.get("c___sfw_g", 0)
110+
shots_hit = stats_dict.get("c___shw_g", 0)
111+
headshot_amount = stats_dict.get("c___hsh_g", 0)
112+
matches_played = stats_dict.get("c___roo_g", 0)
113+
try:
114+
accuracy = round((shots_hit / shots_fired) * 100, 2)
115+
except ZeroDivisionError:
116+
accuracy = 0.0
117+
try:
118+
win_percent = round(wins / (wins + losses) * 100, 2)
119+
except ZeroDivisionError:
120+
win_percent = 0.0
121+
try:
122+
headshots = round((headshot_amount / kills) * 100, 2)
123+
except ZeroDivisionError:
124+
headshots = 0.0
125+
try:
126+
kill_death = round(kills / deaths, 2)
127+
except ZeroDivisionError:
128+
kill_death = 0.0
129+
130+
try:
131+
kills_per_match = round(kills / matches_played, 2)
132+
except (ZeroDivisionError, KeyError):
133+
kills_per_match = 0.0
134+
135+
result["kills"] = kills
136+
result["deaths"] = deaths
137+
result["wins"] = wins
138+
result["loses"] = losses
139+
result["killsPerMatch"] = kills_per_match
140+
result["headShots"] = headshot_amount
141+
result["roundsPlayed"] = matches_played
142+
result["winPercent"] = format_percentage_value(win_percent, format_values)
143+
result["headshots"] = format_percentage_value(headshots, format_values)
144+
result["accuracy"] = format_percentage_value(accuracy, format_values)
145+
result["killDeath"] = kill_death
146+
result["score"] = stats_dict.get("score", 0)
147+
result["revives"] = stats_dict.get("c___re_g", 0)
148+
result["heals"] = stats_dict.get("c___h_g", 0)
149+
result["repairs"] = stats_dict.get("c___r_g", 0)
150+
result["killAssists"] = stats_dict.get("c___kak_g", 0)
151+
result["shotsHit"] = shots_hit
152+
result["shotsFired"] = shots_fired
153+
result["awardScore"] = stats_dict.get("sc_award", 0)
154+
result["bonusScore"] = stats_dict.get("sc_bonus", 0)
155+
result["squadScore"] = stats_dict.get("sc_squad", 0)
156+
result["currentRankProgress"] = stats_dict.get("sc_rank", 0)
157+
result["highestKillStreak"] = stats_dict.get("c___k_ghvs", 0)
158+
result["dogtagsTaken"] = stats_dict.get("c___dt_g", 0)
159+
result["longestHeadShot"] = stats_dict.get("c___hsd_ghva", 0)
160+
return result
161+
162+
163+
async def get_stats_bf1_blaze(
164+
data: dict, format_values: bool = True, with_extras: bool = True
165+
):
166+
result = {}
167+
for player_name, stats in data.items():
168+
int_stats = {}
169+
current_result = {}
170+
for key, value in stats.items():
171+
int_stats[key] = float(value)
172+
173+
if with_extras:
174+
tasks = []
175+
tasks.append(get_weapons(int_stats, format_values))
176+
tasks.append(get_gamemodes(int_stats, format_values))
177+
tasks.append(get_classes(int_stats))
178+
(
179+
current_result["weapons"],
180+
current_result["gamemodes"],
181+
current_result["classes"],
182+
) = await asyncio.gather(*tasks)
183+
184+
current_result.update(await get_main_stats(int_stats, format_values))
185+
186+
result[player_name] = current_result
187+
return result

0 commit comments

Comments
 (0)