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
178db3ee
Commit
178db3ee
authored
1 year ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
refact: expand items after fetch
parent
6668881f
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/api.py
+51
-3
51 additions, 3 deletions
src/aura_engine/scheduling/api.py
with
51 additions
and
3 deletions
src/aura_engine/scheduling/api.py
+
51
−
3
View file @
178db3ee
...
@@ -186,8 +186,8 @@ class ApiFetcher(threading.Thread):
...
@@ -186,8 +186,8 @@ class ApiFetcher(threading.Thread):
timeslot
=
Timeslot
(
timeslot
=
Timeslot
(
id
=
api_ts
.
id
,
id
=
api_ts
.
id
,
repetition_id
=
api_ts
.
repetition_of_id
,
repetition_id
=
api_ts
.
repetition_of_id
,
start
=
api_ts
.
start
,
start
=
api_ts
.
start
.
timestamp
()
,
end
=
api_ts
.
end
,
end
=
api_ts
.
end
.
timestamp
()
,
show
=
show
,
show
=
show
,
episode
=
episode
,
episode
=
episode
,
)
)
...
@@ -196,6 +196,9 @@ class ApiFetcher(threading.Thread):
...
@@ -196,6 +196,9 @@ class ApiFetcher(threading.Thread):
playlist_schedule
=
self
.
fetch_playlist
(
api_ts
.
schedule_default_playlist_id
)
playlist_schedule
=
self
.
fetch_playlist
(
api_ts
.
schedule_default_playlist_id
)
playlist_show
=
self
.
fetch_playlist
(
api_ts
.
show_default_playlist_id
)
playlist_show
=
self
.
fetch_playlist
(
api_ts
.
show_default_playlist_id
)
timeslot
.
set_playlists
(
playlist_timeslot
,
playlist_schedule
,
playlist_show
)
timeslot
.
set_playlists
(
playlist_timeslot
,
playlist_schedule
,
playlist_show
)
self
.
expand_item_duration
(
playlist_timeslot
)
self
.
expand_item_duration
(
playlist_schedule
)
self
.
expand_item_duration
(
playlist_show
)
timeslots
.
append
(
timeslot
)
timeslots
.
append
(
timeslot
)
return
timeslots
return
timeslots
...
@@ -234,7 +237,13 @@ class ApiFetcher(threading.Thread):
...
@@ -234,7 +237,13 @@ class ApiFetcher(threading.Thread):
title
=
entry
.
file
.
metadata
.
title
,
title
=
entry
.
file
.
metadata
.
title
,
)
)
item
=
PlaylistItem
(
entry
.
uri
,
entry
.
duration
,
100
,
metadata
)
# Convert nanoseconds to seconds
# TODO remove after tank is using seconds for duration
duration
:
float
=
None
if
entry
.
duration
:
duration
=
SU
.
nano_to_seconds
(
entry
.
duration
)
item
=
PlaylistItem
(
entry
.
uri
,
duration
,
100
,
metadata
)
# "Hidden Functionality" to feed engine with M3U playlists
# "Hidden Functionality" to feed engine with M3U playlists
# via Tank's "Stream" playlist item type
# via Tank's "Stream" playlist item type
...
@@ -250,6 +259,45 @@ class ApiFetcher(threading.Thread):
...
@@ -250,6 +259,45 @@ class ApiFetcher(threading.Thread):
return
playlist
return
playlist
@private
def
expand_item_duration
(
self
,
playlist
:
Playlist
):
"""
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.
Args:
playlist (Playlist): the playlist with items to expand.
@private
"""
timeslot_duration
:
float
=
playlist
.
get_timeslot
().
get_duration
()
playlist_duration
:
float
=
0.0
items_wo_duration
:
list
(
PlaylistItem
)
=
[]
for
item
in
playlist
.
get_items
():
if
not
item
.
duration
:
items_wo_duration
.
append
(
item
)
else
:
playlist_duration
+=
item
.
duration
if
len
(
items_wo_duration
)
==
1
:
items_wo_duration
[
0
].
duration
=
timeslot_duration
-
playlist_duration
self
.
logger
.
info
(
f
"
Expand duration for playlist item #
{
items_wo_duration
[
0
]
}
"
)
elif
len
(
items_wo_duration
)
>
1
:
# This case should actually never happen, as Tank does not allow more than one item w/o
# duration anymore
for
item
in
reversed
(
items_wo_duration
[
1
:
-
1
]):
msg
=
f
"
Delete playlist item without duration:
{
item
}
"
self
.
logger
.
error
(
SU
.
red
(
msg
))
item
.
remove
()
@private
@private
def
is_valid_timeslot
(
self
,
timeslot
:
API_TIMESLOT
)
->
bool
:
def
is_valid_timeslot
(
self
,
timeslot
:
API_TIMESLOT
)
->
bool
:
"""
"""
...
...
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