-
Notifications
You must be signed in to change notification settings - Fork 8
/
summary2cvs.py
103 lines (87 loc) · 3.78 KB
/
summary2cvs.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
99
100
101
102
103
import os
import subprocess
# meant to be run in the parent directory of the directories generated by Sango simulations
old = True
# allParamKeys = ['nbMSN','nbFSI','nbSTN','nbGPe','nbGPi','nbCSN','nbPTN','nbCMPf','GMSN','GFSI','GSTN','GGPe','GGPi','IeGPe','IeGPi','inDegCSNMSN','inDegPTNMSN','inDegCMPfMSN','inDegFSIMSN','inDegMSNMSN','inDegCSNFSI','inDegPTNFSI','inDegSTNFSI','inDegGPeFSI','inDegCMPfFSI','inDegFSIFSI','inDegPTNSTN','inDegCMPfSTN','inDegGPeSTN','inDegCMPfGPe','inDegSTNGPe','inDegMSNGPe','inDegGPeGPe','inDegMSNGPi','inDegSTNGPi','inDegGPeGPi','inDegCMPfGPi',]
paramKeys = ['GMSN','GFSI','GSTN','GGPe','GGPi','IeGPe','IeGPi','inDegCSNMSN','inDegPTNMSN','inDegCMPfMSN','inDegFSIMSN','inDegMSNMSN','inDegCSNFSI','inDegPTNFSI','inDegSTNFSI','inDegGPeFSI','inDegCMPfFSI','inDegFSIFSI','inDegPTNSTN','inDegCMPfSTN','inDegGPeSTN','inDegCMPfGPe','inDegSTNGPe','inDegMSNGPe','inDegGPeGPe','inDegMSNGPi','inDegSTNGPi','inDegGPeGPi','inDegCMPfGPi','nbMSN','nbFSI','nbSTN','nbGPe','nbGPi','nbCSN','nbPTN','nbCMPf',]
fOut = open('resWrapUp.csv','w')
fBestOut = open('resBestOnlyWrapUp.csv','w')
nbMax = 0
# header of the wrap-up file :
#-----------------------------
outStr = 'LG14ID, score'
for k in paramKeys:
outStr += ', '+k
outStr+=' \n'
fOut.writelines(outStr)
fBestOut.writelines(outStr)
# processing the various subdirectories containing simulation results
#-----------------------------
dirs = os.listdir('.')
nbFailures = 0
nbParameterizations = 0
for d in dirs:
if ('2017' in d) and ('.txt' not in d): # filters out files & directories that do not comply with the data format, including this .py file!
nbParameterizations += 1
# retrieve the score
#-----------------------------
score = -1.
# get the score with old way of handling results (data from 24/01/17):
if old == True:
os.chdir(d+'/log')
filez = os.listdir('.')
for f in filez:
if 'OutSummary' in f:
sf = open(f,"r")
scoreLine = sf.readlines()[-1].split()
if len(scoreLine)==4:
score = float(scoreLine[1])
if float(scoreLine[1]) == 14.0:
nbMax += 1
print d,score
else:
print d,'Execution problem',scoreLine
nbFailures += 1
sf.close()
os.chdir('..') # goes back from log subdirectory to 2017* dir
# get the score with new way of handling results:
else:
os.chdir(d)
filez = os.listdir('.')
scoreFileFound = False
for f in filez:
if 'score.txt' in f:
scoreFileFound = True
if scoreFileFound:
sf = open('score.txt','r')
score = float(sf.readlines()[0])
print d,score
else:
nbFailures += 1
print d,'score.txt file not found'
# retrieve the parameters from modelParams.py
#-----------------------------
pf = open('modelParams.py','r')
pLines = pf.readlines()
pf.close()
d = {} # a temporary dictionary to store the retrieved parameters
for line in pLines:
lineList = line.split(':')
if len(lineList)>1: # if there is more that one element, a ':' was found in the string, thus we are on a parameter line
key = lineList[0].split("'")[1]
value = float(lineList[1].split(",")[0])
d[key]=value
# write the score and the parameters in the wrap up file
#-----------------------------
outStr = str(d['LG14modelID'])+', '+str(score)
for k in paramKeys:
outStr += ', %4.2f' %d[k]
outStr += ' \n'
fOut.writelines(outStr)
if score == 14.0:
fBestOut.writelines(outStr)
os.chdir('..') # goes back from 2017* directory to main data dir
fOut.close()
fBestOut.close()
print "Found",nbMax,"good parameterizations, over",nbParameterizations,"tested."
print nbFailures,'failures to load score data.'