-
Notifications
You must be signed in to change notification settings - Fork 0
/
Morpho_scores_list.py
51 lines (36 loc) · 2.04 KB
/
Morpho_scores_list.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
# Name : Morpho_scores_list.py
# Objective : create scores listes .csv from raw files generated by Morpho algorithms (MFI/MFE)
# Created by : mjacquet
# Last version : 05.04.2021
import os
def make_scorelist(path1, path2) :
for d in os.listdir( path1 ) :
if not os.path.exists( path2 + d ) :
os.makedirs( path2 + d )
for f in os.listdir( path1 + d ) :
lstimg = []
lstscore = []
lstdecision = []
filename, _ = os.path.splitext( os.path.basename( path1 + d + "/" + f ) )
img1 = filename.replace( "person_to_person_match_response_encode_person_response_", "" )
with open( path1 + d + "/" + f, 'r' ) as input :
for line in input :
if "id: " in line :
if not img1 in line :
firstline = line.strip().rstrip( '\n' ) # strip() removes whitespace surrounding the line
secondline = next( input ).strip().rstrip( '\n' )
img = firstline.replace( "id: ", "" )
img2 = img.replace( '"', "" )
if "score:" in secondline :
score = secondline.replace( "score: ", "" )
lstimg.append( img2 )
lstscore.append( score )
if "decision:" in line :
decision = line.replace( " decision: ", "" )
lstdecision.append( decision )
for i, s, h in zip( lstimg, lstscore, lstdecision ) :
with open( path2 + d + "/" + img1[:3] + ".csv", 'a' ) as output :
if i != img1 :
output.write( "%s;%s;%s;%s" % (img1, i, s, h) )
make_scorelist( "C:/Users/mjacquet.AD/Desktop/THESE/MANIP_DEV_MODEL/MFI/Raw_files/pop_triee/female/",
"C:/Users/mjacquet.AD/Desktop/THESE/MANIP_DEV_MODEL/TEST/" )