commit e4f85a7d4f141999a4b1c9f0d8e9cb674128907f
Author: David Fifield <david(a)bamsoftware.com>
Date: Tue Dec 18 19:11:48 2012 -0800
Rework facilitator-graph.py again.
---
experiments/facilitator-graph.py | 67 +++++++++-----------------------------
1 files changed, 16 insertions(+), 51 deletions(-)
diff --git a/experiments/facilitator-graph.py b/experiments/facilitator-graph.py
index c86742e..3c7ef3e 100755
--- a/experiments/facilitator-graph.py
+++ b/experiments/facilitator-graph.py
@@ -51,14 +51,11 @@ def format_date(d, pos=None):
def timedelta_to_seconds(delta):
return delta.days * (24 * 60 * 60) + delta.seconds + delta.microseconds / 1000000.0
-class Block(object):
- def __init__(self, date):
- self.begin_date = date
- self.end_date = date
-
-prev_date = None
-current = []
-blocks = []
+prev_output = None
+count = 0
+
+data = []
+
for line in input_file:
m = re.match(r'^(\d+-\d+-\d+ \d+:\d+:\d+) proxy gets', line)
if not m:
@@ -66,50 +63,18 @@ for line in input_file:
date_str, = m.groups()
date = datetime.datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
- if prev_date is None or prev_date != date.date():
- print date.date()
- prev_date = date.date()
-
- block = Block(date)
- block.end_date = date + datetime.timedelta(0, 10)
- current.append(block)
- # Poor man's priority queue: keep the first to expire (oldest) at the
- # tail of the list.
- current.sort(key = lambda x: x.end_date, reverse = True)
-
- # Delete all those that are now expired.
- while current:
- block = current[-1]
- delta = timedelta_to_seconds(date - block.end_date)
- if delta > POLL_INTERVAL * 1.5:
- blocks.append(block)
- current.pop()
- else:
- break
-
-events = []
-for block in blocks:
- events.append(("begin", block.begin_date))
- events.append(("end", block.end_date + datetime.timedelta(seconds = POLL_INTERVAL / 2)))
-# Handle any still alive at the end.
-while current:
- block = current[-1]
- events.append(("begin", block.begin_date))
- events.append(("end", date))
- current.pop()
-
-events.sort(key = lambda x: x[1])
+ count += 1
+
+ rounded_date = date.replace(minute=0, second=0, microsecond=0)
+ prev_output = prev_output or rounded_date
+ if prev_output is None or rounded_date != prev_output:
+ delta = timedelta_to_seconds(date - prev_output)
+ avg = float(count) / delta * POLL_INTERVAL
+ data.append((date, avg))
+ print date, avg
+ prev_output = rounded_date
+ count = 0
-data = []
-num = 0
-for i, event in enumerate(events):
- t = event[1]
- data.append((t, num))
- if event[0] == "begin":
- num += 1
- elif event[0] == "end":
- num -= 1
- data.append((t, num))
data = np.array(data)
fig = plt.figure()