diff options
| author | Karan Jayachandra <karan.jayachandra@nxp.com> | 2024-10-16 23:28:46 +0200 |
|---|---|---|
| committer | Karan Jayachandra <karan.jayachandra@nxp.com> | 2024-10-16 23:28:46 +0200 |
| commit | 156056e9c31468564fb53ca284996a5de41471fb (patch) | |
| tree | d7cf9efc12e0fb411de3f9b33ac2f478cb29133b /model.py | |
| parent | 74480cbe2b335fd141cdf5f07bb08808c0d08692 (diff) | |
Working version with all functionality
Diffstat (limited to 'model.py')
| -rw-r--r-- | model.py | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -1,6 +1,7 @@ from math import floor from csv import reader from typing import Tuple +from time import time, strftime from dataclasses import dataclass MIN_LEVEL = 1 @@ -101,3 +102,35 @@ class PlayerList: } players.update(guests) return players + + +@dataclass +class Timer: + ref: float = None + running: bool = False + max_mins: int = 1 + default: str = ("00", "00") + + def __post_init__(self): + self.max_seconds = self.max_mins * 60 + + def start(self): + self.ref = time() + self.max_seconds + self.running = True + + def stop(self): + self.ref = None + self.running = False + + def get(self): + if not self.running: + return self.default + total_seconds = self.ref - time() + if total_seconds < 0: + self.stop() + return self.default + mins = f"{int(total_seconds // 60):02d}" + secs = f"{int(total_seconds % 60):02d}" + print(mins) + print(secs) + return mins, secs |
