/
04_comparison_lists_export_guid.py
126 lines (86 loc) · 3.23 KB
/
04_comparison_lists_export_guid.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
### Copyright (c) 2022 Syntegrate
###
### This software is released under the MIT License.
### https://opensource.org/licenses/MIT
import csv
path6 = 'C:\\Users\\Name\\Desktop\\_data\\blockList_sorted.csv'
path7 = 'C:\\Users\\Name\\Desktop\\_data\\ref_distanceList.csv'
path8 = 'C:\\Users\\Name\\Desktop\\_data\\error_ids.csv'
a = []
b = []
def isfloat(string):
try:
float(string)
return True
except ValueError:
return False
def readCsv(path):
aa = []
with open (path, 'r', encoding="utf-8") as f:
reader = csv.reader(f)
for row in reader:
new_row = []
for i in range(len(row)):
#cleanup list elm
r = str(row[i])
r1 = r.replace("'", "")
r2 = r1.replace("[", "")
r3 = r2.replace("]", "")
bool = isfloat(r3)
if bool is True:
ff = float(r3)
new_row.append(ff)
else:
tt = str(r3)
ttt = tt.strip()
new_row.append(ttt)
#delete empty
new_row1 = []
for elem in new_row:
if elem != '':
new_row1.append(elem)
aa.append(new_row1)
print(aa)
return aa
def comparisonOfTwoLists(refList, list1):
ids = []
for i in range(len(list1)):
for j in range(len(refList)):
#search BK
if list1[i] != refList[j] and len(list1[i]) == len(refList[j]):
#search only blockname and position
num = int(len(refList[j]) / 4)
#check block set in reflist and list
tmp_ref_set = []
tmp_list_set = []
for k in range(num):
blcname_id = 1 + k*4
bkname_r = str(refList[j][blcname_id])
bkname_l = str(list1[i][blcname_id])
tmp_ref_set.append(bkname_r)
tmp_list_set.append(bkname_l)
if tmp_ref_set == tmp_list_set:
for m in range(num):
blcpos_id = 2 + m*4
pos_r = float(refList[j][blcpos_id])
pos_l = float(list1[i][blcpos_id])
if pos_r != pos_l:
blcguid = blcpos_id - 2
ids.append(list1[i][blcguid])
else:
pass
else:
pass
else:
pass
#print(ids)
return ids
def writeCsv(path, list):
with open (path, 'w') as f:
writer = csv.writer(f, delimiter='\n')
writer.writerow(list)
print("done2")
blclist = readCsv(path6)
ref = readCsv(path7)
error_blocks = comparisonOfTwoLists(ref, blclist)
writeCsv(path8, error_blocks)