summaryrefslogtreecommitdiff
path: root/tableconversion.py
blob: 5fc74a630e6728bad81dec32dbc47b5ccbd18db2 (plain)
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
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)

    wires = data['cables']
    connectors = data['connectors']
    connections = data['connections']
    wire_info = []
    for connection in connections:
        #print(connection[0])
        connectorwpin = str(connection[0])
        connector = connectorwpin[2:connectorwpin.find("':")]
        connectorpins = connectorwpin[connectorwpin.find(" [")+2:connectorwpin.rfind("]}")].strip(" ").split(",")

        connectorwires = str(connection[1])
        bundle = connectorwires[2:connectorwires.find("':")]
        bundlewires = connectorwires[connectorwires.find(" [")+2:connectorwires.rfind("]}")].split(",")
        print(connectorpins)
        if len(connection) > 2:
            connector2wpin = str(connection[2])
            connector2 = connector2wpin[2:connector2wpin.find("':")]
            connector2pins = connector2wpin[connector2wpin.find(" [")+2:connector2wpin.rfind("]}")].split(",")

            for x in range(0,len(connectorpins)):
                print(wires[bundle]['length'])
                wire_info.append({
                    'End 1': connector,
                    'Pin 1': connectorpins[x],
                    'Length': wires[bundle]['length'],
                    'Color': wires[bundle]['colors'][x],
                    'Gauge': wires[bundle]['gauge'],
                    'End 2': connector2,
                    'Pin 2': connector2pins[x],
                })




        #print(connection[1])
    

    for wire in wires:
        wire_name = wire
        length = wires[wire]['length']


    # Create a DataFrame to display the data as a table
    wire_df = pd.DataFrame(wire_info, columns=['End 1', 'Pin 1', 'Length', 'Color', 'Gauge', 'End 2', 'Pin 2'])
    return wire_df

# Path to your WireViz YML file
file_path = 'wireviz\Choppy_IB_1X.yml'
wire_table = parse_wireviz_yml(file_path)

# Display the table
print(wire_table)