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
P
panikdb
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
panikdb
Commits
6e48764c
Commit
6e48764c
authored
Apr 10, 2015
by
fred
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add stats module
parent
a94071fc
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
86 additions
and
0 deletions
+86
-0
panikdb/settings.py
panikdb/settings.py
+1
-0
panikdb/stats/__init__.py
panikdb/stats/__init__.py
+0
-0
panikdb/stats/management/__init__.py
panikdb/stats/management/__init__.py
+0
-0
panikdb/stats/management/commands/__init__.py
panikdb/stats/management/commands/__init__.py
+0
-0
panikdb/stats/management/commands/load-piwik-stats.py
panikdb/stats/management/commands/load-piwik-stats.py
+48
-0
panikdb/stats/migrations/0001_initial.py
panikdb/stats/migrations/0001_initial.py
+27
-0
panikdb/stats/migrations/__init__.py
panikdb/stats/migrations/__init__.py
+0
-0
panikdb/stats/models.py
panikdb/stats/models.py
+10
-0
No files found.
panikdb/settings.py
View file @
6e48764c
...
...
@@ -136,6 +136,7 @@ INSTALLED_APPS = (
'nonstop'
,
'panikdb.aa'
,
'panikdb.customtags'
,
'panikdb.stats'
,
'gadjo'
,
'combo.data'
,
'combo.manager'
,
...
...
panikdb/stats/__init__.py
0 → 100644
View file @
6e48764c
panikdb/stats/management/__init__.py
0 → 100644
View file @
6e48764c
panikdb/stats/management/commands/__init__.py
0 → 100644
View file @
6e48764c
panikdb/stats/management/commands/load-piwik-stats.py
0 → 100644
View file @
6e48764c
import
datetime
import
json
import
urllib2
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
,
CommandError
from
panikdb.stats.models
import
SoundFile
,
DailyStat
class
Command
(
BaseCommand
):
def
handle
(
self
,
verbosity
,
**
kwargs
):
self
.
verbose
=
(
verbosity
>
1
)
piwik_api_href
=
settings
.
PIWIK_API_HREF
piwik_token_auth
=
settings
.
PIWIK_TOKEN_AUTH
piwik_site_id
=
settings
.
PIWIK_SITE_ID
url
=
'%(piwik_api_href)s?module=API&method=Events.getAction&'
\
'secondaryDimension=eventName&idSite=%(piwik_site_id)s&'
\
'period=day&date=last2&format=json&'
\
'token_auth=%(piwik_token_auth)s&expanded=1'
%
locals
()
request
=
urllib2
.
Request
(
url
)
request
.
add_header
(
'Accept'
,
'application/json'
)
if
self
.
verbose
:
print
'calling piwik'
result
=
json
.
load
(
urllib2
.
urlopen
(
request
))
if
self
.
verbose
:
print
'collecting results'
for
day
in
result
:
day_datetime
=
datetime
.
datetime
.
strptime
(
day
,
'%Y-%m-%d'
)
for
stat_segment
in
result
.
get
(
day
):
if
stat_segment
.
get
(
'segment'
)
!=
'eventAction==Play'
:
continue
for
entry
in
stat_segment
.
get
(
'subtable'
):
sound_id
=
entry
.
get
(
'label'
).
split
(
':'
)[
0
]
try
:
soundfile
=
SoundFile
.
objects
.
get
(
id
=
sound_id
)
except
(
SoundFile
.
DoesNotExist
,
ValueError
):
if
self
.
verbose
:
print
'failed to process'
,
entry
.
get
(
'label'
)
continue
try
:
stat
=
DailyStat
.
objects
.
get
(
soundfile
=
soundfile
,
day
=
day_datetime
)
except
DailyStat
.
DoesNotExist
:
stat
=
DailyStat
(
soundfile
=
soundfile
,
day
=
day_datetime
)
for
attribute
in
(
'nb_events'
,
'nb_visits'
):
setattr
(
stat
,
attribute
,
entry
.
get
(
attribute
))
stat
.
save
()
panikdb/stats/migrations/0001_initial.py
0 → 100644
View file @
6e48764c
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'emissions'
,
'0003_newsitem_event_date'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'DailyStat'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
(
'day'
,
models
.
DateField
()),
(
'nb_events'
,
models
.
IntegerField
()),
(
'nb_visits'
,
models
.
IntegerField
()),
(
'soundfile'
,
models
.
ForeignKey
(
to
=
'emissions.SoundFile'
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
]
panikdb/stats/migrations/__init__.py
0 → 100644
View file @
6e48764c
panikdb/stats/models.py
0 → 100644
View file @
6e48764c
from
django.db
import
models
from
emissions.models
import
SoundFile
class
DailyStat
(
models
.
Model
):
soundfile
=
models
.
ForeignKey
(
SoundFile
)
day
=
models
.
DateField
()
nb_events
=
models
.
IntegerField
()
nb_visits
=
models
.
IntegerField
()
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