-
Notifications
You must be signed in to change notification settings - Fork 0
/
MiscFct.py
98 lines (83 loc) · 2.32 KB
/
MiscFct.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
96
97
98
#!/usr/bin/python3
import os
############################################################################################
# Auxiliary functions
############################################################################################
def getFilename(fullname):
head, tail = os.path.split(fullname)
filename, file_extension = os.path.splitext( tail )
return filename
def filterResults( results, col, value):
filtResults = []
for line in results:
if line[col - 1] == value:
filtResults.append(line)
return filtResults
def filterSeveralResults( results, col, values):
filtResults = []
for line in results:
for v in values:
if line[col - 1] == v:
filtResults.append(line)
break
return filtResults
def findColumn( line, keyword):
for i in range( len( line ) ):
if line[i] == keyword:
return i
return -1
# Returns an array of [ detail, name ]
def resultsGetDetails( results, col):
members = []
for line in results:
value = line[col - 1]
if value not in members:
members.append( value )
outMembers = []
for line in members:
outMembers.append([line, line])
return outMembers
# Find name in mappins
def findMap( mappings, config):
name = config
for line in mappings:
if line[0] == config:
name = line[1]
return name
return name
# Find name in mappins
def translateMappings( mappings, details):
outDetails = []
for line in details:
outDetails.append( [line[0], findMap( mappings, line[0] )] )
return outDetails
def readResults(fname):
resultsTable = []
if os.path.isfile(fname):
print("Reading results!!")
for line in open(fname).readlines():
if not line.startswith("#"):
resultsTable.append(line.split())
return resultsTable
def readResultsHeader(fname):
if os.path.isfile(fname):
print("Finding header!!")
for line in open(fname).readlines():
if line.startswith("#"):
return line[1:].split()
def replaceLabelChars(label):
label = label.replace('_', '\\_')
return label
def processLabel(label):
if label != "":
#label = label[:-3]
label = replaceLabelChars( label )
return label
def formatNumber(value):
if isinstance(value, str):
if value == "--" or value == "NaN":
return value
else:
assert(0)
value = float(value)
return str("%.2f" % ( value ) )