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
|
import yaml
import numpy
import pandas as pd
def parse_wireviz_yml(file_path):
# Load the WireViz YML file
with open(file_path, 'r') as file:
data = yaml.safe_load(file)
idcount = 0
wires = data['cables']
connectors = data['connectors']
connections = data['connections']
connectorlist = []
for connector in data['connectors']:
connectorlist.append(connector)
#print(connectors['ECU']['pins'])
wire_info = []
for connection in connections:
connectorwpin = str(connection[0])
connector = connectorwpin[2:connectorwpin.find("':")]
connectorwires = str(connection[1])
if (len(connection)==2)and(connectorlist.count(connector) < 1):
connectorwpin = str(connection[1])
connector = connectorwpin[2:connectorwpin.find("':")]
connectorwires = str(connection[0])
#currently skipping all abnormal conditions
if connectorlist.count(connector) < 1:
continue
connectorpins = connectorwpin[connectorwpin.find(" [")+2:connectorwpin.rfind("]}")].strip(" ").split(",")
connectorpinsadjusted = []
for pins in connectorpins:
if str(pins).count("-") > 0:
pinrange = pins.strip("' ").split("-")
for x in range(int(pinrange[0]),int(pinrange[1])+1):
connectorpinsadjusted.append(x)
else:
connectorpinsadjusted.append(pins)
bundle = connectorwires[2:connectorwires.find("':")]
bundlewires = connectorwires[connectorwires.find(" [")+2:connectorwires.rfind("]}")].split(",")
connector2pinsadjusted = []
if len(connection) > 2:
connector2wpin = str(connection[2])
connector2 = connector2wpin[2:connector2wpin.find("':")]
connector2pins = connector2wpin[connector2wpin.find(" [")+2:connector2wpin.rfind("]}")].split(",")
for pins in connector2pins:
idcount=idcount+1
if pins.count("-") > 0:
pinrange = pins.strip("' ").split("-")
negativesign=0
for pin in pinrange:
if str(connectors[connector]['pins']).count(pin) < 1:
print(pin)
negativesign=1
if not negativesign:
for x in range(int(pinrange[0]),int(pinrange[1])+1):
connector2pinsadjusted.append(x)
else:
connector2pinsadjusted = connector2pins
else:
connector2pinsadjusted = connector2pins
for x in range(0,len(connectorpinsadjusted)):
ident = str(ord(connector[0]))[:1]+str(ord(str(connectorpinsadjusted[x])[-1]))[-1]+str(ord(str(connector2pinsadjusted[x])[-1]))[-1]+str(ord(wires[bundle]['colors'][x][0]))+str(idcount)[-1]
ident = ident.strip(" ")
pin1 = connectorpinsadjusted[x]
notes = "none"
if str(connectors[connector]).count("'pinlabels':"):
if str(connectors[connector]['pinlabels']).count(connectorpinsadjusted[x]):
stringarray= [str(x) for x in connectors[connector]['pinlabels']]
print(stringarray)
print(connectorpinsadjusted)
print(stringarray.index(connectorpinsadjusted[x].strip("\"")))
if str(wires[bundle]).find("'notes':") > 0:
notes = wires[bundle]['notes']
wire_info.append({
'Identifier': ident,
'End 1': connector,
'Pin 1': pin1,
'Length': wires[bundle]['length'],
'Color': wires[bundle]['colors'][x],
'Gauge': wires[bundle]['gauge'],
'End 2': connector2,
'Pin 2': connector2pinsadjusted[x],
'Notes': notes,
})
else:
idcount=idcount+1
for x in range(0,len(connectorpinsadjusted)):
ident = str(ord(connector[0]))[:1]+str(ord(str(connectorpinsadjusted[x])[-1]))[-1]+"0"+str(ord(wires[bundle]['colors'][x][0]))+str(idcount)[-1]
ident = ident.strip(" ")
notes = "none"
if str(wires[bundle]).find("'notes':") > 0:
notes = wires[bundle]['notes']
wire_info.append({
'Identifier': ident,
'End 1': connector,
'Pin 1': connectorpinsadjusted[x],
'Length': wires[bundle]['length'],
'Color': wires[bundle]['colors'][x],
'Gauge': wires[bundle]['gauge'],
'End 2': "----",
'Pin 2': "----",
'Notes': notes,
})
# Create a DataFrame to display the data as a table
wire_df = pd.DataFrame(wire_info, columns=['Identifier','End 1', 'Pin 1', 'Length', 'Color', 'Gauge', 'End 2', 'Pin 2', 'Notes'])
return wire_df
# Path to your WireViz YML file
file_path = 'wireviz/Choppy_ECU_12FB.yml'
wire_table = parse_wireviz_yml(file_path)
# Display the table
print(wire_table)
outputfile = file_path[:-4]+".csv"
wire_table.to_csv(outputfile)
|