Newer
Older
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#
# Aura Engine API (https://gitlab.servus.at/aura/engine-api)
#
# Copyright (C) 2020 - The Aura Engine Team.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import datetime
from sqlalchemy import create_engine, Column, DateTime, String, Integer, Boolean
from src.server import db, ma
class PlayLog(db.Model):
"""
Table holding play-log entries.
"""
__tablename__ = 'playlog'
# Primary Key
track_start = Column(DateTime, primary_key=True)
# Columns
track_artist = Column(String(256))
track_album = Column(String(256))
track_title = Column(String(256))
track_duration = Column(String(256))
track_type = Column(Integer)
schedule_id = Column(Integer)
schedule_start = Column(DateTime)
schedule_end = Column(DateTime)
schedule_repetition = Column(Boolean)
schedule_playlist_id = Column(Integer)
schedule_fallback_type = Column(Integer)
show_id = Column(Integer)
schedule_repetition = Column(Boolean)
schedule_playlist_id = Column(Integer)
schedule_fallback_type = Column(Integer)
show_id = Column(Integer)
show_name = Column(String(256))
show_funding_category = Column(String(256))
show_name = Column(String(256))
show_type = Column(String(256))
show_category = Column(String(256))
show_topic = Column(String(256))
def __init__(self):
"""
Initializes a trackservice entry
"""
pass
@staticmethod
def select_current():
"""
Selects the currently playing track.
"""
db.session.commit()
now = datetime.datetime.now()
track = db.session.query(PlayLog).\
filter(PlayLog.track_start <= str(now)).\
order_by(PlayLog.track_start.desc()).first()
return track
@staticmethod
def select_last_hours(n):
"""
Selects the tracks playing in the past (`n`) hours.
"""
db.session.commit()
last_hours = datetime.datetime.today() - datetime.timedelta(hours=n)
tracks = db.session.query(PlayLog).filter(PlayLog.track_start >= str(last_hours)).all()
return tracks
@staticmethod
def select_by_day(day):
"""
Select the track-service items for a day.
"""
db.session.commit()
day_plus_one = day + datetime.timedelta(days=1)
tracks = db.session.query(PlayLog).\
filter(PlayLog.track_start >= str(day), PlayLog.track_start < str(day_plus_one)).\
order_by(PlayLog.track_start.desc()).all()
return tracks
@staticmethod
def select_by_range(from_day, to_day):
"""
Selects the track-service items for a day range.
"""
db.session.commit()
tracks = db.session.query(PlayLog).filter(PlayLog.track_start >= str(from_day),\
PlayLog.track_start < str(to_day)).all()
return tracks
def __str__(self):
return "Track [track_start: %s, track_title: %s]" % (str(self.track_start), str(self.track_title))
class PlayLogSchema(ma.SQLAlchemyAutoSchema):
"""
Schema for playlog entries.
"""
class Meta:
model = PlayLog
sqla_session = db.session
class TrackServiceSchema(ma.SQLAlchemySchema):
"""
Schema for trackservice entries.
"""
class Meta:
model = PlayLog
sqla_session = db.session
fields = (
"track_start",
"track_artist",
"track_album",
"track_title"
)
# Create Tables
db.create_all()