Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine-api
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-api
Commits
e469e930
Commit
e469e930
authored
3 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Handle 'None' duration.
parent
f6374a10
No related branches found
No related tags found
No related merge requests found
Pipeline
#1143
passed
3 years ago
Stage: bundle
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/models.py
+27
-25
27 additions, 25 deletions
src/models.py
with
27 additions
and
25 deletions
src/models.py
+
27
−
25
View file @
e469e930
...
@@ -50,7 +50,7 @@ class PlayLog(db.Model):
...
@@ -50,7 +50,7 @@ class PlayLog(db.Model):
playlist_id
=
Column
(
Integer
)
playlist_id
=
Column
(
Integer
)
timeslot_id
=
Column
(
Integer
)
timeslot_id
=
Column
(
Integer
)
show_id
=
Column
(
Integer
)
show_id
=
Column
(
Integer
)
show_name
=
Column
(
String
(
256
))
show_name
=
Column
(
String
(
256
))
log_source
=
Column
(
Integer
)
# The play-out source which this log is coming from (e.g. engine1, engine2)
log_source
=
Column
(
Integer
)
# The play-out source which this log is coming from (e.g. engine1, engine2)
is_synced
=
Column
(
Boolean
)
# Only relevant for main nodes, in a multi-node setup
is_synced
=
Column
(
Boolean
)
# Only relevant for main nodes, in a multi-node setup
...
@@ -71,8 +71,10 @@ class PlayLog(db.Model):
...
@@ -71,8 +71,10 @@ class PlayLog(db.Model):
self
.
timeslot_id
=
data
.
timeslot_id
self
.
timeslot_id
=
data
.
timeslot_id
self
.
show_id
=
data
.
show_id
self
.
show_id
=
data
.
show_id
self
.
show_name
=
data
.
show_name
self
.
show_name
=
data
.
show_name
self
.
log_source
=
data
.
log_source
self
.
log_source
=
data
.
log_source
self
.
is_synced
=
False
self
.
is_synced
=
False
if
not
self
.
track_duration
:
self
.
track_duration
=
0
def
save
(
self
):
def
save
(
self
):
...
@@ -99,13 +101,13 @@ class PlayLog(db.Model):
...
@@ -99,13 +101,13 @@ class PlayLog(db.Model):
"""
"""
db
.
session
.
commit
()
db
.
session
.
commit
()
now
=
datetime
.
datetime
.
now
()
now
=
datetime
.
datetime
.
now
()
track
=
db
.
session
.
query
(
PlayLog
).
\
track
=
db
.
session
.
query
(
PlayLog
).
\
order_by
(
PlayLog
.
track_start
.
desc
()).
\
order_by
(
PlayLog
.
track_start
.
desc
()).
\
filter
(
PlayLog
.
track_start
<=
str
(
now
)).
first
()
filter
(
PlayLog
.
track_start
<=
str
(
now
)).
first
()
return
track
return
track
@staticmethod
@staticmethod
...
@@ -115,18 +117,18 @@ class PlayLog(db.Model):
...
@@ -115,18 +117,18 @@ class PlayLog(db.Model):
"""
"""
db
.
session
.
commit
()
db
.
session
.
commit
()
now
=
datetime
.
datetime
.
now
()
now
=
datetime
.
datetime
.
now
()
track
=
PlayLog
.
select_recent
()
track
=
PlayLog
.
select_recent
()
if
track
:
# Preferably only get playlogs which are known for still being on air
if
track
.
track_start
+
datetime
.
timedelta
(
0
,
track
.
track_duration
)
>
now
:
return
track
if
track
:
# Station fallback may not provide a duration. Take this one, it's better than nothing.
# Station fallback may not provide a duration. Take this one, it's better than nothing.
if
track
.
track_duration
==
0
:
if
track
.
track_duration
==
0
:
return
track
return
track
# Preferably only get playlogs which are known for still being on air
if
track
.
track_start
+
datetime
.
timedelta
(
0
,
track
.
track_duration
)
>
now
:
return
track
return
None
return
None
...
@@ -160,7 +162,7 @@ class PlayLog(db.Model):
...
@@ -160,7 +162,7 @@ class PlayLog(db.Model):
order_by
(
PlayLog
.
track_start
.
desc
()).
\
order_by
(
PlayLog
.
track_start
.
desc
()).
\
filter
(
PlayLog
.
timeslot_id
==
timeslot_id
)
filter
(
PlayLog
.
timeslot_id
==
timeslot_id
)
playlogs
=
result
.
all
()
playlogs
=
result
.
all
()
return
playlogs
return
playlogs
...
@@ -174,7 +176,7 @@ class PlayLog(db.Model):
...
@@ -174,7 +176,7 @@ class PlayLog(db.Model):
if
not
to_time
:
if
not
to_time
:
to_time
=
datetime
.
datetime
.
now
()
to_time
=
datetime
.
datetime
.
now
()
def
q
(
page
=
0
,
page_size
=
None
):
def
q
(
page
=
0
,
page_size
=
None
):
query
=
db
.
session
.
query
(
PlayLog
).
order_by
(
PlayLog
.
track_start
.
desc
())
query
=
db
.
session
.
query
(
PlayLog
).
order_by
(
PlayLog
.
track_start
.
desc
())
if
isinstance
(
from_time
,
datetime
.
datetime
):
if
isinstance
(
from_time
,
datetime
.
datetime
):
query
=
query
.
filter
(
PlayLog
.
track_start
>=
from_time
.
isoformat
(
'
'
,
'
seconds
'
))
query
=
query
.
filter
(
PlayLog
.
track_start
>=
from_time
.
isoformat
(
'
'
,
'
seconds
'
))
...
@@ -221,7 +223,7 @@ class PlayLog(db.Model):
...
@@ -221,7 +223,7 @@ class PlayLog(db.Model):
filter
(
PlayLog
.
track_start
>=
str
(
day
),
PlayLog
.
track_start
<
str
(
day_plus_one
)).
\
filter
(
PlayLog
.
track_start
>=
str
(
day
),
PlayLog
.
track_start
<
str
(
day_plus_one
)).
\
order_by
(
PlayLog
.
track_start
.
desc
()).
all
()
order_by
(
PlayLog
.
track_start
.
desc
()).
all
()
return
tracks
return
tracks
@staticmethod
@staticmethod
def
select_by_range
(
from_day
,
to_day
):
def
select_by_range
(
from_day
,
to_day
):
...
@@ -398,7 +400,7 @@ class ClockInfo(db.Model):
...
@@ -398,7 +400,7 @@ class ClockInfo(db.Model):
# Primary Key
# Primary Key
log_source
=
Column
(
Integer
,
primary_key
=
True
)
# The source this entry was updated from ("1" for engine1, "2" for engine2)
log_source
=
Column
(
Integer
,
primary_key
=
True
)
# The source this entry was updated from ("1" for engine1, "2" for engine2)
# Columns
# Columns
log_time
=
Column
(
DateTime
)
log_time
=
Column
(
DateTime
)
current_track
=
None
# Populated live from within `get_info(..)`
current_track
=
None
# Populated live from within `get_info(..)`
...
@@ -426,7 +428,7 @@ class ClockInfo(db.Model):
...
@@ -426,7 +428,7 @@ class ClockInfo(db.Model):
if
current_timeslot
:
if
current_timeslot
:
self
.
current_timeslot
=
json
.
dumps
(
current_timeslot
.
to_dict
(),
default
=
str
)
self
.
current_timeslot
=
json
.
dumps
(
current_timeslot
.
to_dict
(),
default
=
str
)
else
:
else
:
self
.
current_timeslot
=
None
self
.
current_timeslot
=
None
if
next_timeslot
:
if
next_timeslot
:
self
.
next_timeslot
=
json
.
dumps
(
next_timeslot
.
to_dict
(),
default
=
str
)
self
.
next_timeslot
=
json
.
dumps
(
next_timeslot
.
to_dict
(),
default
=
str
)
else
:
else
:
...
@@ -452,19 +454,19 @@ class ClockInfo(db.Model):
...
@@ -452,19 +454,19 @@ class ClockInfo(db.Model):
current_track
=
PlayLog
.
select_current
()
current_track
=
PlayLog
.
select_current
()
planned_playlist_id
=
-
1
planned_playlist_id
=
-
1
playlogs
=
None
playlogs
=
None
# Construct the clock `info` object
# Construct the clock `info` object
if
data
:
if
data
:
info
[
"
log_source
"
]
=
data
.
log_source
info
[
"
log_source
"
]
=
data
.
log_source
info
[
"
log_time
"
]
=
data
.
log_time
info
[
"
log_time
"
]
=
data
.
log_time
# Get the track currently playing
# Get the track currently playing
if
current_track
:
if
current_track
:
info
[
"
current_track
"
]
=
track_schema
.
dump
(
current_track
)
info
[
"
current_track
"
]
=
track_schema
.
dump
(
current_track
)
# Append the missing planned playlist items to the ones played
# Append the missing planned playlist items to the ones played
if
data
.
planned_playlist
:
if
data
.
planned_playlist
:
info
[
"
planned_playlist
"
]
=
json
.
loads
(
data
.
planned_playlist
)
info
[
"
planned_playlist
"
]
=
json
.
loads
(
data
.
planned_playlist
)
else
:
else
:
info
[
"
planned_playlist
"
]
=
{}
info
[
"
planned_playlist
"
]
=
{}
...
@@ -481,14 +483,14 @@ class ClockInfo(db.Model):
...
@@ -481,14 +483,14 @@ class ClockInfo(db.Model):
# Get the actual playlogs of the current timeslot, until now
# Get the actual playlogs of the current timeslot, until now
playlog_schema
=
PlayLogSchema
(
many
=
True
)
playlog_schema
=
PlayLogSchema
(
many
=
True
)
playlogs
=
PlayLog
.
select_for_timeslot
(
most_recent_track
.
timeslot_id
)
playlogs
=
PlayLog
.
select_for_timeslot
(
most_recent_track
.
timeslot_id
)
playlogs
.
sort
(
key
=
lambda
track
:
track
.
track_start
,
reverse
=
False
)
playlogs
.
sort
(
key
=
lambda
track
:
track
.
track_start
,
reverse
=
False
)
info
[
"
current_playlogs
"
]
=
playlog_schema
.
dump
(
playlogs
)
info
[
"
current_playlogs
"
]
=
playlog_schema
.
dump
(
playlogs
)
if
info
[
"
current_playlogs
"
]
==
None
:
if
info
[
"
current_playlogs
"
]
==
None
:
info
[
"
current_playlogs
"
]
=
{}
info
[
"
current_playlogs
"
]
=
{}
# Invalid timeslots (e.g. in fallback scenarios) get a virtual start date of the first fallback track
# Invalid timeslots (e.g. in fallback scenarios) get a virtual start date of the first fallback track
if
info
[
"
current_timeslot
"
][
"
timeslot_id
"
]
==
-
1
:
if
info
[
"
current_timeslot
"
][
"
timeslot_id
"
]
==
-
1
:
if
playlogs
and
playlogs
[
0
]:
if
playlogs
and
playlogs
[
0
]:
info
[
"
current_timeslot
"
][
"
timeslot_start
"
]
=
playlogs
[
0
].
track_start
info
[
"
current_timeslot
"
][
"
timeslot_start
"
]
=
playlogs
[
0
].
track_start
# Get the next timeslot
# Get the next timeslot
...
@@ -528,4 +530,4 @@ class ClockInfoSchema(ma.SQLAlchemySchema):
...
@@ -528,4 +530,4 @@ class ClockInfoSchema(ma.SQLAlchemySchema):
"
current_playlogs
"
,
"
current_playlogs
"
,
"
current_timeslot
"
,
"
current_timeslot
"
,
"
next_timeslot
"
"
next_timeslot
"
)
)
\ No newline at end of file
\ No newline at end of file
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