[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [metrics-utils/master 1/4] Fix an inaccuracy in visitor.py.
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Thu, 25 Nov 2010 18:41:16 +0100
Subject: Fix an inaccuracy in visitor.py.
Commit: a4535ac24cb1d3e3a0e1ec6578b7194b452dabc8
When parsing an Apache log line, we're trying to find the last ExitAddress
line preceding the log timestamp. bisect_left gives us the insertion point
to maintain sorted order when inserting a new element. We need to make
sure this insertion point isn't index 0, meaning there's no smaller
timestamp. And we need to look at index pos - 1 to compare the log
timestamp with the exit list timestamp.
---
visitor/visitor.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/visitor/visitor.py b/visitor/visitor.py
index e779f9a..06288b1 100644
--- a/visitor/visitor.py
+++ b/visitor/visitor.py
@@ -93,8 +93,8 @@ def is_tor(apache_ip, apache_time, exitlist):
if not apache_ip in exitlist: return False
timestamps = exitlist[apache_ip]
pos = bisect.bisect_left(timestamps, apache_time)
- if pos >= len(timestamps): return False
- return timestamps[pos] - apache_time <= timedelta(1)
+ if pos == 0: return False
+ return apache_time - timestamps[pos - 1] <= timedelta(1)
def analyze(apache_log_path, exitlist_path, output = sys.stdout):
"""
--
1.7.1