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
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
d924d550
Commit
d924d550
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
add pretty graphs of uploads/plays to the about page
parent
e618e850
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/djrandom/frontend/templates/about.html
+16
-5
16 additions, 5 deletions
server/djrandom/frontend/templates/about.html
server/djrandom/frontend/views.py
+24
-7
24 additions, 7 deletions
server/djrandom/frontend/views.py
server/djrandom/model/mp3.py
+14
-0
14 additions, 0 deletions
server/djrandom/model/mp3.py
with
54 additions
and
12 deletions
server/djrandom/frontend/templates/about.html
+
16
−
5
View file @
d924d550
...
@@ -5,16 +5,27 @@
...
@@ -5,16 +5,27 @@
<h3>
{{ config['SITE_NAME'] }}
</h3>
<h3>
{{ config['SITE_NAME'] }}
</h3>
<p>
<p>
<b>
{{ num_users }}
</b>
users,
<b>
{{
data['
num_users
']
}}
</b>
users,
</p>
</p>
<p>
<p>
<b>
{{ num_songs }}
</b>
songs
<b>
{{
data['
num_songs
']
}}
</b>
songs
(
<b>
{{ used_gb }}
</b>
Gb).
(
<b>
{{
data['
used_gb
']
}}
</b>
Gb).
</p>
</p>
{% if dup_songs %}
{% if
data['
dup_songs
']
%}
<p>
<p>
<b>
{{ dup_songs }}
</b>
duplicates found.
<b>
{{
data['
dup_songs
']
}}
</b>
duplicates found.
</p>
</p>
{% endif %}
{% endif %}
<hr/>
<p>
<small>
Uploads (30 days):
</small><br>
<img
src=
"{{ data['incoming_graph'] }}"
>
</p>
<p>
<small>
Played songs (30 days):
</small><br>
<img
src=
"{{ data['play_graph'] }}"
>
</p>
{% endblock %}
{% endblock %}
This diff is collapsed.
Click to expand it.
server/djrandom/frontend/views.py
+
24
−
7
View file @
d924d550
import
os
import
os
import
logging
import
logging
import
pygooglechart
from
datetime
import
datetime
from
datetime
import
datetime
from
flask
import
Flask
,
request
,
Response
,
abort
,
jsonify
,
render_template
,
g
from
flask
import
Flask
,
request
,
Response
,
abort
,
jsonify
,
render_template
,
g
from
djrandom
import
utils
from
djrandom
import
utils
...
@@ -47,16 +48,32 @@ def songs_fragment():
...
@@ -47,16 +48,32 @@ def songs_fragment():
return
render_template
(
'
songs_fragment.html
'
,
songs
=
mp3s
)
return
render_template
(
'
songs_fragment.html
'
,
songs
=
mp3s
)
def
_makegraph
(
values
):
max_v
=
max
(
values
)
*
1.2
chart
=
pygooglechart
.
SimpleLineChart
(
220
,
125
,
y_range
=
[
0
,
max_v
])
chart
.
add_data
(
values
)
chart
.
set_colours
([
'
0000FF
'
])
return
chart
.
get_url
()
@app.route
(
'
/about
'
)
@app.route
(
'
/about
'
)
@require_auth
@require_auth
def
about
():
def
about
():
num_songs
=
MP3
.
query
.
filter_by
(
state
=
MP3
.
READY
).
count
()
cache_key
=
'
about
'
dup_songs
=
MP3
.
query
.
filter_by
(
state
=
MP3
.
DUPLICATE
).
count
()
data
=
svcs
[
'
cache
'
].
get
(
cache_key
)
used_gb
=
int
(
Session
.
query
(
func
.
sum
(
MP3
.
size
)).
first
()[
0
]
/
(
2
<<
29
))
if
not
data
:
num_users
=
User
.
query
.
filter_by
(
active
=
True
).
count
()
data
=
{
return
render_template
(
'
about.html
'
,
num_users
=
num_users
,
'
num_songs
'
:
MP3
.
query
.
filter_by
(
state
=
MP3
.
READY
).
count
(),
num_songs
=
num_songs
,
used_gb
=
used_gb
,
'
dup_songs
'
:
MP3
.
query
.
filter_by
(
state
=
MP3
.
DUPLICATE
).
count
(),
dup_songs
=
dup_songs
,
config
=
app
.
config
)
'
used_gb
'
:
int
(
Session
.
query
(
func
.
sum
(
MP3
.
size
)).
first
()[
0
]
/
(
2
<<
29
)),
'
num_users
'
:
User
.
query
.
filter_by
(
active
=
True
).
count
(),
'
incoming_graph
'
:
_makegraph
(
MP3
.
uploads_by_day
(
30
)),
'
play_graph
'
:
_makegraph
(
PlayLog
.
plays_by_day
(
30
)),
}
svcs
[
'
cache
'
].
set
(
cache_key
,
data
,
timeout
=
9600
)
return
render_template
(
'
about.html
'
,
data
=
data
,
config
=
app
.
config
)
@app.route
(
'
/
'
)
@app.route
(
'
/
'
)
...
...
This diff is collapsed.
Click to expand it.
server/djrandom/model/mp3.py
+
14
−
0
View file @
d924d550
...
@@ -154,6 +154,7 @@ class MP3(Base):
...
@@ -154,6 +154,7 @@ class MP3(Base):
def
uploads_by_day
(
cls
,
days
=
30
):
def
uploads_by_day
(
cls
,
days
=
30
):
# select to_days(uploaded_at) as d, count(*) from mp3 group by d order by d asc;
# select to_days(uploaded_at) as d, count(*) from mp3 group by d order by d asc;
result
=
[]
result
=
[]
date_limit
=
datetime
.
now
()
-
timedelta
(
days
)
for
row
in
Session
.
query
(
func
.
to_days
(
cls
.
uploaded_at
).
label
(
'
day
'
),
for
row
in
Session
.
query
(
func
.
to_days
(
cls
.
uploaded_at
).
label
(
'
day
'
),
func
.
count
(
'
*
'
).
label
(
'
count
'
)).
filter
(
func
.
count
(
'
*
'
).
label
(
'
count
'
)).
filter
(
cls
.
uploaded_at
>
date_limit
).
group_by
(
cls
.
uploaded_at
>
date_limit
).
group_by
(
...
@@ -206,6 +207,19 @@ class PlayLog(Base):
...
@@ -206,6 +207,19 @@ class PlayLog(Base):
&
(
cls
.
stamp
>
date_limit
)
&
(
cls
.
stamp
>
date_limit
)
).
group_by
(
cls
.
sha1
).
order_by
(
'
count desc
'
).
limit
(
n
)
).
group_by
(
cls
.
sha1
).
order_by
(
'
count desc
'
).
limit
(
n
)
@classmethod
def
plays_by_day
(
cls
,
days
=
30
):
# select to_days(uploaded_at) as d, count(*) from mp3 group by d order by d asc;
result
=
[]
date_limit
=
datetime
.
now
()
-
timedelta
(
days
)
for
row
in
Session
.
query
(
func
.
to_days
(
cls
.
stamp
).
label
(
'
day
'
),
func
.
count
(
'
*
'
).
label
(
'
count
'
)).
filter
(
cls
.
stamp
>
date_limit
).
group_by
(
'
day
'
).
order_by
(
'
day asc
'
):
result
.
append
(
row
.
count
)
return
result
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