iwla

iwla Commit Details

Date:2014-11-20 16:31:00 (6 years 8 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:34aec57c46a8791b8bdee8c192afad71430413df
Parents: f3cb04b16cf8856294ca426d1e5aa6bae87a719c
Message:Separate display functions into display.py

Changes:
Adisplay.py (full)
Miwla.py (5 diffs)

File differences

display.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def createPage(display, filename, title):
page = {}
page['title'] = title;
page['blocks'] = []
display[filename] = page
return page
def appendBlockToPage(page, block):
page['blocks'].append(block)
def createTable(title, cols):
table = {'type' : 'table', 'title' : title}
table['cols'] = cols
table['rows'] = []
def appendRowToTable(table, row):
table['rows'].append(row)
def buildPages(display):
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>')
iwla.py
88
99
1010
11
12
1113
1214
1315
......
8587
8688
8789
88
89
90
91
92
93
94
95
9690
9791
9892
......
211205
212206
213207
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236208
237209
238210
239211
240
212
241213
242
243
244
214
215
245216
246217
247218
......
249220
250221
251222
252
223
253224
254225
255226
......
262233
263234
264235
265
236
266237
267238
268239
269
270
240
241
271242
272243
273244
import pickle
import gzip
from display import *
# Default configuration
DB_ROOT = './output/'
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)
page = createPage(display, filename, title)
days = {'type' : 'table', 'title' : 'By day'}
days['cols'] = ['Day', 'Visits', 'Pages', 'Hits', 'Bandwith', 'Robot Bandwith']
days['rows'] = []
days = createTable('By day', ['Day', 'Visits', 'Pages', 'Hits', 'Bandwith', 'Robot Bandwith'])
keys = current_visits['days_stats'].keys()
keys.sort()
nb_visits = 0
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)
appendRowToTable(days, row)
nb_visits += stats['nb_visitors']
stats = current_visits['month_stats']
row = map(lambda(v): '0', row)
row[0] = 'Average'
days['rows'].append(row)
appendRowToTable(days, 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)
appendRowToTable(days, row)
appendBlockToPage(page, days)
def generateDisplay():
generateDisplayDaysStat()

Archive Download the corresponding diff file

Branches

Tags