Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
engine
Commits
fcd23698
Commit
fcd23698
authored
1 year ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
refactor: cleanup
parent
c0e8e7cc
No related branches found
No related tags found
1 merge request
!35
ORM-less scheduling
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/aura_engine/scheduling/programme.py
+0
-349
0 additions, 349 deletions
src/aura_engine/scheduling/programme.py
with
0 additions
and
349 deletions
src/aura_engine/scheduling/programme.py
+
0
−
349
View file @
fcd23698
...
...
@@ -202,32 +202,6 @@ class TimetableService:
return
current_timeslot
# def get_current_playlist(self, timeslot):
# """
# Retrieve the playlist to be scheduled.
# If no playlist is specifically assigned to the timeslot, then the first it is checked,
# if some default schedule playlist is available. If yes, this one is returned. As a last
# resort it checks if a show playlist is available.
# This method does not respect any defined default playlists.
# Returns:
# (dict, Playlist): A dictionary holding the playlist type, the currently assigned
# playlist
# """
# playlist_type = Playlist.TYPE_TIMESLOT
# playlist = timeslot.playlist
# if not playlist:
# playlist_type = Playlist.TYPE_SCHEDULE
# playlist = timeslot.default_schedule_playlist
# if not playlist:
# playlist_type = Playlist.TYPE_SHOW
# playlist = timeslot.default_show_playlist
# return (playlist_type, playlist)
def
get_next_timeslots
(
self
,
max_count
:
int
=
0
)
->
[
Timeslot
]:
"""
Retrieve the timeslots to be played after the current one.
...
...
@@ -346,54 +320,6 @@ class TimetableMerger:
if
not
idx
.
get
(
"
local
"
):
idx
[
"
local
"
]
=
""
return
timeslot_map
# self.m3u_processor = M3UPlaylistProcessor()
# def load_timeslots(self):
# """
# Load the programme from the database.
# """
# timeslots = None
# try:
# timeslots = Timeslot.get_timeslots(datetime.now())
# except Exception as e:
# self.logger.critical(
# SU.red("Could not load programme from database. \
# We are in big trouble my friend!"),
# e,
# )
# return timeslots
# def store_timeslots(self, fetched_timeslots):
# """
# Store the fetched timeslots to the database.
# """
# timeslots = []
# # Check if existing timeslots have been deleted
# self.update_deleted_timeslots(fetched_timeslots)
# # Process fetched timeslots
# for timeslot in fetched_timeslots:
# # Store the timeslot
# timeslot_db = self.store_timeslot(timeslot)
# timeslots.append(timeslot_db)
# # Store assigned playlists
# self.store_playlist(timeslot_db, timeslot_db.playlist_id, timeslot["playlist"])
# if timeslot_db.default_schedule_playlist_id:
# self.store_playlist(
# timeslot_db,
# timeslot_db.default_schedule_playlist_id,
# timeslot["default_schedule_playlist"],
# )
# if timeslot_db.default_show_playlist_id:
# self.store_playlist(
# timeslot_db,
# timeslot_db.default_show_playlist_id,
# timeslot["default_show_playlist"],
# )
# return timeslots
def
merge
(
self
,
local_timeslots
:
[
Timeslot
],
remote_timeslots
:
[
Timeslot
])
->
[
Timeslot
]:
"""
...
...
@@ -444,278 +370,3 @@ class TimetableMerger:
self
.
logger
.
debug
(
f
"
\t
TIME:
{
timestamp
}
-
{
local
}
|
{
remote
}
↦ (
{
resolution
}
)
"
)
return
merged_ts
# def remove_deleted_timeslots(
# self, local_timeslots: [Timeslot], remote_timeslots: [Timeslot]
# ) -> [Timeslot]:
# """
# Check if some timeslot has been deleted remotely, so delete it locally too.
# Attention: This method has no effect if only a single existing timeslot got
# deleted, i.e. zero timeslots got returned, because this could simply indicate
# an issue with the API/Steering, since that means no data got retrieved. This
# should not be a problem in real life scenarios though, as there's practically
# always something in the timetable.
# 2. Add any timeslots valid to be scheduled, which are existing remotely, but not
# yet locally.
# Args:
# local_timeslots ([Timeslot]): List of local timeslots.
# remote_timeslots ([Timeslot]): List of remote timeslots.
# Returns:
# [Timeslot]: The reduced list of timeslots.
# """
# now = SU.timestamp()
# scheduling_window_start = self.config.get("scheduling_window_start")
# ts_to_delete: [Timeslot] = []
# if not local_timeslots:
# local_timeslots = []
# for local_timeslot in local_timeslots:
# # Ignore timeslots which started already
# if local_timeslot.get_start() > now:
# # Filter the local timeslot from the fetched ones
# existing_remotely = list(
# filter(
# lambda new_timeslot: new_timeslot.get_id() == local_timeslot.get_id(),
# remote_timeslots,
# )
# )
# if not existing_remotely:
# # Only allow deletion of timeslots which are deleted before the start of the
# # scheduling window
# if (local_timeslot.get_start() - scheduling_window_start) > now:
# msg = f"Timeslot #{local_timeslot.get_id()} has been deleted remotely,\
# going to delete it locally too"
# self.logger.info(msg)
# ts_to_delete.append(local_timeslot)
# else:
# msg = (
# f"Timeslot #{local_timeslot.get_id()} has been deleted remotely."
# f" Since the scheduling window has already started, it won't be"
# f" deleted locally."
# )
# self.logger.warn(SU.red(msg))
# for del_ts in ts_to_delete:
# self.logger.info(f"Delete timeslot #{del_ts.get_id()} locally")
# local_timeslots.remove(del_ts)
# return local_timeslots
# def add_new_timeslots(
# self, local_timeslots: [Timeslot], remote_timeslots: [Timeslot]
# ) -> [Timeslot]:
# pass
# def store_timeslot(self, timeslot):
# """
# Store the given timeslot to the database.
# Args:
# timeslot (Timeslot): The timeslot
# """
# timeslot_start = SU.to_datetime(timeslot["start"])
# timeslot_db = Timeslot.for_datetime(timeslot_start)
# havetoadd = False
# if not timeslot_db:
# self.logger.debug("no timeslot with given timeslot id in database => create new")
# timeslot_db = Timeslot()
# havetoadd = True
# timeslot_db.show_id = timeslot["showId"]
# timeslot_db.timeslot_id = timeslot["timeslot_id"]
# timeslot_db.timeslot_start = SU.to_datetime(timeslot["start"])
# timeslot_db.timeslot_end = SU.to_datetime(timeslot["end"])
# timeslot_db.show_name = timeslot["showName"]
# timeslot_db.show_hosts = timeslot["showHosts"]
# timeslot_db.repetition_of_id = timeslot["repetitionOfId"]
# timeslot_db.funding_category = timeslot["showFundingCategory"]
# timeslot_db.languages = timeslot["showLanguages"]
# timeslot_db.type = timeslot["showType"]
# timeslot_db.category = timeslot["showCategories"]
# timeslot_db.topic = timeslot["showTopics"]
# timeslot_db.musicfocus = timeslot["showMusicFocus"]
# timeslot_db.playlist_id = timeslot["playlist_id"]
# # Optional API properties
# if "default_schedule_playlistId" in timeslot:
# timeslot_db.default_schedule_playlist_id = timeslot["default_schedule_playlist_id"]
# if "default_show_playlist_id" in timeslot:
# timeslot_db.default_show_playlist_id = timeslot["default_show_playlist_id"]
# msg = f"Store/Update TIMESLOT havetoadd={havetoadd} - data: {timeslot}"
# self.logger.debug(SU.pink(msg))
# timeslot_db.store(add=havetoadd, commit=True)
# return timeslot_db
# def store_playlist(self, timeslot_db, playlist_id, fetched_playlist):
# """
# Store the Playlist to the database.
# """
# if not playlist_id or not fetched_playlist:
# self.logger.debug(f"Playlist ID#{playlist_id} is not available!")
# return
# playlist_db = Playlist.select_playlist_for_timeslot(
# timeslot_db.timeslot_start, playlist_id
# )
# havetoadd = False
# if not playlist_db:
# playlist_db = Playlist()
# havetoadd = True
# self.logger.debug(f"Storing playlist {playlist_id} for timeslot {timeslot_db}")
# playlist_db.playlist_id = playlist_id
# playlist_db.timeslot_start = timeslot_db.timeslot_start
# playlist_db.show_name = timeslot_db.show_name
# if "items" in fetched_playlist:
# playlist_db.item_count = len(fetched_playlist["items"])
# else:
# playlist_db.item_count = 0
# playlist_db.store(havetoadd, commit=True)
# if playlist_db.item_count > 0:
# self.store_playlist_items(timeslot_db, playlist_db, fetched_playlist)
# return playlist_db
# def store_playlist_items(self, timeslot_db, playlist_db, fetched_playlist):
# """
# Store the playlist items to the database.
# """
# item_num = 0
# time_marker = playlist_db.start_unix
# items = fetched_playlist["items"]
# "Hidden Functionality" to feed engine with M3U playlists via Tank's "Stream" playlist
# item type
# See https://gitlab.servus.at/aura/engine/-/issues/53
# In the future this is to be replaced by a generic music pool feature.
# items = self.m3u_processor.spread(items)
# self.expand_item_duration(timeslot_db, items)
# self.delete_orphaned_items(playlist_db, items)
# for item in items:
# item_db = PlaylistItem.select_playlistitem_for_playlist(
# playlist_db.artificial_id, item_num
# )
# havetoadd = False
# if not item_db:
# item_db = PlaylistItem()
# havetoadd = True
# item_db.item_start = datetime.fromtimestamp(time_marker)
# item_db.artificial_playlist_id = playlist_db.artificial_id
# item_db.item_num = item_num
# item_db.duration = SU.nano_to_seconds(item["duration"])
# if "uri" in item:
# item_db.source = item["uri"]
# if "filename" in item:
# item_db.source = item["filename"]
# item_db.store(havetoadd, commit=True)
# if "file" in item:
# self.store_playlist_item_metadata(item_db, item["file"]["metadata"])
# item_num = item_num + 1
# time_marker += item_db.duration
# def delete_orphaned_playlist_items(
# self, local_playlist: Playlist, remote_playlist: Playlist
# ) -> Playlist:
# """
# Delete all playlist items which are beyond the current playlist's `item_count`.
# Such items might be existing due to a remotely changed playlist, which now has
# less items than before.
# """
# new_last_idx = len(items)
# existing_last_idx = PlaylistItem.count_items(playlist_db.artificial_id) - 1
# if existing_last_idx < new_last_idx:
# return
# for item_num in range(new_last_idx, existing_last_idx + 1, 1):
# PlaylistItem.delete_item(playlist_db.artificial_id, item_num)
# msg = f"Deleted playlist item {playlist_db.artificial_id}:{item_num}"
# self.logger.info(SU.yellow(msg))
# item_num += 1
# def expand_item_duration(self, timeslot_db, items):
# """
# Expand item to the timeslot gap left.
# If some playlist item doesn't have a duration assigned, its duration is expanded to the
# remaining duration of the playlist (= timeslot duration minus playlist items with
# duration).
# If there is more than one item without duration, such items are removed from the
# playlist.
# """
# total_seconds = (timeslot_db.timeslot_end - timeslot_db.timeslot_start).total_seconds()
# total_duration = SU.seconds_to_nano(total_seconds)
# actual_duration = 0
# missing_duration = []
# idx = 0
# for item in items:
# if "duration" not in item:
# missing_duration.append(idx)
# else:
# actual_duration += item["duration"]
# idx += 1
# if len(missing_duration) == 1:
# items[missing_duration[0]]["duration"] = total_duration - actual_duration
# self.logger.info(f"Expanded duration of playlist item #{missing_duration[0]}")
# elif len(missing_duration) > 1:
# # This case should actually never happen, as TANK doesn't allow more than one item
# # w/o duration anymore
# for i in reversed(missing_duration[1:-1]):
# msg = f"Deleted Playlist Item without duration: {items[i]}"
# self.logger.error(SU.red(msg))
# del items[i]
# def store_playlist_item_metadata(self, item_db, metadata):
# """
# Store the meta-data for a PlaylistItem.
# """
# metadata_db = PlaylistItemMetaData.select_metadata_for_item(item_db.artificial_id)
# havetoadd = False
# if not metadata_db:
# metadata_db = PlaylistItemMetaData()
# havetoadd = True
# metadata_db.artificial_item_id = item_db.artificial_id
# if "artist" in metadata:
# metadata_db.artist = metadata["artist"]
# else:
# metadata_db.artist = ""
# if "album" in metadata:
# metadata_db.album = metadata["album"]
# else:
# metadata_db.album = ""
# if "title" in metadata:
# metadata_db.title = metadata["title"]
# else:
# metadata_db.title = ""
# metadata_db.store(havetoadd, commit=True)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment