-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
100 lines (94 loc) · 3.05 KB
/
game.py
File metadata and controls
100 lines (94 loc) · 3.05 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from bson.objectid import ObjectId
class Game:
"""
A model representing a game.
Attributes:
- `city` The city of the game.
- `date` The date of the game.
- `gender` The gender of the game.
- `location` The location of the game. (optional)
- `opponent_id` The id of the opposing team.
- `result` The result of the game. (optional)
- `sport` The sport of the game.
- `state` The state of the game.
- `time` The time of the game. (optional)
- `box_score` The scoring summary of the game (optional)
- `score_breakdown` The scoring breakdown of the game (optional)
- 'ticket_link' The ticket link for the game (optional)
"""
def __init__(
self,
city,
date,
gender,
opponent_id,
sport,
state,
id=None,
location=None,
result=None,
time=None,
box_score=None,
score_breakdown=None,
team=None,
utc_date=None,
ticket_link=None,
):
self.id = id if id else str(ObjectId())
self.city = city
self.date = date
self.gender = gender
self.location = location
self.opponent_id = opponent_id
self.result = result
self.sport = sport
self.state = state
self.time = time
self.box_score = box_score
self.score_breakdown = score_breakdown
self.team = team
self.utc_date = utc_date
self.ticket_link = ticket_link
def to_dict(self):
"""
Converts the Game object to a dictionary format for MongoDB storage.
"""
return {
"_id": self.id,
"city": self.city,
"date": self.date,
"gender": self.gender,
"location": self.location,
"opponent_id": self.opponent_id,
"result": self.result,
"sport": self.sport,
"state": self.state,
"time": self.time,
"box_score": self.box_score,
"score_breakdown": self.score_breakdown,
"team": self.team,
"utc_date": self.utc_date,
"ticket_link": self.ticket_link,
}
@staticmethod
def from_dict(data) -> None:
"""
Converts a MongoDB document to a Game object.
"""
return Game(
id=data.get("_id"),
city=data.get("city"),
date=data.get("date"),
gender=data.get("gender"),
location=data.get("location"),
opponent_id=data.get("opponent_id"),
result=data.get("result"),
sport=data.get("sport"),
state=data.get("state"),
time=data.get("time"),
box_score=data.get("box_score"),
score_breakdown=data.get("score_breakdown"),
team=data.get("team"),
utc_date=data.get("utc_date"),
ticket_link=data.get("ticket_link"),
)