summaryrefslogtreecommitdiffstats
path: root/stats.py
diff options
context:
space:
mode:
authorGary Bressler <garybressler@nc.rr.com>2010-03-01 23:46:44 -0500
committerGary Bressler <garybressler@nc.rr.com>2010-03-01 23:46:44 -0500
commit44a8ade3ed5dc4810fd95c41dbe8ec3aa2fb0cf7 (patch)
tree4275bbcb03ec58412c3703e4df68f43fb1c10089 /stats.py
Reorganized tree, along with the visualizer
Diffstat (limited to 'stats.py')
-rw-r--r--stats.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/stats.py b/stats.py
new file mode 100644
index 0000000..34a842f
--- /dev/null
+++ b/stats.py
@@ -0,0 +1,39 @@
1###############################################################################
2# Description
3###############################################################################
4# Compute and produce statistics
5
6
7###############################################################################
8# Public Functions
9###############################################################################
10
11def stats(stream):
12 min_inversion = -1
13 max_inversion = -1
14 sum_inversions = 0
15 num_inversions = 0
16 for record in stream:
17 if record.type_name == 'inversion_end':
18 length = record.job.inversion_end - record.job.inversion_start
19 if length > 0:
20 num_inversions += 1
21 if length > max_inversion:
22 max_inversion = length
23 if length < min_inversion or min_inversion == -1:
24 min_inversion = length
25 sum_inversions += length
26 yield record
27 if num_inversions > 0:
28 avg_inversion = int(sum_inversions / num_inversions)
29 else:
30 avg_inversion = 0
31 class Obj(object): pass
32 rec = Obj()
33 rec.record_type = "meta"
34 rec.type_name = "stats"
35 rec.num_inversions = num_inversions
36 rec.min_inversion = min_inversion
37 rec.max_inversion = max_inversion
38 rec.avg_inversion = avg_inversion
39 yield rec