-
Notifications
You must be signed in to change notification settings - Fork 4
/
sram.py
executable file
·57 lines (46 loc) · 1.64 KB
/
sram.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
#!/usr/bin/env python3
import os
import yaml
import json
import sys
from tabulate import tabulate
def main():
if len(sys.argv) == 1:
print("Usage: {} <desired.json> <files>".format(sys.argv[0]))
sys.exit(1)
with open(sys.argv[1], "r") as f:
build_bazel = json.load(f)
srams = {}
for filename in sys.argv[2:]:
with open(filename, "r") as f:
key = os.path.splitext(os.path.basename(filename))[0].replace(
"_floorplan", ""
)
srams[key] = (
srams.get(key, {})
| yaml.load(f, Loader=yaml.FullLoader)
| build_bazel[key]
)
list_of_list_of_all_columns = [list(sram.keys()) for sram in srams.values()]
all_columns = sorted(
list(set([item for sublist in list_of_list_of_all_columns for item in sublist]))
)
order = ["aspect_ratio", "width", "height"]
all_columns = order + [col for col in all_columns if col not in order]
table_data = []
table_data.append(["Name"] + all_columns)
for sram, values in srams.items():
basename_without_ext = os.path.splitext(os.path.basename(sram))[0]
row = [basename_without_ext] + [
(
f"{float(values.get(col, '')):>10.2f}"
if isinstance(values.get(col, ""), (int, float))
or values.get(col, "").replace(".", "", 1).isdigit()
else str(values.get(col, ""))
)
for col in all_columns
]
table_data.append(row)
print(tabulate(table_data, headers="firstrow", tablefmt="pipe"))
if __name__ == "__main__":
main()