Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubes
awstats
Commits
d0117e96ee97
Commit
86441169
authored
May 23, 2011
by
Arthur Lutz
Browse files
make the command work for different periodicities
parent
c248b2134a11
Changes
1
Hide whitespace changes
Inline
Side-by-side
ccplugin.py
View file @
d0117e96
...
...
@@ -43,16 +43,22 @@ def url_count_from_stats(stats_dict):
class
UpdateWebstatsCommand
(
Command
):
""" Update web stats """
""" Update web stats
according to periodicity setting the input format for the date is different :
* month 05/2011
* day 15/05/2011
* hour 15/05/2011-13h
"""
arguments
=
'<instance>'
name
=
'update-webstats'
min_args
=
1
def
get_current_stats_period
(
self
,
session
,
chosendate
):
def
get_current_stats_period
(
self
,
session
,
chosendate
,
periodicity
):
""" return a statperiod for the current month, if it doesn't exist, create it """
start
=
first_day
(
chosendate
)
end
=
last_day
(
start
)
start
,
end
=
self
.
choose_period
(
chosendate
,
periodicity
)
rql
=
'Any P WHERE P is StatPeriod, P start "%(start_date)s", P stop "%(end_date)s"'
rset
=
session
.
execute
(
rql
%
{
'start_date'
:
start
,
...
...
@@ -62,17 +68,43 @@ class UpdateWebstatsCommand(Command):
else
:
return
session
.
create_entity
(
'StatPeriod'
,
start
=
start
,
stop
=
end
)
def
choose_period
(
self
,
chosendate
,
periodicity
):
if
periodicity
==
'month'
:
start
=
first_day
(
chosendate
)
end
=
last_day
(
start
)
elif
periodicity
==
'day'
:
start
=
datetime
(
chosendate
.
year
,
chosendate
.
month
,
chosendate
.
day
)
end
=
datetime
(
chosendate
.
year
,
chosendate
.
month
,
chosendate
.
day
,
23
,
59
,
59
)
elif
periodicity
==
'hour'
:
start
=
datetime
(
chosendate
.
year
,
chosendate
.
month
,
chosendate
.
day
,
chosendate
.
hour
)
end
=
datetime
(
chosendate
.
year
,
chosendate
.
month
,
chosendate
.
day
,
chosendate
.
hour
,
59
,
59
)
return
start
,
end
def
choose_dateformat
(
self
,
periodicity
):
return
{
'hour'
:
'%m%Y%d%H'
,
'day'
:
'%m%Y%d'
,
'month'
:
'%m%Y'
}[
periodicity
]
def
update_stats
(
self
,
session
,
args
):
''' parses awstats and creates or updates the corresponding
data in the cubicweb instance'''
awstatsdir
=
session
.
vreg
.
config
.
get
(
'awstats-dir'
,
'/var/lib/awstats'
)
domain
=
session
.
vreg
.
config
.
get
(
'awstats-domain'
,
''
)
periodicity
=
session
.
vreg
.
config
.
get
(
'awstats-periodicity'
,
'day'
)
#FIXME s/day/month/
assert
periodicity
in
(
'hour'
,
'day'
,
'month'
)
if
args
:
chosendate
=
datetime
.
strptime
(
args
[
0
],
'%m/%Y'
)
# FIXME - adapt according to periodicity
input_format
=
{
'month'
:
'%m/%Y'
,
'day'
:
'%d/%m/%Y'
,
'hour'
:
'%d/%m/%Y-%Hh'
}[
periodicity
]
chosendate
=
datetime
.
strptime
(
args
[
0
],
input_format
)
# TODO - probably need a command to update stats from day X to day Y...
else
:
chosendate
=
datetime
.
now
()
stats_period
=
self
.
get_current_stats_period
(
session
,
chosendate
)
aw
stats
dir
=
session
.
vreg
.
config
.
get
(
'awstats-dir'
,
'/var/lib/awstats'
)
d
omain
=
session
.
vreg
.
config
.
get
(
'awstats-domain'
,
''
)
filename
=
'awstats%s%s.txt'
%
(
chosendate
.
strftime
(
'%m%Y'
),
domain
and
'.%s'
%
domain
)
stats
_period
=
self
.
get_current_stats_period
(
session
,
chosendate
,
periodicity
)
d
ateformat_in_file
=
self
.
choose_dateformat
(
periodicity
)
filename
=
'awstats%s%s.txt'
%
(
chosendate
.
strftime
(
dateformat_in_file
),
domain
and
'.%s'
%
domain
)
stats_dict
=
extract_stats_dict
(
awstatsdir
,
filename
)
normal_dict
,
rdf_dict
=
url_count_from_stats
(
stats_dict
)
is_rdf
=
False
...
...
@@ -169,7 +201,7 @@ Number of stat objects skipped : %(skipped)s
def
run
(
self
,
args
):
appid
=
args
.
pop
(
0
)
cw_cnx
,
session
=
self
.
_init_cw_connection
(
appid
)
session
.
set_
pool
()
session
.
set_
cnxset
()
self
.
update_stats
(
session
,
args
)
session
.
commit
()
...
...
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