|
import streamlit as st |
|
from collections import Counter |
|
|
|
from data_manager import get_data |
|
from data_manager_bziiit import get_labels, get_engaged_brands |
|
|
|
def display_rse_labels(): |
|
st.markdown("## OPEN DATA bziiit Labels RSE") |
|
st.markdown("### Découvrez les labels et certifications (RSE, Qualité...)") |
|
|
|
labels_option = st.radio( |
|
"Choisissez les labels à afficher :", |
|
("Labels / Certifications des organisations engagées Bdx Métropole", "Tous les labels / Certifications DATA bziiit") |
|
) |
|
|
|
|
|
st.markdown("""<hr style='border-color: darkgrey;'>""", unsafe_allow_html=True) |
|
|
|
labels = get_labels() |
|
|
|
if labels_option == "Tous les labels / Certifications DATA bziiit": |
|
labels.sort(key=lambda x: x['name']) |
|
else: |
|
|
|
data, _ = get_data() |
|
|
|
|
|
engaged_brands = get_engaged_brands() |
|
|
|
|
|
org_names = set(org['nom_courant_denomination'] for org in data if 'nom_courant_denomination' in org) |
|
|
|
|
|
engaged_brands = [brand for brand in engaged_brands if brand['name'] in org_names] |
|
|
|
|
|
org_labels = [label['name'] for brand in engaged_brands if 'labels' in brand and brand['labels'] for label in brand['labels']] |
|
|
|
|
|
label_counts = Counter(org_labels) |
|
|
|
|
|
labels = [{'name': label['name'], 'logo_url': label['logo_url'], 'count': label_counts[label['name']]} for label in labels if label['name'] in label_counts] |
|
|
|
|
|
labels.sort(key=lambda x: x['count'], reverse=True) |
|
|
|
|
|
unique_labels = set(label['name'] for label in labels) |
|
st.markdown(f"**Nombre de labels / certifications :** {len(unique_labels)}") |
|
|
|
|
|
for i in range(0, len(labels), 5): |
|
cols = st.columns(5) |
|
for j in range(5): |
|
if i + j < len(labels): |
|
label = labels[i + j] |
|
with cols[j]: |
|
st.image(label['logo_url']) |
|
if labels_option == "Tous les labels / Certifications DATA bziiit": |
|
st.markdown(f'<p style="text-align: center; font-size: 10px;"><a href="{label["website"]}" style="color: darkgray;">Site web</a></p>', unsafe_allow_html=True) |
|
else: |
|
st.markdown(f'<p style="text-align: center; font-size: 10px; color: darkgray;">Nb marques certifiées : {label["count"]}</p>', unsafe_allow_html=True) |
|
|