iwla

iwla Git Source Tree

Root/plugins/post_analysis/top_hits.py

Source at commit 4e02325733e5e8e4f5de2f0046e721f8da7abfff created 6 years 10 months ago.
By Gregory Soutade, Initial commit
1# -*- coding: utf-8 -*-
2#
3# Copyright Grégory Soutadé 2015
4
5# This file is part of iwla
6
7# iwla is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# iwla is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with iwla. If not, see <http://www.gnu.org/licenses/>.
19#
20
21from iwla import IWLA
22from iplugin import IPlugin
23
24"""
25Post analysis hook
26
27Count TOP hits
28
29Plugin requirements :
30 None
31
32Conf values needed :
33 None
34
35Output files :
36 None
37
38Statistics creation :
39 None
40
41Statistics update :
42month_stats:
43 top_hits =>
44 uri
45
46Statistics deletion :
47 None
48"""
49
50class IWLAPostAnalysisTopHits(IPlugin):
51 def __init__(self, iwla):
52 super(IWLAPostAnalysisTopHits, self).__init__(iwla)
53 self.API_VERSION = 1
54
55 def hook(self):
56 stats = self.iwla.getCurrentVisists()
57 month_stats = self.iwla.getMonthStats()
58
59 top_hits = month_stats.get('top_hits', {})
60
61 for (k, super_hit) in stats.items():
62 if super_hit['robot']: continue
63 for r in super_hit['requests'][::-1]:
64 if not self.iwla.isValidForCurrentAnalysis(r):
65 break
66 if not self.iwla.hasBeenViewed(r) or\
67 r['is_page']:
68 continue
69
70 uri = r['extract_request']['extract_uri'].lower()
71 uri = "%s%s" % (r.get('server_name', ''), uri)
72
73 if not uri in top_hits.keys():
74 top_hits[uri] = 1
75 else:
76 top_hits[uri] += 1
77
78 month_stats['top_hits'] = top_hits

Archive Download this file

Branches

Tags