Skip to content

Commit acb46fe

Browse files
version v.0.0.18.7
setting null rewards to Nothing x 0
1 parent adac5fa commit acb46fe

File tree

5 files changed

+70
-25
lines changed

5 files changed

+70
-25
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ classifiers = [
2222
keywords=['helldivers2','api']
2323
requires-python = ">=3.8.1"
2424

25-
version = '0.0.1.18.6'
25+
version = '0.0.1.18.7'
2626
dependencies= [
2727
"pydantic>=2.9.2",
2828
"httpx>=0.27.2"

src/hd2api/builders/assignment_builder.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def build_assignment_2(assignment: Assignment) -> Assignment2:
2626
amount=reward.amount,
2727
id32=reward.id32,
2828
)
29+
else:
30+
set_reward = Reward2(
31+
retrieved_at=assignment.retrieved_at,
32+
type=0,
33+
amount=0,
34+
id32=000,
35+
)
2936
ret = Assignment2(
3037
retrieved_at=assignment.retrieved_at,
3138
id=assignment.id32,

src/hd2api/models/Planet.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ def calculate_timeval(self, change: float, is_positive: bool) -> datetime.dateti
231231

232232
def format_estimated_time_string(self, change: float, esttime: datetime.datetime):
233233
change_str = f"{round(change, 5)}"
234-
timeval_str = f"Est.Loss {fdt(esttime,'R')}" if change > 0 else f"{fdt(esttime,'R')}"
234+
timeval_str = (
235+
f"Est.Loss {fdt(esttime,'R')}" if change > 0 else f"{fdt(esttime,'R')}"
236+
)
235237

236238
return f"`[{change_str} dps]`, {timeval_str}"
237239

@@ -275,7 +277,8 @@ def average(planets_list: List["Planet"]) -> "Planet":
275277
return Planet()
276278

277279
avg_health = (
278-
sum(planet.health for planet in planets_list if planet.health is not None) // count
280+
sum(planet.health for planet in planets_list if planet.health is not None)
281+
// count
279282
)
280283

281284
stats = []
@@ -357,9 +360,7 @@ def simple_planet_view(
357360
faction = emj(self.currentOwner.lower())
358361

359362
name = f"{faction}P#{self.index}: {self.name}"
360-
players = (
361-
f"{emj('hdi')}: `{self.statistics.playerCount} {cfi(diff.statistics.playerCount)}`"
362-
)
363+
players = f"{emj('hdi')}: `{self.statistics.playerCount} {cfi(diff.statistics.playerCount)}`"
363364
outlist = [f"{players}"]
364365
if (not self.event) or show_hp_without_event:
365366
outlist.append(
@@ -384,6 +385,8 @@ def simple_planet_view(
384385
outlist.append(f"Deadline: [{timev}]")
385386
if avg:
386387
if avg.event:
387-
outlist.append(f"{self.event.estimate_remaining_lib_time(avg.event)}")
388+
outlist.append(
389+
f"{self.event.estimate_remaining_lib_time(avg.event)}"
390+
)
388391

389392
return name, outlist

src/hd2api/models/Reward2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ class Reward2(BaseApiModel):
3636
def format(self):
3737
"""Return the string representation of any reward."""
3838
type = self.type
39+
3940
if self.id32 in rewards:
4041
type = rewards[self.id32]
42+
if type == 0:
43+
return f"Nothing × 0"
4144
if type == 1:
4245
return f"{emj('medal')} × {self.amount}"
4346
if type == 2:

src/hd2api/models/Statistics.py

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def __sub__(self, other: "Statistics") -> "Statistics":
111111
deaths=(self.deaths or 0) - (other.deaths or 0),
112112
revives=(self.revives or 0) - (other.revives or 0),
113113
friendlies=(self.friendlies or 0) - (other.friendlies or 0),
114-
missionSuccessRate=(self.missionSuccessRate or 0) - (other.missionSuccessRate or 0),
114+
missionSuccessRate=(self.missionSuccessRate or 0)
115+
- (other.missionSuccessRate or 0),
115116
accuracy=(self.accuracy or 0) - (other.accuracy or 0),
116117
playerCount=(self.playerCount or 0) - (other.playerCount or 0),
117118
time_delta=self.retrieved_at - other.retrieved_at, # type: ignore
@@ -137,47 +138,73 @@ def average(stats_list: List["Statistics"]) -> "Statistics":
137138
// count
138139
)
139140
avg_stats = Statistics(
140-
missionsWon=sum(stat.missionsWon for stat in stats_list if stat.missionsWon is not None)
141+
missionsWon=sum(
142+
stat.missionsWon for stat in stats_list if stat.missionsWon is not None
143+
)
141144
// count,
142145
missionsLost=sum(
143-
stat.missionsLost for stat in stats_list if stat.missionsLost is not None
146+
stat.missionsLost
147+
for stat in stats_list
148+
if stat.missionsLost is not None
144149
)
145150
// count,
146-
missionTime=sum(stat.missionTime for stat in stats_list if stat.missionTime is not None)
151+
missionTime=sum(
152+
stat.missionTime for stat in stats_list if stat.missionTime is not None
153+
)
147154
// count,
148155
terminidKills=sum(
149-
stat.terminidKills for stat in stats_list if stat.terminidKills is not None
156+
stat.terminidKills
157+
for stat in stats_list
158+
if stat.terminidKills is not None
150159
)
151160
// count,
152161
automatonKills=sum(
153-
stat.automatonKills for stat in stats_list if stat.automatonKills is not None
162+
stat.automatonKills
163+
for stat in stats_list
164+
if stat.automatonKills is not None
154165
)
155166
// count,
156167
illuminateKills=sum(
157-
stat.illuminateKills for stat in stats_list if stat.illuminateKills is not None
168+
stat.illuminateKills
169+
for stat in stats_list
170+
if stat.illuminateKills is not None
158171
)
159172
// count,
160173
bulletsFired=sum(
161-
stat.bulletsFired for stat in stats_list if stat.bulletsFired is not None
174+
stat.bulletsFired
175+
for stat in stats_list
176+
if stat.bulletsFired is not None
177+
)
178+
// count,
179+
bulletsHit=sum(
180+
stat.bulletsHit for stat in stats_list if stat.bulletsHit is not None
181+
)
182+
// count,
183+
timePlayed=sum(
184+
stat.timePlayed for stat in stats_list if stat.timePlayed is not None
162185
)
163186
// count,
164-
bulletsHit=sum(stat.bulletsHit for stat in stats_list if stat.bulletsHit is not None)
187+
deaths=sum(stat.deaths for stat in stats_list if stat.deaths is not None)
165188
// count,
166-
timePlayed=sum(stat.timePlayed for stat in stats_list if stat.timePlayed is not None)
189+
revives=sum(stat.revives for stat in stats_list if stat.revives is not None)
167190
// count,
168-
deaths=sum(stat.deaths for stat in stats_list if stat.deaths is not None) // count,
169-
revives=sum(stat.revives for stat in stats_list if stat.revives is not None) // count,
170-
friendlies=sum(stat.friendlies for stat in stats_list if stat.friendlies is not None)
191+
friendlies=sum(
192+
stat.friendlies for stat in stats_list if stat.friendlies is not None
193+
)
171194
// count,
172195
missionSuccessRate=sum(
173196
stat.missionSuccessRate
174197
for stat in stats_list
175198
if stat.missionSuccessRate is not None
176199
)
177200
// count,
178-
accuracy=sum(stat.accuracy for stat in stats_list if stat.accuracy is not None)
201+
accuracy=sum(
202+
stat.accuracy for stat in stats_list if stat.accuracy is not None
203+
)
179204
// count,
180-
playerCount=sum(stat.playerCount for stat in stats_list if stat.playerCount is not None)
205+
playerCount=sum(
206+
stat.playerCount for stat in stats_list if stat.playerCount is not None
207+
)
181208
// count,
182209
time_delta=datetime.timedelta(seconds=avg_time),
183210
)
@@ -201,18 +228,23 @@ def format_statistics(self) -> str:
201228
# f"I: {hf(self.illuminateKills)}"
202229

203230
# Format deaths and friendlies statistics
204-
deaths_and_friendlies = f"Deaths/Friendlies: {hf(self.deaths)}/" f"{hf(self.friendlies)}"
231+
deaths_and_friendlies = (
232+
f"Deaths/Friendlies: {hf(self.deaths)}/" f"{hf(self.friendlies)}"
233+
)
205234

206235
# Format player count
207236
player_count = f"{emj('hdi')}: {hf(self.playerCount)}"
208237
thistime = round(
209-
max(self.missionTime, 1) / max(((self.missionsWon or 0) + (self.missionsLost or 0)), 1),
238+
max(self.missionTime, 1)
239+
/ max(((self.missionsWon or 0) + (self.missionsLost or 0)), 1),
210240
4,
211241
) # type: ignore
212242

213243
mission_stats += f"\n Time per mission: {sts(thistime)}"
214244
# Concatenate all formatted statistics
215-
statsa = f"`[Missions: {mission_stats}]`\n`[{missiontime}]`\n`[Kills: {kill_stats}]`"
245+
statsa = (
246+
f"`[Missions: {mission_stats}]`\n`[{missiontime}]`\n`[Kills: {kill_stats}]`"
247+
)
216248
statsb = f"`[{deaths_and_friendlies}]`"
217249
statsc = f"`Total Time: {sts(self.timePlayed)}`"
218250
return f"{player_count}\n{statsa}\n{statsb}\n{statsc}"

0 commit comments

Comments
 (0)