· 7 years ago · Oct 04, 2018, 11:46 AM
1#!/usr/bin/env python
2# -*- encoding: UTF8 -*-
3
4# Author: Philipp Klaus, philipp.klaus AT gmail.com
5
6def main():
7
8 ## for small files this is just fine...
9 #f = open("speed_proto_cropped.txt")
10 #for line in f.readlines():
11 # #process(line)
12
13 # for large files we use this:
14 f = open('speed_proto_cropped.txt','r')
15 out = open('speed_proto_cropped_2.txt', 'w')
16 counter = 0
17 mib_before = 0
18 seconds_before=0
19 for line in f.xreadlines():
20 if counter%3==0: # every third line contains information
21 mib_now = int(line.split(' ')[0])/1024.0/1024.0 # calculate the data position from first part of the line, bytes converted to MiB
22 seconds_now = float(line.split(' ')[5]) # 6th part of the line: the time passed until now
23 mib_delta = mib_now-mib_before
24 seconds_delta = seconds_now-seconds_before
25 rate = float(mib_delta)/(seconds_delta)
26 #out.write("%.1f %.1f" % (mib_delta, rate) + '\n')
27 out.write("%.1f %.1f" % (mib_now, rate) + '\n')
28 mib_before=mib_now
29 seconds_before=seconds_now
30 counter+=1
31 f.close()
32 out.close()
33
34if __name__ == '__main__':
35 main()