]> git.ipfire.org Git - ipfire.org.git/blob - src/web/analytics.py
wiki: Only match usernames when a word starts with @
[ipfire.org.git] / src / web / analytics.py
1 #!/usr/bin/python3
2
3 import datetime
4 import tornado.web
5
6 from . import base
7 from . import ui_modules
8
9 class IndexHandler(base.BaseHandler):
10 @tornado.web.authenticated
11 def get(self):
12 # Check access permissions
13 if not self.current_user.is_admin():
14 raise tornado.web.HTTPError(403)
15
16 self.render("analytics/index.html")
17
18
19 class DocsHandler(base.BaseHandler):
20 @tornado.web.authenticated
21 def get(self):
22 # Check access permissions
23 if not self.current_user.is_admin():
24 raise tornado.web.HTTPError(403)
25
26 # Most Popular Pages
27 popular_pages = self.backend.analytics.get_most_popular_docs_pages(
28 self.request.host, since=datetime.timedelta(hours=24 * 365), limit=50)
29
30 # Popular Searches
31 popular_searches = self.backend.analytics.get_search_queries(
32 self.request.host, "/docs/search", limit=25)
33
34 self.render("analytics/docs.html",
35 popular_pages=popular_pages, popular_searches=popular_searches)
36
37
38 class SummaryModule(ui_modules.UIModule):
39 def render(self, host=None, uri=None):
40 if host is None:
41 host = self.request.host
42
43 if uri is None:
44 uri = self.request.path
45
46 # Fetch the total number of page views
47 total_page_views = self.backend.analytics.get_page_views(host, uri)
48
49 # Fetch the total number of page views in the last 24h
50 total_page_views_24h = self.backend.analytics.get_page_views(host, uri,
51 since=datetime.timedelta(hours=24))
52
53 return self.render_string("analytics/modules/summary.html", host=host, uri=uri,
54 total_page_views=total_page_views, total_page_views_24h=total_page_views_24h)