WIP
This commit is contained in:
parent
b8027fe509
commit
8c7f135741
27
iwla.py
27
iwla.py
|
@ -59,6 +59,9 @@ def serialize(obj, filename):
|
|||
if not os.path.exists(base):
|
||||
os.makedirs(base)
|
||||
|
||||
# TODO : remove return
|
||||
return
|
||||
|
||||
with open(filename + '.tmp', 'wb+') as f:
|
||||
pickle.dump(obj, f)
|
||||
f.seek(0)
|
||||
|
@ -95,10 +98,17 @@ def isPage(request):
|
|||
return False
|
||||
|
||||
def appendHit(hit):
|
||||
super_hit = current_visits['visits'][hit['remote_addr']]
|
||||
remote_addr = hit['remote_addr']
|
||||
|
||||
if not remote_addr in current_visits['visits'].keys():
|
||||
createUser(hit)
|
||||
return
|
||||
|
||||
super_hit = current_visits['visits'][remote_addr]
|
||||
super_hit['pages'].append(hit)
|
||||
super_hit['bandwith'] += int(hit['body_bytes_sent'])
|
||||
|
||||
super_hit['last_access'] = meta_visit['last_time']
|
||||
|
||||
request = hit['extract_request']
|
||||
|
||||
if 'extract_uri' in request.keys():
|
||||
|
@ -132,6 +142,7 @@ def createUser(hit):
|
|||
super_hit['not_viewed_pages'] = 0;
|
||||
super_hit['not_viewed_hits'] = 0;
|
||||
super_hit['bandwith'] = 0;
|
||||
super_hit['last_access'] = meta_visit['last_time']
|
||||
super_hit['pages'] = [];
|
||||
super_hit['robot'] = isRobot(hit);
|
||||
appendHit(hit)
|
||||
|
@ -240,6 +251,11 @@ def generateDayStats():
|
|||
if last_day:
|
||||
for k in stats.keys():
|
||||
stats[k] -= current_visits['days_stats'][last_day][k]
|
||||
stats['nb_visitors'] = 0
|
||||
for k in visits.keys():
|
||||
if visits[k]['robot']: continue
|
||||
if visits[k]['last_access'].tm_mday == cur_time.tm_mday:
|
||||
stats['nb_visitors'] += 1
|
||||
print stats
|
||||
|
||||
current_visits['days_stats'][cur_time.tm_mday] = stats
|
||||
|
@ -280,11 +296,7 @@ def newHit(hit):
|
|||
for k in hit.keys():
|
||||
if hit[k] == '-': hit[k] = ''
|
||||
|
||||
remote_addr = hit['remote_addr']
|
||||
if remote_addr in current_visits['visits'].keys():
|
||||
appendHit(hit)
|
||||
else:
|
||||
createUser(hit)
|
||||
appendHit(hit)
|
||||
|
||||
return True
|
||||
|
||||
|
@ -310,6 +322,7 @@ for l in f:
|
|||
f.close();
|
||||
|
||||
if analyse_started:
|
||||
generateDayStats()
|
||||
generateMonthStats()
|
||||
serialize(meta_visit, META_PATH)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user