Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
ale
djrandom-py
Commits
a87951a8
Commit
a87951a8
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
add a never_played API method
parent
525b041e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/djrandom/frontend/api_views.py
+8
-0
8 additions, 0 deletions
server/djrandom/frontend/api_views.py
server/djrandom/model/mp3.py
+11
-3
11 additions, 3 deletions
server/djrandom/model/mp3.py
with
19 additions
and
3 deletions
server/djrandom/frontend/api_views.py
+
8
−
0
View file @
a87951a8
...
...
@@ -156,6 +156,14 @@ def most_played_json():
return
jsonify
(
results
=
most_played
)
@app.route
(
'
/json/never_played
'
,
methods
=
[
'
GET
'
])
@require_auth
def
never_played_json
():
n
=
int
(
request
.
args
.
get
(
'
n
'
,
20
))
never_played
=
MP3
.
never_played
(
n
)
return
jsonify
(
results
=
never_played
)
@app.route
(
'
/json/last_uploaded
'
,
methods
=
[
'
GET
'
])
@require_auth
def
last_uploaded_json
():
...
...
This diff is collapsed.
Click to expand it.
server/djrandom/model/mp3.py
+
11
−
3
View file @
a87951a8
...
...
@@ -54,13 +54,16 @@ class MP3(Base):
desc
(
cls
.
uploaded_at
)).
limit
(
n
)
@classmethod
def
get_random_songs
(
cls
,
n
=
10
):
def
get_random_songs
(
cls
,
n
=
10
,
where_clause
=
None
):
"""
Return N completely random songs.
"""
results
=
[]
num_songs
=
cls
.
query
.
filter_by
(
state
=
cls
.
READY
).
count
()
if
where_clause
is
None
:
where_clause
=
(
cls
.
state
==
cls
.
READY
)
num_songs
=
cls
.
query
.
filter
(
where_clause
).
count
()
fraction
=
float
(
n
)
/
num_songs
where_clause
=
where_clause
&
(
func
.
rand
()
<
fraction
)
while
len
(
results
)
<
n
:
tmprows
=
Session
.
query
(
cls
.
sha1
).
filter
(
func
.
rand
()
<
fraction
).
limit
(
n
)
tmprows
=
Session
.
query
(
cls
.
sha1
).
filter
(
where_clause
).
limit
(
n
)
for
row
in
tmprows
:
results
.
append
(
row
[
0
])
return
results
...
...
@@ -70,6 +73,11 @@ class MP3(Base):
return
cls
.
query
.
filter_by
(
state
=
cls
.
READY
,
artist
=
artist
,
album
=
album
)
@classmethod
def
never_played
(
cls
,
n
=
10
):
"""
Return N random songs that were never played.
"""
return
cls
.
get_random_songs
(
n
,
where_clause
=
(
cls
.
play_count
==
0
))
class
PlayLog
(
Base
):
...
...
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