-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.py
97 lines (70 loc) · 2.88 KB
/
structs.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
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
from sqlalchemy import (Column, Integer, String, DateTime,
ForeignKey, PrimaryKeyConstraint, Float)
from sqlalchemy.orm import declarative_base, relationship
Base = declarative_base()
class Profile(Base):
"""
Represents a user profile in the database.
Attributes:
id (int): The primary key of the profile.
name (str): The name of the profile.
colour (str): The colour associated with the profile.
avatar (str): The avatar URL of the profile.
"""
__tablename__ = 'profiles'
id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
colour = Column(String)
avatar = Column(String)
def __repr__(self):
return f'<Profile {self.id}, {self.name}, {self.colour}>'
class Record(Base):
"""
Represents a record of a profile's activity in the database.
Attributes:
id (int): The ID of the profile associated with this record.
timestamp (datetime): The timestamp of the record.
value (int): The value associated with the record.
profile (Profile): The profile associated with this record.
"""
__tablename__ = 'records'
id = Column(Integer, ForeignKey('profiles.id'), nullable=False)
timestamp = Column(DateTime, nullable=False)
value = Column(Integer, nullable=False)
__table_args__ = (
PrimaryKeyConstraint('id', 'timestamp'),
)
# Relationship to Profile
profile = relationship('Profile', back_populates='records')
def __repr__(self):
return f'<Record {self.id}, {self.timestamp}, {self.value}>'
Profile.records = relationship(
'Record', order_by=Record.timestamp, back_populates='profile')
class Minecraft(Base):
"""
Represents a Minecraft user associated with a Discord profile in the database.
Attributes:
discord_id (int): The Discord ID of the user.
mc_uuid (str): The Minecraft UUID of the user.
mc_name (str): The Minecraft name of the user.
profile (Profile): The profile associated with this Minecraft user.
"""
__tablename__ = 'minecraft'
discord_id = Column(Integer, ForeignKey('profiles.id'), primary_key=True, nullable=False)
mc_uuid = Column(String, nullable=False, unique=True)
mc_name = Column(String)
# Relationship to Profile
profile = relationship('Profile', back_populates='minecraft')
def __repr__(self):
return f'<Minecraft {self.discord_id}, {self.mc_uuid}, {self.mc_name}>'
Profile.minecraft = relationship('Minecraft', back_populates='profile')
class Event(Base):
"""
"""
__tablename__ = 'events'
id = Column(Integer, primary_key=True, autoincrement=True)
start_time = Column(DateTime, nullable=False)
end_time = Column(DateTime)
multiplier = Column(Float)
def __repr__(self):
return f'<Event {self.id}, {self.start_time}, {self.end_time}, {self.multiplier}>'