-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist_files_and_meta.py
More file actions
executable file
·54 lines (46 loc) · 975 Bytes
/
Copy pathlist_files_and_meta.py
File metadata and controls
executable file
·54 lines (46 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
"""
Task: List files' metadata
URL: no link
Description: You're given a list of files, each has the following format:
-----
consistency = 'no'
latency = 12
bandwidth = 20
size = 123
width = 234
-----
Parse the files and calculate total bandwidth and average latency.
"""
from os import walk
# import converter
# get filenames
files = []
fstop = 0
fpath = '/Users/dminaev/tmp/tsvfiles/'
ttl_latency = 0
ttl_bandwidth = 0
for (q,w,filenames) in walk(fpath):
files.extend(filenames)
break
# init converter
# conv = new converter()
for fn in files:
f = open(fpath+'/'+fn, 'r')
print fn+"\n====="
for row in f:
fstop = 0
[k,v] = row.split(" = ")
k.strip()
v.strip()
print "k="+k+"\tv="+v
if(k == 'latency'):
ttl_latency += int(v)
fstop+=1
if(k == 'bandwidth'):
ttl_bandwidth += int(v)
fstop+=1
if(fstop >= 2):
break
print 'Total bandwidth: ' + str(ttl_bandwidth)
print 'Avg. latency: ' + str(ttl_latency / len(files))