fix average calculation to be blocks over time

This commit is contained in:
Arvid Norberg 2009-05-25 07:42:55 +00:00
parent 55b598cbba
commit e7967a9c7c
1 changed files with 9 additions and 4 deletions

View File

@ -19,6 +19,7 @@ out = open('disk_buffer_log.dat', 'w+')
field_sum = {} field_sum = {}
field_num_samples = {} field_num_samples = {}
field_timestamp = {}
for c in key_order: for c in key_order:
keys.append(c) keys.append(c)
@ -26,6 +27,7 @@ for c in key_order:
maximum[c] = 0 maximum[c] = 0
field_sum[c] = 0 field_sum[c] = 0
field_num_samples[c] = 0 field_num_samples[c] = 0
field_timestamp[c] = 0
last_t = 0 last_t = 0
for l in lines: for l in lines:
@ -47,12 +49,15 @@ for l in lines:
keys.append(c) keys.append(c)
fields[c] = 0 fields[c] = 0
maximum[c] = 0 maximum[c] = 0
field_sum[c] = 0
field_num_samples[c] = 0
field_timestamp[c] = 0
field_sum[c] += fields[c] * float(t - field_timestamp[c])
field_timestamp[c] = t
fields[c] = n fields[c] = n
field_sum[c] += n
field_num_samples[c] += 1
if n > maximum[c]: maximum[c] = n if n > maximum[c]: maximum[c] = n
if last_t != t: if last_t != t:
@ -60,7 +65,7 @@ for l in lines:
maximum = fields maximum = fields
for i in keys: for i in keys:
print '%s: avg: %f' % (i, float(field_sum[i]) / float(field_num_samples[i])) print '%s: avg: %f' % (i, field_sum[i] / last_t)
print print
out.close() out.close()