|
| 1 | +from datetime import timedelta |
1 | 2 | import logging |
2 | 3 |
|
3 | 4 | from sqlalchemy.orm import Session |
@@ -58,7 +59,8 @@ def handle_event(self, event: LogEvent, session: Session, statsParticipant: Stat |
58 | 59 | assert isinstance(event, ChronoEvent) |
59 | 60 | self.event_chrono(statsParticipant, player, event) |
60 | 61 | case StartSessionEvent.__tablename__: |
61 | | - pass |
| 62 | + assert isinstance(event, StartSessionEvent) |
| 63 | + self.event_start_session(statsParticipant, event) |
62 | 64 | case SkillAssessmentEvent.__tablename__: |
63 | 65 | pass |
64 | 66 | case QualiEvent.__tablename__: |
@@ -204,6 +206,33 @@ def event_chrono(self, |
204 | 206 | raise LogValidationError(f'Unknown timer type "{event.timerType}"') |
205 | 207 |
|
206 | 208 |
|
| 209 | + def event_start_session(self, |
| 210 | + statsParticipant: StatsParticipant, |
| 211 | + event: StartSessionEvent |
| 212 | + ): |
| 213 | + assert event.timeClient is not None |
| 214 | + assert event.phase is not None |
| 215 | + |
| 216 | + # No need to set the page reload flag, if this is the first launch |
| 217 | + if not statsParticipant.game_started: |
| 218 | + statsParticipant.game_started = True |
| 219 | + statsParticipant.start_time = event.timeClient |
| 220 | + return |
| 221 | + |
| 222 | + # Otherwise at this point this must be a page reload |
| 223 | + statsParticipant.activePhase.reloaded = True |
| 224 | + levelName = '' |
| 225 | + |
| 226 | + if isinstance(statsParticipant.activePhase, StatsPhaseLevels): |
| 227 | + statsParticipant.activePhase.activeLevel.reloaded = True |
| 228 | + levelName = '@' + statsParticipant.activePhase.activeLevel.log_name |
| 229 | + |
| 230 | + ui = getShortPseudo(statsParticipant.pseudonym) |
| 231 | + reload_location = statsParticipant.activePhase.phaseType + levelName |
| 232 | + logging.warning(f'Participant {ui} reloaded the page at "{reload_location}"') |
| 233 | + statsParticipant.reloads.append(reload_location) |
| 234 | + |
| 235 | + |
207 | 236 | def event_quali(self, |
208 | 237 | statsParticipant: StatsParticipant, |
209 | 238 | event: QualiEvent |
@@ -321,24 +350,14 @@ def start_phase(self, event: ChronoEvent, statsParticipant: StatsParticipant): |
321 | 350 | assert event.timeClient is not None |
322 | 351 | assert event.phase is not None |
323 | 352 |
|
324 | | - # Set the reload flag on page reload for phase and if applicable, also level |
| 353 | + # Preload events follow directly after event_start_session |
325 | 354 | if event.phase.activePhase == PhaseType.Preload: |
326 | | - # No need to set the page reload flag, if this is the first launch |
327 | | - if not statsParticipant.game_started: |
328 | | - statsParticipant.game_started = True |
329 | | - return |
330 | | - |
331 | | - statsParticipant.activePhase.reloaded = True |
332 | | - levelName = '' |
333 | | - |
334 | | - if isinstance(statsParticipant.activePhase, StatsPhaseLevels): |
335 | | - statsParticipant.activePhase.activeLevel.reloaded = True |
336 | | - levelName = '@' + statsParticipant.activePhase.activeLevel.log_name |
337 | | - |
338 | | - ui = getShortPseudo(statsParticipant.pseudonym) |
339 | | - reload_location = statsParticipant.activePhase.phaseType + levelName |
340 | | - logging.warning(f'Participant {ui} reloaded the page at "{reload_location}"') |
341 | | - statsParticipant.reloads.append(reload_location) |
| 355 | + if not statsParticipant.game_started or statsParticipant.start_time is None: |
| 356 | + raise LogValidationError('Preload Scene must follow directly after an event_start_phase') |
| 357 | + |
| 358 | + # The Preload event contains the time limit |
| 359 | + if event.limit is not None: |
| 360 | + statsParticipant.time_limit = timedelta(seconds=event.limit) |
342 | 361 |
|
343 | 362 | # If this is not a preload phase, start the phase as usual |
344 | 363 | else: |
|
0 commit comments