Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
django-panik-nonstop
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
radiopanik
django-panik-nonstop
Commits
75f92077
Commit
75f92077
authored
Jun 14, 2015
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add filtering options to stats query string
parent
ca102b4c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
6 deletions
+34
-6
nonstop/templates/nonstop/statistics.html
nonstop/templates/nonstop/statistics.html
+3
-1
nonstop/views.py
nonstop/views.py
+31
-5
No files found.
nonstop/templates/nonstop/statistics.html
View file @
75f92077
...
...
@@ -3,6 +3,8 @@
{% block appbar %}
<h2>
Nonstop - Statistics
</h2>
<a
href=
"?from=-7d"
>
during last week
</a>
<a
href=
"?from=-30d"
>
during last month
</a>
{% endblock %}
{% block content %}
...
...
@@ -12,7 +14,7 @@
<h3>
{{ zone.title }}
<span>
({{zone.start}} → {{zone.end}})
</span></h3>
<ul>
<li>
Number of tracks: {{zone.stats.count}}
<li>
Number of tracks: {{zone.stats.count}}
{% if from_date %} (new: {{zone.stats.new_files}}, {{zone.stats.percent_new_files}}){% endif %}
<ul>
<li>
Instru: {{zone.stats.instru}} ({{zone.stats.instru_percentage}})
</li>
<li>
SABAM: {{zone.stats.sabam}} ({{zone.stats.sabam_percentage}})
</li>
...
...
nonstop/views.py
View file @
75f92077
...
...
@@ -36,7 +36,7 @@ class SomaDayArchiveCsvView(SomaDayArchiveView):
else
:
writer
.
writerow
([
line
.
play_timestamp
.
strftime
(
'%Y-%m-%d %H:%M'
),
line
.
filepath
.
short
.
encode
(
'utf-8'
,
'replace'
)])
return
HttpResponse
(
out
.
getvalue
(),
mime
type
=
'text/csv; charset=utf-8'
)
return
HttpResponse
(
out
.
getvalue
(),
content_
type
=
'text/csv; charset=utf-8'
)
class
RedirectTodayView
(
RedirectView
):
...
...
@@ -61,11 +61,18 @@ class ArtistListView(ListView):
class
ZoneStats
(
object
):
def
__init__
(
self
,
zone
):
def
__init__
(
self
,
zone
,
from_date
=
None
,
until_date
=
None
,
**
kwargs
):
self
.
zone
=
zone
self
.
qs
=
Track
.
objects
.
filter
(
nonstop_zones
=
self
.
zone
,
**
kwargs
)
self
.
from_date
=
from_date
if
from_date
:
self
.
qs
=
self
.
qs
.
filter
(
nonstopfile__somalogline__play_timestamp__gte
=
from_date
)
if
until_date
:
self
.
qs
=
self
.
qs
.
filter
(
nonstopfile__somalogline__play_timestamp__lte
=
until_date
)
self
.
qs
=
self
.
qs
.
distinct
()
def
count
(
self
,
**
kwargs
):
return
Track
.
objects
.
filter
(
nonstop_zones
=
self
.
zone
,
**
kwargs
).
count
()
return
self
.
qs
.
filter
(
**
kwargs
).
count
()
def
percentage
(
self
,
**
kwargs
):
total
=
self
.
count
()
...
...
@@ -100,13 +107,32 @@ class ZoneStats(object):
return
'-'
return
'%.2f%%'
%
(
100.
*
self
.
french
()
/
considered_tracks
)
def
new_files
(
self
):
return
self
.
count
(
nonstopfile__creation_timestamp__gte
=
self
.
from_date
)
def
percent_new_files
(
self
):
return
self
.
percentage
(
nonstopfile__creation_timestamp__gte
=
self
.
from_date
)
def
parse_date
(
date
):
if
date
.
endswith
(
'd'
):
return
datetime
.
datetime
.
today
()
+
datetime
.
timedelta
(
int
(
date
.
rstrip
(
'd'
)))
return
datetime
.
datetime
.
strptime
(
date
,
'%Y-%m-%d'
).
date
()
class
StatisticsView
(
TemplateView
):
template_name
=
'nonstop/statistics.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
StatisticsView
,
self
).
get_context_data
(
**
kwargs
)
context
[
'zones'
]
=
Nonstop
.
objects
.
all
().
order_by
(
'start'
)
kwargs
=
{}
if
'from'
in
self
.
request
.
GET
:
kwargs
[
'from_date'
]
=
parse_date
(
self
.
request
.
GET
[
'from'
])
context
[
'from_date'
]
=
kwargs
[
'from_date'
]
if
'until'
in
self
.
request
.
GET
:
kwargs
[
'until_date'
]
=
parse_date
(
self
.
request
.
GET
[
'until'
])
if
'onair'
in
self
.
request
.
GET
:
kwargs
[
'nonstopfile__somalogline__on_air'
]
=
True
for
zone
in
context
[
'zones'
]:
zone
.
stats
=
ZoneStats
(
zone
)
zone
.
stats
=
ZoneStats
(
zone
,
**
kwargs
)
return
context
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment