aboutsummaryrefslogtreecommitdiffstats
path: root/xilinx.py
blob: d7dcf996957cbd7a6b3a9f4bad4af0d4102acdda (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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

import partdb
import csv

def load_csv(path):
    table = []
    with open(path, 'r') as f:
        csv_reader = csv.reader(f)
        for row in csv_reader:
            table.append(row)
    return table

def process_csv(data_path, shared_path, speed_grades, temp_grade):
    raw_specs = load_csv(shared_path)
    raw_data = load_csv(data_path)
    split_row = 0

    # find row split between data and pins
    for i in range(len(raw_data)):
        if raw_data[i][0] == "###":
            split_row = i
            break

    package_table = raw_data[split_row+1:]
    prefix_list = raw_data[0][1:]

    # infill sparse prefix_lists (eg, for xilinx zynq)
    last = None
    for i in range(len(prefix_list)):
        if not prefix_list[i]:
            prefix_list[i] = last
        else:
            last = prefix_list[i]

    suffix_row = [list() for i in range(len(prefix_list))]
    bom = []
    for row_num in range(len(package_table)):
        package = package_table[row_num][0]
        for cell_num in range(len(package_table[row_num][1:])):
            cell = package_table[row_num][cell_num+1].strip()
            if cell:
                for speed_grade in speed_grades:
                    suffix = speed_grade + package + temp_grade
                    mpn = prefix_list[cell_num] + suffix
                    bom.append(('Xilinx', mpn))
                    suffix_row[cell_num].append(dict(mpn=mpn, suffix=suffix))

    shared_specs = dict()
    for row in raw_specs:
        shared_specs[row[0]] = row[1]

    data_table = []
    span = 1
    for raw_row in raw_data[:split_row]:
        row = [[1, raw_row[0]], ]
        for raw_cell in raw_row[1:]:
            if raw_cell:
                row.append([1, raw_cell.replace('n/a', '-')])
            else:
                row[-1][0] += 1
        data_table.append(row)

    partdb.ensure_bom(bom)
    price_row = [None for i in range(len(prefix_list))]
    for i in range(len(prefix_list)):
        bom = [('Xilinx', suf['mpn']) for suf in suffix_row[i]]
        price_row[i] = partdb.best_price_info(bom)

    # attach URLs to suffix row entries
    for cell_num in range(len(suffix_row)):
        cell = suffix_row[cell_num]
        for part_num in range(len(cell)):
            part = cell[part_num]
            p = ('Xilinx', part['mpn'])
            part['url'] = partdb.part_url(p)
            cell[part_num] = part
        suffix_row[cell_num] = cell

    return dict(shared_specs=shared_specs,
                data_table=data_table,
                price_row=price_row,
                package_table=package_table,
                suffix_row=suffix_row)

today = partdb.today

spartan3a_grid = process_csv(
    'xilinx_data/spartan3a.csv',
    'xilinx_data/spartan3a_shared.csv',
    speed_grades=['-4',],
    temp_grade='C')
spartan3a_grid['vendor'] = "Xilinx"
spartan3a_grid['familyname'] = "Spartan3A"

virtex6_grid = process_csv(
    'xilinx_data/virtex6.csv',
    'xilinx_data/virtex6_shared.csv',
    speed_grades=['-1', '-2'],
    temp_grade='C') # E, I
virtex6_grid['vendor'] = "Xilinx"
virtex6_grid['familyname'] = "Virtex6"

virtex7_grid = process_csv(
    'xilinx_data/virtex7.csv',
    'xilinx_data/virtex7_shared.csv',
    speed_grades=['-1', '-2'],
    temp_grade='C') # E, I
virtex7_grid['vendor'] = "Xilinx"
virtex7_grid['familyname'] = "Virtex7"

kintex7_grid = process_csv(
    'xilinx_data/kintex7.csv',
    'xilinx_data/kintex7_shared.csv',
    speed_grades=['-1', '-2'],
    temp_grade='C') # E, I
kintex7_grid['vendor'] = "Xilinx"
kintex7_grid['familyname'] = "Kintex7"

artix7_grid = process_csv(
    'xilinx_data/artix7.csv',
    'xilinx_data/artix7_shared.csv',
    speed_grades=['-2', '-3'],
    temp_grade='C') # E, I
artix7_grid['vendor'] = "Xilinx"
artix7_grid['familyname'] = "Artix7"

spartan6_grid = process_csv(
    'xilinx_data/spartan6.csv',
    'xilinx_data/spartan6_shared.csv',
    speed_grades=['-2', '-3'],
    temp_grade='C')
spartan6_grid['vendor'] = "Xilinx"
spartan6_grid['familyname'] = "Spartan6"

zynq7000_grid = process_csv(
    'xilinx_data/zynq7000.csv',
    'xilinx_data/zynq7000_shared.csv',
    speed_grades=['-1'],
    temp_grade='C')
zynq7000_grid['vendor'] = "Xilinx"
zynq7000_grid['familyname'] = "Zynq7000"