From 5ebf83fcf656d043c19288d2a992ea46b183f51e Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Wed, 25 Nov 2020 13:09:22 +0100 Subject: [PATCH] Differentiation planned_playlist and playlogs. #2 --- src/models.py | 27 ++++++++++---------- src/rest/models/clock_info.py | 34 +++++++++++++------------- src/rest/models/timeslot.py | 4 --- src/rest/swagger/swagger.yaml | 46 +++++++++++++++++++---------------- src/service.py | 4 +-- 5 files changed, 57 insertions(+), 58 deletions(-) diff --git a/src/models.py b/src/models.py index 3a77f53..d3a33cc 100644 --- a/src/models.py +++ b/src/models.py @@ -402,7 +402,7 @@ class ClockInfo(db.Model): # Columns log_time = Column(DateTime) current_track = None # Populated live from within `get_info(..)` - current_playlist = Column(String(4096)) # Stringified "#/components/schemas/Playlist" OpenAPI JSON object + planned_playlist = Column(String(4096)) # Stringified "#/components/schemas/Playlist" OpenAPI JSON object current_timeslot = Column(String(2048)) # Stringified "#/components/schemas/Schedule" OpenAPI JSON object next_timeslot = Column(String(2048)) # Stringified "#/components/schemas/Schedule" OpenAPI JSON object @@ -413,16 +413,16 @@ class ClockInfo(db.Model): """ - def set_info(self, source_number, current_playlist, current_timeslot, next_timeslot): + def set_info(self, source_number, planned_playlist, current_timeslot, next_timeslot): """ Sets the values for a clock info entry. """ self.log_time = datetime.datetime.now() self.log_source = source_number - if current_playlist: - self.current_playlist = json.dumps(current_playlist.to_dict(), default=str) + if planned_playlist: + self.planned_playlist = json.dumps(planned_playlist.to_dict(), default=str) else: - self.current_playlist = None + self.planned_playlist = None if current_timeslot: self.current_timeslot = json.dumps(current_timeslot.to_dict(), default=str) else: @@ -450,7 +450,7 @@ class ClockInfo(db.Model): info = dict() data = db.session.query(ClockInfo).filter(ClockInfo.log_source == source_number).first() current_track = PlayLog.select_current() - current_playlist_id = -1 + planned_playlist_id = -1 playlogs = None # Construct the clock `info` object @@ -463,8 +463,10 @@ class ClockInfo(db.Model): info["current_track"] = track_schema.dump(current_track) # Append the missing planned playlist items to the ones played # FIXME do it client-site - if data.current_playlist: - info["planned_playlist"] = json.loads(data.current_playlist) + if data.planned_playlist: + info["planned_playlist"] = json.loads(data.planned_playlist) + else: + info["planned_playlist"] = {} # Get the current timeslot if data.current_timeslot: @@ -475,15 +477,12 @@ class ClockInfo(db.Model): # Is the most recent track part of the current timeslot? if most_recent_track.timeslot_id == info["current_timeslot"]["timeslot_id"]: - + # Get the actual playlogs of the current timeslot, until now playlog_schema = PlayLogSchema(many=True) playlogs = PlayLog.select_for_timeslot(most_recent_track.timeslot_id) playlogs.sort(key=lambda track: track.track_start, reverse=False) - info["current_playlist"] = { - # "playlist_id": current_playlist_id, - "entries": playlog_schema.dump(playlogs) - } + info["current_playlogs"] = playlog_schema.dump(playlogs) # Invalid timeslots (e.g. in fallback scenarios) get a virtual start date of the first fallback track if info["current_timeslot"]["timeslot_id"] == -1: @@ -521,7 +520,7 @@ class ClockInfoSchema(ma.SQLAlchemySchema): "log_time", "current_track", "planned_playlist", - "current_playlist", + "current_playlogs", "current_timeslot", "next_timeslot" ) \ No newline at end of file diff --git a/src/rest/models/clock_info.py b/src/rest/models/clock_info.py index d70be28..8796e75 100644 --- a/src/rest/models/clock_info.py +++ b/src/rest/models/clock_info.py @@ -17,15 +17,15 @@ class ClockInfo(Model): Do not edit the class manually. """ - def __init__(self, engine_source=None, current_track=None, current_playlist=None, planned_playlist=None, current_timeslot=None, next_timeslot=None): # noqa: E501 + def __init__(self, engine_source=None, current_track=None, current_playlogs=None, planned_playlist=None, current_timeslot=None, next_timeslot=None): # noqa: E501 """ClockInfo - a model defined in Swagger :param engine_source: The engine_source of this ClockInfo. # noqa: E501 :type engine_source: int :param current_track: The current_track of this ClockInfo. # noqa: E501 :type current_track: PlayLog - :param current_playlist: The current_playlist of this ClockInfo. # noqa: E501 - :type current_playlist: Playlist + :param current_playlogs: The current_playlogs of this ClockInfo. # noqa: E501 + :type current_playlogs: List[PlayLog] :param planned_playlist: The planned_playlist of this ClockInfo. # noqa: E501 :type planned_playlist: Playlist :param current_timeslot: The current_timeslot of this ClockInfo. # noqa: E501 @@ -36,7 +36,7 @@ class ClockInfo(Model): self.swagger_types = { 'engine_source': int, 'current_track': PlayLog, - 'current_playlist': Playlist, + 'current_playlogs': List[PlayLog], 'planned_playlist': Playlist, 'current_timeslot': Timeslot, 'next_timeslot': Timeslot @@ -45,14 +45,14 @@ class ClockInfo(Model): self.attribute_map = { 'engine_source': 'engine_source', 'current_track': 'current_track', - 'current_playlist': 'current_playlist', + 'current_playlogs': 'current_playlogs', 'planned_playlist': 'planned_playlist', 'current_timeslot': 'current_timeslot', 'next_timeslot': 'next_timeslot' } self._engine_source = engine_source self._current_track = current_track - self._current_playlist = current_playlist + self._current_playlogs = current_playlogs self._planned_playlist = planned_playlist self._current_timeslot = current_timeslot self._next_timeslot = next_timeslot @@ -111,25 +111,25 @@ class ClockInfo(Model): self._current_track = current_track @property - def current_playlist(self): - """Gets the current_playlist of this ClockInfo. + def current_playlogs(self): + """Gets the current_playlogs of this ClockInfo. - :return: The current_playlist of this ClockInfo. - :rtype: Playlist + :return: The current_playlogs of this ClockInfo. + :rtype: List[PlayLog] """ - return self._current_playlist + return self._current_playlogs - @current_playlist.setter - def current_playlist(self, current_playlist): - """Sets the current_playlist of this ClockInfo. + @current_playlogs.setter + def current_playlogs(self, current_playlogs): + """Sets the current_playlogs of this ClockInfo. - :param current_playlist: The current_playlist of this ClockInfo. - :type current_playlist: Playlist + :param current_playlogs: The current_playlogs of this ClockInfo. + :type current_playlogs: List[PlayLog] """ - self._current_playlist = current_playlist + self._current_playlogs = current_playlogs @property def planned_playlist(self): diff --git a/src/rest/models/timeslot.py b/src/rest/models/timeslot.py index d432ddc..4aea4e3 100644 --- a/src/rest/models/timeslot.py +++ b/src/rest/models/timeslot.py @@ -153,8 +153,6 @@ class Timeslot(Model): :param timeslot_start: The timeslot_start of this Timeslot. :type timeslot_start: datetime """ - if timeslot_start is None: - raise ValueError("Invalid value for `timeslot_start`, must not be `None`") # noqa: E501 self._timeslot_start = timeslot_start @@ -176,8 +174,6 @@ class Timeslot(Model): :param timeslot_end: The timeslot_end of this Timeslot. :type timeslot_end: datetime """ - if timeslot_end is None: - raise ValueError("Invalid value for `timeslot_end`, must not be `None`") # noqa: E501 self._timeslot_end = timeslot_end diff --git a/src/rest/swagger/swagger.yaml b/src/rest/swagger/swagger.yaml index eab4cd1..a847f0c 100644 --- a/src/rest/swagger/swagger.yaml +++ b/src/rest/swagger/swagger.yaml @@ -139,7 +139,7 @@ paths: summary: Set current studio clock information such as timeslot info and track-list for engine 1 or 2 within the Engine API database. description: | - Set current studio clock information (source, timeslot and track-list) and the next timeslot of the given play-out source (engine1, engine2). Please note, the `current_track` information is ignored in the PUT request. It's only dynamically populated in the GET request by reading the most recent playlog. To store current track information use `/playlog` instead. Also note, similar to the `PlayLog` storage endpoint, this information is only stored to the database if a) it is a main node or b) if it's a sync node, and the `engine_source` is the currently active engine. + Set current studio clock information (source, timeslot and planned track-list) and the next timeslot of the given play-out source (engine1, engine2). Please note, the `current_track` and `current_playlogs` information is ignored in the PUT request. It's only dynamically populated in the GET request by reading the most recent playlog. To store current track information use `/playlog` instead. Also note, similar to the `PlayLog` storage endpoint, this information is only stored to the database if a) it is a main node or b) if it's a sync node, and the `engine_source` is the currently active engine. operationId: set_clock_info requestBody: content: @@ -605,8 +605,10 @@ components: example: 1 current_track: $ref: '#/components/schemas/PlayLog' - current_playlist: - $ref: '#/components/schemas/Playlist' + current_playlogs: + type: array + items: + $ref: '#/components/schemas/PlayLog' planned_playlist: $ref: '#/components/schemas/Playlist' current_timeslot: @@ -631,23 +633,9 @@ components: fallback_type: 0 timeslot_start: 2020-08-29T09:12:33.001Z timeslot_id: 23 - current_playlist: - entries: - - track_album: Bricolage - track_start: 2020-08-29T09:12:33.001Z - track_title: Chomp Samba - track_num: 7 - track_artist: Amon Tobin - track_duration: 808 - track_type: 2 - - track_album: Bricolage - track_start: 2020-08-29T09:12:33.001Z - track_title: Chomp Samba - track_num: 7 - track_artist: Amon Tobin - track_duration: 808 - track_type: 2 - playlist_id: 38 + current_playlogs: + - null + - null current_track: track_album: Bricolage show_id: 42 @@ -664,7 +652,23 @@ components: track_duration: 808 custom_json: '{ "custom": "Stringified JSON Object" }' next_timeslot: null - planned_playlist: null + planned_playlist: + entries: + - track_album: Bricolage + track_start: 2020-08-29T09:12:33.001Z + track_title: Chomp Samba + track_num: 7 + track_artist: Amon Tobin + track_duration: 808 + track_type: 2 + - track_album: Bricolage + track_start: 2020-08-29T09:12:33.001Z + track_title: Chomp Samba + track_num: 7 + track_artist: Amon Tobin + track_duration: 808 + track_type: 2 + playlist_id: 38 Timeslot: required: - show_name diff --git a/src/service.py b/src/service.py index 5e57f4f..4890d6e 100644 --- a/src/service.py +++ b/src/service.py @@ -192,7 +192,7 @@ class ApiService(): info = ClockInfo.get_info(self.get_active_source()) now = datetime.datetime.now() - if info["current_timeslot"] and info["current_timeslot"]["timeslot_end"]: + if "current_timeslot" in info and info["current_timeslot"]["timeslot_end"]: timeslot_end = util.deserialize_datetime(info["current_timeslot"]["timeslot_end"]) if timeslot_end < now: info["current_timeslot"] = None @@ -218,7 +218,7 @@ class ApiService(): else: clock_info = ClockInfo() - clock_info.set_info(data.engine_source, data.current_playlist, data.current_timeslot, data.next_timeslot) + clock_info.set_info(data.engine_source, data.planned_playlist, data.current_timeslot, data.next_timeslot) if is_existing: clock_info.update() -- GitLab