Commit 981a8757 authored by Arthur Lutz's avatar Arthur Lutz
Browse files

cleanup and added some visualisation views

parent d19fe684a597
......@@ -104,16 +104,13 @@ class UpdateWebstatsCommand(Command):
'hit_type': is_rdf and 'rdf' or 'normal'})
if rset:
if rset[0][1] != total_hits:
print 'update', entity
update_stats['updated'] += 1
session.execute('SET X count %(hits)s WHERE X eid %(e)s' %
{'e':rset[0][0],
'hits':total_hits})
else:
print 'no change', entity
update_stats['exists no change'] += 1
else:
print 'create', entity
update_stats['created'] += 1
session.create_entity('Hits', count = total_hits,
period=stats_period,
......
......@@ -27,5 +27,3 @@ class AwstatsAccessAction(action.Action):
def url(self):
return self._cw.build_url('?vid=awstats')
def registration_callback(vreg):
vreg.register(AwstatsAccessAction)
......@@ -16,20 +16,72 @@
"""cubicweb-awstats views/forms/actions/components for web ui"""
from cubicweb.web.views import primary
from cubicweb.view import EntityView
from cubicweb.web.views import primary, navigation
from cubicweb.selectors import is_instance
class StatPeriodPrimaryView(primary.PrimaryView):
__select__ = is_instance('StatPeriod')
def cell_call(self, row, col):
req = self._cw
self.w(u'<div id="statperiod"/>')
entity = self.cw_rset.get_entity(row, col)
self.w(u'<h1>%s %s - %s</h1>' % (_('Stats for period :'), entity.start, entity.stop) )
self.w(u'<h1>%s %s - %s</h1>' % (_('Statistics for period :'), entity.start, entity.stop) )
# TODO - could loop over hit_type and make tabs
# TODO - facets ?
rql = 'Any X, T, C ORDERBY C DESC WHERE H is Hits, H stats_about X, H hit_type T, H count C, H period P, P eid %(e)s'
rset = self._cw.execute('Any C GROUPBY C WHERE X is Hits, X hit_type C')
self.w(u'<a href="%s">%s</a>' % (entity.absolute_url(showall=1),
_('show all results')))
for index, hit_type in enumerate(rset):
self.w(u'<h3>%s</h3>' % hit_type[0])
rql = 'Any X, C ORDERBY C DESC %(limit)s WHERE H stats_about X, H hit_type "%(type)s",'\
'H count C, H period P, P eid %%(e)s' % {'type': hit_type[0],
'limit': req.form.get('showall') and ' ' or 'LIMIT 20' }
rset = self._cw.execute(rql, {'e':entity.eid})
self.w(self._cw.view('table', rset, 'null'))
self.w(u'</div>')
def registration_callback(vreg):
vreg.register(StatPeriodPrimaryView)
class StatPeriodIPrevNextAdapter(navigation.IPrevNextAdapter):
__select__ = is_instance('StatPeriod')
def previous_entity(self):
entity = self.entity
execute = self._cw.execute
rset = execute("StatPeriod S ORDERBY D WHERE S start D")
for index, item in enumerate(rset):
if item[0] == entity.eid and index >= 1:
return rset.get_entity(index-1, 0)
def next_entity(self):
entity = self.entity
execute = self._cw.execute
rset = execute("StatPeriod S ORDERBY D WHERE S start D")
for index, item in enumerate(rset):
if item[0] == entity.eid and index + 1 < len(rset):
return rset.get_entity(index+1, 0)
class StatGraph(primary.PrimaryView):
__regid__ = 'webstatsgraph'
def cell_call(self, row, col):
entity = self.cw_rset.get_entity(row, col)
self.w(u'<h1>%s %s</h1>' % (_('Graph of hits for'),
entity.dc_title()))
rql = 'Any S, HITS WHERE H hit_type "normal", H count HITS, H stats_about E, H period P, P start S, E eid %(e)s'
rset = self._cw.execute(rql, {'e':entity.eid})
self.w(self._cw.view('plot', rset, 'null'))
class StatPeriodChart(EntityView):
__regid__ = 'periodchart'
__select__ = is_instance('StatPeriod')
def cell_call(self, row, col):
entity = self.cw_rset.get_entity(row, col)
self.w(u'<h1>%s %s</h1>' % (_('Piechart of hits for'),
entity.dc_title()))
rql = 'Any X, C ORDERBY C DESC LIMIT 20 WHERE H stats_about X, H hit_type "normal",H count C, H period P, P eid %(e)s'
self.wview('piechart', self._cw.execute(rql, {'e': entity.eid}),
'null')
......@@ -151,11 +151,11 @@ class AwstatsView(StartupView):
def render_navigation(self, stats_dict):
""" render navigation according to which sections are present """
self.w(u'<div>')
self.w(u'<ul>')
self.w(u'<table id="navigation">')
for key in SECTIONSPEC.keys():
if stats_dict[key].values():
self.w(u'<li><a href="#%s">%s</a></li>' % (key, SECTIONLABELS[key]))
self.w(u'</ul>')
self.w(u'<tr><td><a href="#%s">%s</a></td></tr>' % (key, SECTIONLABELS[key]))
self.w(u'</table>')
self.w(u'</div>')
def generic_table(self, section_name, stats_dict, limit):
......@@ -201,7 +201,3 @@ class AwstatsView(StartupView):
for item in stats_dict[section_name].values()]
ordered_values.sort(reverse=reverse)
return ordered_values
def registration_callback(vreg):
vreg.register(AwstatsView)
vreg.register(AwstatsRefreshForm)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment