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