-
Notifications
You must be signed in to change notification settings - Fork 0
/
calcJaneCost.py
71 lines (52 loc) · 1.2 KB
/
calcJaneCost.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# calcJaneCost.py
#
# Weiyun Ma
# May 2016
#
# This file calculates the total cost of the reconciliation for
# each file in the janeOut folder. It writes the results
# into corresponding .txt files in the janeCosts folder.
#
# Run with
# python calcJaneCost.py
import os
import os.path
from cStringIO import StringIO
# Global variables (can be customized in the future)
dVal = 2
tVal = 3
lVal = 1
def main():
if not os.path.exists("janeCosts"):
os.mkdir("janeCosts")
for i in xrange(6000):
index = str(i + 1)
for j in xrange(4 - len(str(i + 1))):
index = "0" + index
f = "janeOut/COG" + index + ".txt"
if not os.path.isfile(f):
continue
inFile = open(f, 'r')
ans = 0
for line in inFile:
if line.startswith("Duplication: "):
num = int(line[13:])
ans += num * dVal
print num
elif line.startswith("Host Switch: "):
num = int(line[12:])
ans += num * tVal
print num
elif line.startswith("Loss: "):
num = int(line[6:])
ans += num * lVal
print num
print ans
inFile.close()
f = "janeCosts/COG" + index + ".txt"
outFile = open(f, 'w')
outFile.write(str(ans))
outFile.close()
print "Done ", index
if __name__ == "__main__":
main()