broadcasts.py 24.1 KB
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
#
#  engine
#
#  Playout Daemon for autoradio project
#
#
#  Copyright (C) 2017-2018 Gottfried Gaisbauer <gottfried.gaisbauer@servus.at>
#
#  This file is part of engine.
#
#  engine is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  any later version.
#
#  engine 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 General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with engine. If not, see <http://www.gnu.org/licenses/>.
#
24

25
import sys
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
26
import time
27
28
import logging
import datetime
29

30
from sqlalchemy import orm, func, BigInteger, Boolean, Column, DateTime, Integer, String, ForeignKey, ForeignKeyConstraint
31
from sqlalchemy.orm import relationship
32
from sqlalchemy.sql.expression import false, true
33
34
35
36

from sqlalchemy.orm import relationship
from sqlalchemy import create_engine

37
from libraries.enum.auraenumerations import ScheduleEntryType
38
from aura import DB
39

40

41
42

class AuraDatabaseModel():
43
44
45
46
47
    logger = None

    def __init__(self):
        self.logger = logging.getLogger("AuraEngine")

48
49
    def store(self, add=False, commit=False):
        if add:
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
50
            DB.session.add(self)
51
        if commit:
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
52
            DB.session.commit()
53
54

    def delete(self, commit=False):
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
55
        DB.session.delete(self)
56
57
58
59
#        current_db_sessions = DB.session.object_session(self)
#        current_db_sessions.delete(self)
#        return
#        DB.session.delete(self)
60
        if commit:
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
61
            DB.session.commit()
62

63
64
    def _asdict(self):
        return self.__dict__
65

66
67
    @staticmethod
    def recreate_db(systemexit = False):
68
69
        manualschedule = Schedule()
        manualschedule.schedule_id = 0
70
        manualschedule.show_name = "Manual Show"
71

72
#        self.logger.debug("Recreating Database...")
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
73
        DB.drop_all()
74
#        self.logger.debug("all dropped. creating...")
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
75
        DB.create_all()
76
#        self.logger.debug("inserting manual scheduling possibility and fallback trackservice schedule")
77
#        DB.session.add(manualschedule)
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
78
#        db.session.add(fallback_trackservice_schedule)
79
#        self.logger.debug("all created. commiting...")
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
80
        DB.session.commit()
81
#        self.logger.debug("Database recreated!")
82

83
84
        if systemexit:
            sys.exit(0)
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
151
152
153
154
155
156
157
158
159
160
161
162
# ------------------------------------------------------------------------------------------ #
# class Schedule(DB.Model, AuraDatabaseModel):
#     """
#     One specific Schedule for a show on a timeslot
#     """
#     __tablename__ = 'schedule'
#
#     # primary and foreign keys
#     schedule_start = Column(DateTime, primary_key=True)
#
#     schedule_end = Column(DateTime)
#     schedule_id = Column(Integer) #, primary_key=True, autoincrement=False)
#     show_id = Column(Integer)  # well, in fact not needed..
#     show_name = Column(String(256))
#     show_hosts = Column(String(256))
#     funding_category = Column(String(256))
#     comment = Column(String(512))
#     languages = Column(String(256))
#     type = Column(String(256))
#     category = Column(String(256))
#     topic = Column(String(256))
#     musicfocus = Column(String(256))
#
#     is_repetition = Column(Boolean())
#
#     playlist_id = Column(Integer, ForeignKey("playlist.playlist_id"))
#     timeslot_fallback_id = Column(Integer)
#     show_fallback_id = Column(Integer)
#     station_fallback_id = Column(Integer)
#
#     playlist = relationship("Playlist", foreign_keys=[playlist_id], lazy="joined")
#  #    timeslot_fallback = relationship("Playlist", foreign_keys=[timeslot_fallback_id], lazy="joined")
#  #    show_fallback = relationship("Playlist", foreign_keys=[show_fallback_id], lazy="joined")
#  #    station_fallback = relationship("Playlist", foreign_keys=[station_fallback_id], lazy="joined")
#
#     @staticmethod
#     def select_all():
#          # fetching all entries
#         all_entries = DB.session.query(Schedule).filter().order_by(Schedule.schedule_start).all()
#         return all_entries
#
#     @staticmethod
#     def select_by_id(id):
#         entry = DB.session.query(Schedule).filter(Schedule.schedule_id == id).first()
#         return entry
#     @staticmethod
#     def select_act_programme():
#          #DB.session.query(Schedule).filter
#          # fetching all from today to ..
#         today = datetime.date.today()
#         all_entries = DB.session.query(Schedule).filter(Schedule.schedule_start >= today).order_by(Schedule.schedule_start).all()
#
#         return all_entries
#

#
#     @staticmethod
#     def drop_the_future(timedelta):
#         then = datetime.datetime.now() + timedelta
#
#         # is this really necessary?
#         future_entries = DB.session.query(Schedule).filter(Schedule.schedule_start > then)
#         for e in future_entries:
#             e.delete()
#         DB.session.commit()
#
#     def get_length(self):
#         sec1 = int(datetime.datetime.strptime(self.start[0:16].replace(" ", "T"), "%Y-%m-%dT%H:%M").strftime("%s"))
#         sec2 = int(datetime.datetime.strptime(self.end[0:16].replace(" ", "T"), "%Y-%m-%dT%H:%M").strftime("%s"))
#         len = sec2 - sec1
#         return len
#
#     # ------------------------------------------------------------------------------------------ #
#     def __str__(self):
#         return "ScheduleID: #" + str(self.schedule_id) + " Showname: " + self.show_name + " starts @ " + str(self.schedule_start)

163
# ------------------------------------------------------------------------------------------ #
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
164
class Schedule(DB.Model, AuraDatabaseModel):
165
    """
166
    One specific Schedule for a show on a timeslot
167
    """
168
    __tablename__ = 'schedule'
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
169
170

    # primary and foreign keys
171
    schedule_start = Column(DateTime, primary_key=True)
172

173
174
175
    schedule_end = Column(DateTime)
    schedule_id = Column(Integer) #, primary_key=True, autoincrement=False)
    show_id = Column(Integer)  # well, in fact not needed..
176
177
    show_name = Column(String(256))
    show_hosts = Column(String(256))
178
    funding_category = Column(String(256))
179
180
181
182
183
184
    comment = Column(String(512))
    languages = Column(String(256))
    type = Column(String(256))
    category = Column(String(256))
    topic = Column(String(256))
    musicfocus = Column(String(256))
185
186
187

    is_repetition = Column(Boolean())

188
    playlist_id = Column(Integer) #, ForeignKey("playlist.playlist_id"))
189
190
191
192
    timeslot_fallback_id = Column(Integer)
    show_fallback_id = Column(Integer)
    station_fallback_id = Column(Integer)

193
194
195
196
197
198
199
200
201
202
203
204
    playlist = relationship("Playlist",
                            primaryjoin="and_(Schedule.schedule_start==Playlist.schedule_start, Schedule.playlist_id==Playlist.playlist_id, Schedule.show_name==Playlist.show_name)",
                            back_populates="schedule")
    timeslot_fallback = relationship("Playlist",
                            primaryjoin="and_(Schedule.schedule_start==Playlist.schedule_start, Schedule.timeslot_fallback_id==Playlist.playlist_id, Schedule.show_name==Playlist.show_name)",
                            back_populates="schedule")
    show_fallback = relationship("Playlist",
                            primaryjoin="and_(Schedule.schedule_start==Playlist.schedule_start, Schedule.show_fallback_id==Playlist.playlist_id, Schedule.show_name==Playlist.show_name)",
                            back_populates="schedule")
    station_fallback = relationship("Playlist",
                            primaryjoin="and_(Schedule.schedule_start==Playlist.schedule_start, Schedule.station_fallback_id==Playlist.playlist_id, Schedule.show_name==Playlist.show_name)",
                            back_populates="schedule")
205
206
207
208
209

    @staticmethod
    def select_show_on_datetime(datetime):
        return DB.session.query(Schedule).filter(Schedule.schedule_start == datetime).first()

210
211
212
213
214
215
216
217
218
    @staticmethod
    def select_act_programme():
        #DB.session.query(Schedule).filter
        # fetching all from today to ..
        today = datetime.date.today()
        all_entries = DB.session.query(Schedule).filter(Schedule.schedule_start >= today).order_by(Schedule.schedule_start).all()

        return all_entries

219
# ------------------------------------------------------------------------------------------ #
220
221
222
223
224
225
226
227
228
229
230
231
232
233
class Playlist(DB.Model, AuraDatabaseModel):
    __tablename__ = 'playlist'

    # pk,fk
    artificial_id = Column(Integer, primary_key=True)
    schedule_start = Column(DateTime, ForeignKey("schedule.schedule_start"))
    # relationships
    schedule = relationship("Schedule", uselist=False, back_populates="playlist")
    entries = relationship("PlaylistEntry", back_populates="playlist")
    # data
    playlist_id = Column(Integer, autoincrement=False)  # , ForeignKey("schedule.playlist_id"))
    show_name = Column(String(256))
    fallback_type = Column(Integer)
    entry_count = Column(Integer)
234

235
236
    @staticmethod
    def select_all():
237
        # fetching all entries
238
        all_entries = DB.session.query(Playlist).filter(Playlist.fallback_type == 0).all()
239
240
241
242
243
244
245
246

        cnt = 0
        for entry in all_entries:
            entry.programme_index = cnt
            cnt = cnt + 1

        return all_entries

247
    @staticmethod
248
249
    def select_playlist_for_schedule(datetime, playlist_id):
        return DB.session.query(Playlist).filter(Playlist.schedule_start == datetime, Playlist.playlist_id == playlist_id).first()
250

251

252
253
254
# ------------------------------------------------------------------------------------------ #
class PlaylistEntry(DB.Model, AuraDatabaseModel):
    __tablename__ = 'playlist_entry'
255

256
257
    # primary keys
    artificial_id = Column(Integer, primary_key=True)
258

259
260
261
    # foreign keys
    artificial_playlist_id = Column(Integer, ForeignKey("playlist.artificial_id"))
    entry_num = Column(Integer) # , primary_key=True)
262

263
264
265
    uri = Column(String(1024))
    duration = Column(BigInteger)
    filename = Column(String(1024))
266

267
268
269
    # relationships
    playlist = relationship("Playlist", uselist=False, back_populates="entries")
    meta_data = relationship("PlaylistEntryMetaData", back_populates="entry")
270

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
271
    @staticmethod
272
273
    def select_playlistentry_for_playlist(artificial_playlist_id, entry_num):
        return DB.session.query(PlaylistEntry).filter(PlaylistEntry.artificial_playlist_id == artificial_playlist_id, PlaylistEntry.entry_num == entry_num).first()
274

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
275

276
277
class PlaylistEntryMetaData(DB.Model, AuraDatabaseModel):
    __tablename__ = "playlist_entry_metadata"
278

279
280
    artificial_id = Column(Integer, primary_key=True)
    artificial_entry_id = Column(Integer, ForeignKey("playlist_entry.artificial_id"))
281

282
283
284
    artist = Column(String(256))
    title = Column(String(256))
    album = Column(String(256))
285

286
    entry = relationship("PlaylistEntry", uselist=False, back_populates="meta_data")
287

288
289
290
    @staticmethod
    def select_metadata_for_entry(artificial_playlistentry_id):
        return DB.session.query(PlaylistEntry).filter(PlaylistEntryMetaData.artificial_entry_id == artificial_playlistentry_id).first()
291

292

293
# ------------------------------------------------------------------------------------------ #
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
#class PlaylistEntry(DB.Model, AuraDatabaseModel):
    # __tablename__ = 'playlist_entry'
    #
    # # primary and foreign keys
    # playlist_id = Column(Integer, ForeignKey("playlist.playlist_id"), primary_key=True, nullable=False, autoincrement=True)
    # entry_num = Column(Integer, primary_key=True, nullable=False, autoincrement=False)
    #
    # uri = Column(String(1024))
    #
    # filename = ""
    # cleansource = ""
    # cleanprotocol = ""
    # type = None
    # fadeintimer = None
    # fadeouttimer = None
    # switchtimer = None
    #
    # meta_data = relationship("PlaylistEntryMetaData", primaryjoin="and_(PlaylistEntry.playlist_id==PlaylistEntryMetaData.playlist_id, PlaylistEntry.entry_num==PlaylistEntryMetaData.entry_num)", lazy="joined")
    #
    # # normal constructor
    # def __init__(self, **kwargs):
    #     super(PlaylistEntry, self).__init__(**kwargs)
    #     self.calc_unix_times()
    #     self.define_clean_source()
    #
    # # constructor like - called from sqlalchemy
    # @orm.reconstructor
    # def reconstructor(self):
    #     self.calc_unix_times()
    #     self.define_clean_source()
    #     self.set_entry_type()
    #
    # def define_clean_source(self):
    #     if self.uri is None:
    #         return None
    #
    #     if self.uri.startswith("http"):
    #         self.cleanprotocol = self.uri[:7]
    #         self.cleansource = self.uri
    #
    #     elif self.uri.startswith("linein"):
    #         self.cleanprotocol = self.uri[:9]
    #         self.cleansource = self.uri[9:]
    #
    #     elif self.uri.startswith("pool") or self.uri.startswith("file") or self.uri.startswith("live"):
    #         self.cleanprotocol = self.uri[:7]
    #         self.cleansource = self.uri[7:]
    #
    #     elif self.uri.startswith("playlist"):
    #         self.cleanprotocol = self.uri[:11]
    #         self.cleansource = self.uri[11:]
    #
    #     else:
    #         self.logger.error("Unknown source protocol")
    #
    # def set_entry_type(self):
    #     if self.uri.startswith("http"):
    #         self.type = ScheduleEntryType.STREAM
    #     if self.uri.startswith("pool") or self.uri.startswith("playlist") or self.uri.startswith("file"):
    #         self.type = ScheduleEntryType.FILESYSTEM
    #     if self.uri.startswith("live") or self.uri.startswith("linein"):
    #         if self.cleansource == "0":
    #             self.type = ScheduleEntryType.LIVE_0
    #         elif self.cleansource == "1":
    #             self.type = ScheduleEntryType.LIVE_1
    #         elif self.cleansource == "2":
    #             self.type = ScheduleEntryType.LIVE_2
    #         elif self.cleansource == "3":
    #             self.type = ScheduleEntryType.LIVE_3
    #         elif self.cleansource == "4":
    #             self.type = ScheduleEntryType.LIVE_4




    # def calc_unix_times(self):
    #     if self.entry_start is not None:
    #         self.entry_start_unix = time.mktime(self.entry_start.timetuple())
    #
    #
    #
    # # ------------------------------------------------------------------------------------------ #
    # @staticmethod
    # def select_all():
    #     # fetching all entries
    #     all_entries = DB.session.query(Playlist).filter(Playlist.fallback_type == 0).order_by(Playlist.entry_start).all()
    #
    #     cnt = 0
    #     for entry in all_entries:
    #         entry.programme_index = cnt
    #         cnt = cnt + 1
    #
    #     return all_entries
    #
    # @staticmethod
    # def select_act_programme(include_act_playing = True):
    #     # fetching all from today to ..
    #     today = datetime.date.today()
    #     all_entries = DB.session.query(Playlist).filter(Playlist.entry_start >= today, Playlist.fallback_type == 0).order_by(Playlist.entry_start).all()
    #
    #     cnt = 0
    #     for entry in all_entries:
    #         entry.programme_index = cnt
    #         cnt = cnt + 1
    #
    #     return all_entries
    #
    # # ------------------------------------------------------------------------------------------ #
    # @staticmethod
    # def truncate():
    #     all_entries = DB.session.query(Playlist).filter().order_by(Playlist.entry_start).all()
    #
    #     for a in all_entries:
    #         a.delete()
    #     DB.session.commit()
    #
    # # ------------------------------------------------------------------------------------------ #
    # @staticmethod
    # def select_next_manual_entry_num():
    #
    #     max_manual_entry_num = DB.session.query(func.max(Playlist.entry_num)).filter(Playlist.schedule_id == 0).first()
    #
    #     if max_manual_entry_num[0] is None:
    #         return 0
    #     else:
    #         return int(max_manual_entry_num[0])+1
    #
    # # ------------------------------------------------------------------------------------------ #
    # @staticmethod
    # def select_upcoming(datefrom=datetime.datetime.now()):
    #     upcomingtracks = DB.session.query(Playlist).filter(Playlist.entry_start > datefrom).order_by(Playlist.entry_start).all()
    #     return upcomingtracks
    #
    # # ------------------------------------------------------------------------------------------ #
    # @staticmethod
    # def select_one(playlist_id, entry_num):
    #     return DB.session.query(Playlist).filter(Playlist.playlist_id == playlist_id, Playlist.entry_num == entry_num).first()
    #
    # # ------------------------------------------------------------------------------------------ #
    # @staticmethod
    # def select_one_playlist_entry_for_show(schedule_id, playlist_type, entry_num):
    #     return DB.session.query(Playlist).filter(Playlist.schedule_id == schedule_id, Playlist.fallback_type == playlist_type, Playlist.entry_num == entry_num).first()
    #
    # # ------------------------------------------------------------------------------------------ #
    # @staticmethod
    # def select_playlist(playlist_id):
    #     return DB.session.query(Playlist).filter(Playlist.playlist_id == playlist_id).order_by(Playlist.entry_start).all()
    #
    # @staticmethod
    # def drop_the_future(timedelta):
    #     then = datetime.datetime.now() + timedelta
    #     #DB.session.delete(ScheduleEntry).filter(ScheduleEntry.entry_start >= then)
    #
    #     # is this really necessary?
    #     future_entries = DB.session.query(Playlist).filter(Playlist.entry_start > then)
    #     for e in future_entries:
    #         e.delete()
    #     DB.session.commit()
    #
    # def getChannel(self):
    #     if self.type == self.type.FILESYSTEM:
    #         return "fs"
    #
    #     if self.type == self.type.LIVE_0 or self.type == self.type.LIVE_1 or self.type == self.type.LIVE_2 or self.type == self.type.LIVE_3 or self.type == self.type.LIVE_4:
    #         return "aura_linein_"+self.cleansource # .cleanprotocol[8]
    #
    #     if self.type == self.type.STREAM:
    #         return "http"
    #
    #
    # # ------------------------------------------------------------------------------------------ #
    # def __str__(self):
    #     return "Showentry starts @ " + str(self.entry_start) + " and plays " + self.source


# class ScheduleEntryFile(DB.Model, AuraDatabaseModel):
#     __tablename__ = 'schedule_entry_file'
#
#     # primary and foreign keys
#     file_id = Column(Integer, primary_key=True, nullable=False, autoincrement=False)
#     playlist_id = Column(Integer) #, ForeignKey("schedule_entry.playlist_id")) # primary_key=True, nullable=False, autoincrement=False)
#     entry_num = Column(Integer) # , ForeignKey("schedule_entry.entry_num")) # primary_key=True, nullable=False, autoincrement=False)
#
#     ForeignKeyConstraint(["playlist_id", "entry_num"], ["schedule_entry.playlist_id", "schedule_entry.entry_num"])
#
#     show = Column(String(512))
#     size = Column(Integer)
#     duration = Column(Integer)
#
# class ScheduleEntryFileMetaData(DB.Model, AuraDatabaseModel):
#     __tablename__ = "schedule_entry_file_metadata"
#
#     metadata_id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
#     file_id = Column(Integer, ForeignKey("schedule_entry_file.file_id"))
#
#     artist = Column(String(256))
#     title = Column(String(256))
#     album = Column(String(256))
#
# # ------------------------------------------------------------------------------------------ #
# class TrackService(DB.Model, AuraDatabaseModel):
#     __tablename__ = 'trackservice'
#
#     trackservice_id = Column(Integer, primary_key=True, autoincrement=True)
#     schedule_entry_id = Column(Integer, ForeignKey("schedule_entry.id"))
#     playlist_id = Column(Integer, nullable=False)
#     entry_num = Column(Integer, nullable=False)
#
#     source = Column(String(255), nullable=False)
#     start = Column(DateTime, nullable=False, default=func.now())
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
504

505
506
507
508
#    __table_args__ = (
#        ForeignKeyConstraint(['playlist_id', 'entry_num'], ['schedule_entry.playlist_id', 'schedule_entry.entry_num']),
#    )
#    schedule_entry = relationship("ScheduleEntry", primaryjoin="and_(TrackService.playlist_id==ScheduleEntry.playlist_id, TrackService.entry_num==ScheduleEntry.entry_num)", lazy="joined")
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
509

510
    #schedule = relationship("Schedule", foreign_keys=[schedule_id], lazy="joined")
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
511
    # trackservice_entry = relationship("ScheduleEntry", foreign_keys=[playlist_id, entry_num], lazy="joined")
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
    # schedule_entry = relationship("ScheduleEntry", primaryjoin="and_(TrackService.schedule_entry_id==ScheduleEntry.id)", lazy="joined")
    #
    # @staticmethod
    # # ------------------------------------------------------------------------------------------ #
    # def select_one(trackservice_id):
    #     return DB.session.query(TrackService).filter(TrackService.trackservice_id == trackservice_id).first()
    #
    # @staticmethod
    # # ------------------------------------------------------------------------------------------ #
    # def select_by_day(day):
    #     day_plus_one = day + datetime.timedelta(days=1)
    #     tracks = DB.session.query(TrackService).filter(TrackService.start >= str(day), TrackService.start < str(day_plus_one)).all()
    #     return tracks
    #
    # @staticmethod
    # # ------------------------------------------------------------------------------------------ #
    # def select_by_range(from_day, to_day):
    #     tracks = DB.session.query(TrackService).filter(TrackService.start >= str(from_day),
    #                                                    TrackService.start < str(to_day)).all()
    #     return tracks
    #
    # # ------------------------------------------------------------------------------------------ #
    # def __str__(self):
    #     return "TrackServiceID: #" + str(self.trackservice_id) + " playlist_id: " + str(self.playlist_id) + " started @ " + str(self.start) + " and played " + self.source
Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
536

Gottfried Gaisbauer's avatar
Gottfried Gaisbauer committed
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# ------------------------------------------------------------------------------------------ #
# class TrackServiceSchedule(db.Model, AuraDatabaseModel):
#     """
#     Trackservice is tracking every schedule.
#     """
#     __tablename__ = 'trackservice_schedule'
#
#     # primary and foreign keys
#     ts_schedule_id = Column(Integer, primary_key=True, autoincrement=True)
#     schedule_id = Column(Integer, ForeignKey("schedule.schedule_id"))
#
#     schedule = relationship("Schedule", foreign_keys=[schedule_id], lazy="joined")
#
#     # ------------------------------------------------------------------------------------------ #
#     @staticmethod
#     def select_one(schedule_id):
#         # damn BAND-AID
#         # db.session.commit()
#
#         return db.session.query(ScheduleEntry).filter(TrackServiceSchedule.schedule_id == schedule_id).first()
#
# # ------------------------------------------------------------------------------------------ #
# class TrackServiceScheduleEntry(db.Model, AuraDatabaseModel):
#     """
#     And a schedule can have multiple entries
#     """
#     __tablename__ = 'trackservice_entry'
#
#     # primary and foreign keys. the foreign keys here can be null, because of fallback stuff
#     ts_entry_id = Column(Integer, primary_key=True, autoincrement=True)
#     ts_schedule_id = Column(Integer, ForeignKey("trackservice_schedule.ts_schedule_id"), nullable=True)
#     playlist_id = Column(Integer, nullable=True)
#     entry_num = Column(Integer, nullable=True)
#
#     fallback = Column(Boolean, default=False)
#     fallback_start = Column(DateTime, nullable=True, default=None)
#     source = Column(String(256), nullable=True, default=None)
#
#     # foreign key definitions
#     __table_args__ = (
#         ForeignKeyConstraint(['playlist_id', 'entry_num'], ['schedule_entry.playlist_id', 'schedule_entry.entry_num']),
#     )
#
#     trackservice_schedule = relationship("TrackServiceSchedule", foreign_keys=[ts_schedule_id], lazy="joined")
#     #trackservice_entry = relationship("ScheduleEntry", foreign_keys=[playlist_id, entry_num], lazy="joined")
#     trackservice_entry = relationship("ScheduleEntry", primaryjoin="and_(TrackServiceScheduleEntry.playlist_id==ScheduleEntry.playlist_id, TrackServiceScheduleEntry.entry_num==ScheduleEntry.entry_num)" , lazy="joined")
#
#     @staticmethod
#     def select_all():
#         return db.session.query(TrackServiceScheduleEntry).filter().all()

588
# AuraDatabaseModel.recreate_db(systemexit=True)