blob: 695c49c18f2aa4959897bc7df8ca6d7758c25612 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright 2020 The Skywater PDK Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from prettytable import PrettyTable
from glob import glob as gl
import argparse
from pathlib import Path
import pandas as pd
from termcolor import colored
import csv
def try_float(v):
try:
val = float(v)
return val
except:
return v
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('input', type=Path, help='Directory containing wrap files')
parser.add_argument('output', type=Path, help='File containing summary of wrap files')
parser.add_argument('output_csv', type=Path, help='File containing summary of wrap files in CSV format')
args = parser.parse_args()
wrapfiles = sorted(args.input.rglob('*.wrap.json'))
parameters = ['file', 'library']
wrapdata = []
for wrap in wrapfiles:
print(wrap)
with open(wrap, 'r') as data:
lib = json.load(data)
if lib:
wraprow = {}
libname = list(lib.keys())[0]
wraprow['file'] = wrap
wraprow['library'] = libname
for key, value in lib[libname].items():
if type(value) is list:
prefix = key + '_'
for val in value:
if type(val) is str:
k = val.split(',')[0]
v = val.split(',')[1]
if prefix + k not in parameters:
parameters.append(prefix + k)
wraprow[prefix + k] = v
pass
elif type(value) is dict:
prefix = ''
if key.startswith('operating_conditions'):
prefix = 'operating_conditions_'
if 'operating_conditions_libname' not in parameters:
parameters.append('operating_conditions_libname')
wraprow['operating_conditions_libname'] = try_float(key.split(' ', 1)[1])
for k, v in value.items():
if type(v) is not list:
if prefix + k not in parameters:
parameters.append(prefix + k)
wraprow[prefix + k] = try_float(v)
else:
if key != 'define':
if key not in parameters:
parameters.append(key)
wraprow[key] = try_float(value)
wrapdata.append(wraprow)
fintable = []
for entry in wrapdata:
row = []
for parameter in parameters:
if parameter in entry:
row.append(entry[parameter])
else:
row.append('N/A')
fintable.append(row)
with open(args.output, 'w') as out:
t = PrettyTable(parameters)
t.align = 'r'
t.border = False
for line in fintable:
t.add_row(line)
out.write(str(t))
with open(args.output_csv, 'w') as csvfile:
writer = csv.writer(csvfile, delimiter=';', quotechar='"')
writer.writerow(parameters)
for line in fintable:
writer.writerow(line)
df = pd.DataFrame(fintable, columns=parameters)
for col in df:
print(colored(col, 'green'))
print(df[col].unique())