Skip to content

Commit deb80f2

Browse files
krzysztof-kwittcpcloud
authored andcommitted
docs: clean up gen_matrix.py after adding streamlit app
1 parent 012da8c commit deb80f2

File tree

2 files changed

+12
-52
lines changed

2 files changed

+12
-52
lines changed

docs/backends/app/backend_info_app.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ def load_ops_data():
1919
reader = csv.DictReader(response.text.splitlines())
2020

2121
data = [
22-
{k: v if k == "Backends" else v == "True" for k, v in row.items()}
22+
{k: v if k == "FullOperation" else v == "True" for k, v in row.items()}
2323
for row in reader
2424
]
2525
for row in data:
26-
row["FullOperation"] = row['Backends']
27-
del row['Backends']
2826
row['ShortOperation'] = row['FullOperation'].rsplit(".")[4]
2927
row['OpCategory'] = row['FullOperation'].rsplit(".")[3]
3028
return data

gen_matrix.py

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,65 +33,27 @@ def get_leaf_classes(op):
3333
ops.ScalarParameter,
3434
}
3535

36-
GEOSPATIAL_OPS = frozenset(get_leaf_classes(ops.GeoSpatialUnOp)) | frozenset(
37-
get_leaf_classes(ops.GeoSpatialBinOp)
38-
)
36+
PUBLIC_OPS = (frozenset(get_leaf_classes(ops.Value))) - INTERNAL_OPS
3937

40-
CORE_OPS = (frozenset(get_leaf_classes(ops.Value))) - INTERNAL_OPS - GEOSPATIAL_OPS
41-
42-
ICONS = {
43-
True: ":material-check-decagram:{ .verified }",
44-
False: ":material-cancel:{ .cancel }",
45-
}
46-
47-
48-
def gen_matrix(basename, possible_ops, raw_data_format=False):
49-
if raw_data_format:
50-
support = {
51-
"operation": [f"{op.__module__}.{op.__name__}" for op in possible_ops]
52-
}
53-
else:
54-
support = {"operation": [f"`{op.__name__}`" for op in possible_ops]}
5538

39+
def main():
40+
support = {"operation": [f"{op.__module__}.{op.__name__}" for op in PUBLIC_OPS]}
5641
support.update(
57-
(name, list(map(backend.has_operation, possible_ops)))
42+
(name, list(map(backend.has_operation, PUBLIC_OPS)))
5843
for name, backend in get_backends()
5944
)
6045

6146
df = pd.DataFrame(support).set_index("operation").sort_index()
62-
if not raw_data_format:
63-
counts = df.sum().sort_values(ascending=False)
64-
counts = counts[counts > 0]
65-
num_ops = len(possible_ops)
66-
coverage = (
67-
counts.map(lambda n: f"_{n} ({round(100 * n / num_ops)}%)_")
68-
.to_frame(name="**API Coverage**")
69-
.T
70-
)
71-
72-
ops_table = df.loc[:, counts.index].replace(ICONS)
73-
table = pd.concat([coverage, ops_table])
74-
else:
75-
table = df
76-
77-
file_path = Path("backends", f"{basename}_support_matrix.csv")
78-
local_pth = Path(__file__).parent / "docs" / file_path
47+
48+
file_path = Path("backends", "raw_support_matrix.csv")
49+
local_path = Path(__file__).parent / "docs" / file_path
50+
7951
buf = io.StringIO()
80-
table.to_csv(buf, index_label="Backends")
81-
local_pth.write_text(buf.getvalue())
52+
df.to_csv(buf, index_label="FullOperation")
53+
54+
local_path.write_text(buf.getvalue())
8255
with mkdocs_gen_files.open(file_path, "w") as f:
8356
f.write(buf.getvalue())
8457

8558

86-
def main():
87-
gen_matrix(basename="core", possible_ops=CORE_OPS)
88-
gen_matrix(
89-
basename="geospatial",
90-
possible_ops=GEOSPATIAL_OPS,
91-
)
92-
gen_matrix(
93-
basename="raw", possible_ops=CORE_OPS | GEOSPATIAL_OPS, raw_data_format=True
94-
)
95-
96-
9759
main()

0 commit comments

Comments
 (0)