-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
71 lines (51 loc) · 1.61 KB
/
game.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
import db
import model
import util
from datetime import datetime
class Game(model.Model):
@classmethod
def from_id(cls, game_id):
return cls(db.game_from_id(game_id))
@classmethod
def games_for_week(cls, week):
return map(cls, db.games_for_week(week))
@property
def result(self):
if '_result' not in dir(self):
self._result = GameResult.for_game_id(self.game_id)
return self._result
@property
def game_id(self):
return self.mongo_document['game_id']
@property
def home_team(self):
return util.teams[self.mongo_document['home_team']]
@property
def away_team(self):
return util.teams[self.mongo_document['away_team']]
@property
def home_score(self):
return self.mongo_document['home_score']
@property
def away_score(self):
return self.mongo_document['away_score']
@property
def home_spread(self):
return self.mongo_document['home_spread']
@property
def away_spread(self):
return self.mongo_document['away_spread']
@property
def game_time(self):
return self.mongo_document['game_time']
@property
def time_left(self):
return self.mongo_document['time_left']
def started(self):
return datetime.now() >= self.mongo_document['game_time']
def update_score(self, away_score, home_score, time_left):
db.update_score(self.game_id, away_score, home_score, time_left)
class GameResult(model.Model):
@classmethod
def for_game_id(cls, game_id):
return cls(db.game_result_from_id(game_id))