Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py-deleted-112
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This project is pending deletion, and will be deleted on
2025-06-14
. Repository and other project resources are read-only.
Show more breadcrumbs
ale
djrandom-py-deleted-112
Commits
d6e3251b
Commit
d6e3251b
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
add a couple of methods to extract stats from the playlog
parent
c726994c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/djrandom/model/mp3.py
+20
-0
20 additions, 0 deletions
server/djrandom/model/mp3.py
with
20 additions
and
0 deletions
server/djrandom/model/mp3.py
+
20
−
0
View file @
d6e3251b
...
@@ -136,6 +136,17 @@ class MP3(Base):
...
@@ -136,6 +136,17 @@ class MP3(Base):
"""
Return N random songs that were never played.
"""
"""
Return N random songs that were never played.
"""
return
cls
.
get_random_songs
(
n
,
where_clause
=
(
cls
.
play_count
==
0
))
return
cls
.
get_random_songs
(
n
,
where_clause
=
(
cls
.
play_count
==
0
))
@classmethod
def
uploads_by_day
(
cls
,
days
=
30
):
# select to_days(uploaded_at) as d, count(*) from mp3 group by d order by d asc;
result
=
[]
for
row
in
Session
.
query
(
func
.
to_days
(
cls
.
uploaded_at
).
label
(
'
day
'
),
func
.
count
(
'
*
'
).
label
(
'
count
'
)).
filter
(
cls
.
uploaded_at
>
date_limit
).
group_by
(
'
day
'
).
order_by
(
'
day asc
'
):
result
.
append
(
row
.
count
)
return
result
class
PlayLog
(
Base
):
class
PlayLog
(
Base
):
...
@@ -171,6 +182,15 @@ class PlayLog(Base):
...
@@ -171,6 +182,15 @@ class PlayLog(Base):
hashes
=
[
None
]
*
n
hashes
=
[
None
]
*
n
yield
(
plog
.
sha1
,
hashes
)
yield
(
plog
.
sha1
,
hashes
)
@classmethod
def
top_songs_for_user
(
cls
,
userid
,
days
=
30
,
n
=
10
):
"""
Return the top played songs for a user.
"""
date_limit
=
datetime
.
now
()
-
timedelta
(
days
)
return
Session
.
query
(
cls
.
sha1
,
func
.
count
(
cls
.
sha1
).
label
(
'
count
'
)
).
filter
((
cls
.
userid
==
userid
)
&
(
cls
.
stamp
>
date_limit
)
).
group_by
(
cls
.
sha1
).
order_by
(
'
count desc
'
).
limit
(
n
)
class
SearchLog
(
Base
):
class
SearchLog
(
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