-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractPerformance.py
95 lines (74 loc) · 3.2 KB
/
extractPerformance.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import numpy as np
import sys
import getopt
import os
##we want to read files once, read the whole file and throw away columns we dont need from a numpy array
#use global variables to be able change whatever u want, for example columns number to add or remove
def getData(name):
array = np.genfromtxt(name, delimiter=",", skip_header=62, skip_footer=13764, usecols=(0,1,2,3,4,59,60,61), dtype=None)
return array
def getProblems(name):
array = np.empty(shape=10, dtype="S10")
array[0:] = np.genfromtxt(name, delimiter=",", skip_header=62, skip_footer=13764, usecols=(0), dtype=None)
return array
def getStatus(name):
array = np.genfromtxt(name, delimiter=",", skip_header=62, skip_footer=13764, usecols=(1), dtype=None)
return array
def getUserTime(name):
array = np.genfromtxt(name, delimiter=",", skip_header=62, skip_footer=13764, usecols=(2), dtype=None)
return array
def getFailure(name):
array = np.genfromtxt(name, delimiter=",", skip_header=62, skip_footer=13764, usecols=(3), dtype=None)
return array
def getPreprocessingTime(name):
array = np.genfromtxt(name, delimiter=",", skip_header=62, skip_footer=13764, usecols=(4), dtype=None)
return array
def getHeuristic(name):
array = np.genfromtxt(name, delimiter=",", skip_header=62, skip_footer=13764, usecols=(59), dtype=None)
return array
def getType(name):
array = np.genfromtxt(name, delimiter=",", skip_header=62, skip_footer=13764, usecols=(60), dtype=None)
return array
def getEquational(name):
array = np.genfromtxt(name, delimiter=",", skip_header=62, skip_footer=13764, usecols=(61), dtype=None)
return array
## we need status and time, no need for combination between them.
##give cell with no data, a zero for example,
##first try to cluster, upon success or no success, get sth simple work first then upgrade
def getNumericalStatus(status, time):
result = [999999.9]*(len(status))
for i in [i for i,x in enumerate(status) if x == "T"]:
result[i] = 100.0 * float(time[i])
return result
def performanceVectors(heuristicsDir):
file1 = os.listdir(heuristicsDir)[1]
allFiles = os.listdir(heuristicsDir)
filesCount = len([i for i,x in enumerate(allFiles) if x.endswith(".csv")])
vectors = np.empty((filesCount+1,11),dtype="S10")
vectors[0][0] = "Problem/Heuristic"
vectors[0][1:] = getProblems(file1)[:]
counter = 1
for file in allFiles:
if file.endswith(".csv"):
vectors[counter][0] = os.path.basename(file)[16:-4]
vectors[counter][1:] = getNumericalStatus(getStatus(file), getUserTime(file))[:]
counter += 1
return vectors
def main(argv):
try:
opts, args = getopt.getopt(argv, "hi:", ["ifile="])
except getopt.GetoptError:
print 'extractPerformance.py -i <inputfile>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'extractPerformance -i <inputfile>'
sys.exit()
elif opt == '-i':
inputfile = arg
if (os.path.isdir(inputfile)):
print performanceVectors(inputfile)
else:
print "Please enter a valid Directory"
if __name__ == "__main__":
main(sys.argv[1:])