Spaces:
Sleeping
Sleeping
File size: 2,664 Bytes
aa68450 eb58c95 aa68450 eb58c95 aa68450 f80e04a e8fb6a3 aa68450 f80e04a aa68450 e8fb6a3 aa68450 e8fb6a3 aa68450 e8fb6a3 aa68450 e8fb6a3 aa68450 e8fb6a3 aa68450 e8fb6a3 120dad2 e8fb6a3 |
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 |
from collections import Counter
import streamlit as st
import json
from itertools import islice
from typing import Generator
from plotly import express as px
def chunks(data: dict, size=13) -> Generator:
it = iter(data)
for i in range(0, len(data), size):
yield {k: data[k] for k in islice(it, size)}
def get_tree_map_data(
data: dict,
countings_parents: dict,
countings_labels: dict,
root: str = " ",
) -> tuple:
names: list = [""]
parents: list = [root]
values: list = ["0"]
for group, labels in data.items():
names.append(group)
parents.append(root)
if group in countings_parents:
values.append(str(countings_parents[group]))
else:
values.append("0")
for label in labels:
if "-" in label:
label = label.split("-")
label = label[0] + "<br> -" + label[1]
names.append(label)
parents.append(group)
if label in countings_labels:
values.append(str(countings_labels[label]))
else:
values.append("0")
# if "-" in label:
# names.append(label.split("-")[0])
# parents.append(label)
# names.append(label.split("-")[1])
# parents.append(label)
return parents, names, values
def load_json(path: str) -> dict:
with open(path, "r") as fp:
return json.load(fp)
# Load Data
data = load_json("data.json")
taxonomy = load_json("taxonomy_processed_v3.json")
theme_counts = dict(Counter([el["THEMA"] for el in data]))
labels_counts = dict(Counter([el["BEZEICHNUNG"] for el in data]))
taxonomy = taxonomy
names = [""]
parents = ["Musterdatenkatalog"]
taxonomy_group_label_mapper: dict = {el["group"]: [] for el in taxonomy}
for el in taxonomy:
if el["group"] != "Sonstiges":
taxonomy_group_label_mapper[el["group"]].append(el["label"])
else:
taxonomy_group_label_mapper[el["group"]].append("Sonstiges ")
parents, name, values = get_tree_map_data(
data=taxonomy_group_label_mapper,
countings_parents=theme_counts,
countings_labels=labels_counts,
root="Musterdatenkatalog",
)
# fig = go.Figure(
# go.Treemap(
# labels=name,
# parents=parents,
# root_color="white",
# values=values,
# # textinfo="label+value",
# ),
# )
fig = px.treemap(
names=name,
parents=parents,
)
fig.update_layout(
margin=dict(t=50, l=25, r=25, b=25),
height=1000,
width=1000,
template="plotly",
)
st.title("Musterdatenkatalog")
st.plotly_chart(fig)
|