iwla

iwla Commit Details

Date:2014-11-20 11:50:06 (6 years 8 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:7bd5a42962750cee68c672689fc76cf0fd45b75c
Parents: 8ba8c99b3c86864153cd5acfad37abb021d2bdfc
Message:Display works

Changes:
Miwla.py (6 diffs)

File differences

iwla.py
1616
1717
1818
19
1920
2021
2122
......
3334
3435
3536
36
37
37
38
39
40
3841
42
3943
4044
4145
......
4852
4953
5054
51
55
5256
5357
58
59
60
61
62
63
64
65
66
67
68
69
5470
5571
5672
......
180196
181197
182198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
183261
184262
185263
......
211289
212290
213291
292
293
214294
215295
216296
......
232312
233313
234314
315
316
235317
236318
237319
analyse_started = False
current_visits = {}
cache_plugins = {}
display = {}
log_format = '$server_name:$server_port $remote_addr - $remote_user [$time_local] ' +\
'"$request" $status $body_bytes_sent ' +\
pages_extensions = ['/', 'html', 'xhtml', 'py', 'pl', 'rb', 'php']
viewed_http_codes = [200]
PRE_HOOK_DIRECTORY = './hooks/pre_analysis/*.py'
POST_HOOK_DIRECTORY = './hooks/post_analysis/*.py'
HOOKS_ROOT = './hooks/'
PRE_HOOK_DIRECTORY = HOOKS_ROOT + 'pre_analysis/*.py'
POST_HOOK_DIRECTORY = HOOKS_ROOT + 'post_analysis/*.py'
DISPLAY_HOOK_DIRECTORY = HOOKS_ROOT + 'display/*.py'
DB_ROOT = './output/'
DISPLAY_ROOT = './output/'
META_PATH = DB_ROOT + 'meta.db'
DB_FILENAME = 'iwla.db'
return visits
def createEmptyMeta():
meta = {'last_time':None}
meta = {'last_time' : None}
return meta
def createEmptyDisplay():
display = {}
return display
def createPage(filename, title):
page = {}
page['title'] = title;
page['blocks'] = []
display[filename] = page
return page
def getDBFilename(time):
return (DB_ROOT + '%d/%d_%s') % (time.tm_year, time.tm_mon, DB_FILENAME)
hit['time_decoded'] = time.strptime(t, time_format)
def buildPages():
for filename in display.keys():
page = display[filename]
with open(DISPLAY_ROOT + filename, 'w') as f:
f.write('<html><title>%s</title><body>' % (page['title']))
for block in page['blocks']:
if block['type'] == 'html':
f.write(block['value'])
elif block['type'] == 'table':
f.write('<table>')
f.write('<tr>')
for title in block['cols']:
f.write('<th>%s</th>' % (title))
f.write('</tr>')
for row in block['rows']:
f.write('<tr>')
for v in row:
f.write('<td>%s</td>' % (v))
f.write('</tr>')
f.write('</table>')
f.write('</body></html>')
def generateDisplayDaysStat():
cur_time = meta_visit['last_time']
title = 'Stats %d/%d' % (cur_time.tm_mon, cur_time.tm_year)
filename = '%d/index_%d.html' % (cur_time.tm_year, cur_time.tm_mon)
page = createPage(filename, title)
days = {'type' : 'table', 'title' : 'By day'}
days['cols'] = ['Day', 'Visits', 'Pages', 'Hits', 'Bandwith', 'Robot Bandwith']
days['rows'] = []
keys = current_visits['days_stats'].keys()
keys.sort()
nb_visits = 0
for k in keys:
stats = current_visits['days_stats'][k]
row = [k, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'], stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
row = map(lambda(v): str(v), row)
days['rows'].append(row)
nb_visits += stats['nb_visitors']
stats = current_visits['month_stats']
nb_days = len(keys)
row = [0, nb_visits, stats['viewed_pages'], stats['viewed_hits'], stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
if nb_days:
row = map(lambda(v): str(int(v/nb_days)), row)
else:
row = map(lambda(v): '0', row)
row[0] = 'Average'
days['rows'].append(row)
row = ['Total', nb_visits, stats['viewed_pages'], stats['viewed_hits'], stats['viewed_bandwidth'], stats['not_viewed_bandwidth']]
row = map(lambda(v): str(v), row)
days['rows'].append(row)
page['blocks'].append(days)
def generateDisplay():
generateDisplayDaysStat()
callPlugins(DISPLAY_HOOK_DIRECTORY, current_visits, display)
buildPages()
def generateStats(visits):
stats = {}
return stats
def generateMonthStats():
display = createEmptyDisplay()
visits = current_visits['visits']
stats = generateStats(visits)
serialize(current_visits, path)
generateDisplay()
def generateDayStats():
visits = current_visits['visits']

Archive Download the corresponding diff file

Branches

Tags