Upload 28 files
Browse files- README.md +2 -0
- app.py +117 -13
- build_data.py +18 -0
- selftest.py +15 -0
- titles.csv +0 -0
README.md
CHANGED
|
@@ -32,6 +32,8 @@ from being a text a teacher can use.
|
|
| 32 |
|
| 33 |
Interface in English by default; a French toggle sits at the top of the page, beside a light/dark switch. Eight tabs: Overview · **Atlas** · Presses · Catalogue · Recovery · Rights · Copies · Methods.
|
| 34 |
|
|
|
|
|
|
|
| 35 |
## What it contains
|
| 36 |
|
| 37 |
| Table | Rows | What it is |
|
|
|
|
| 32 |
|
| 33 |
Interface in English by default; a French toggle sits at the top of the page, beside a light/dark switch. Eight tabs: Overview · **Atlas** · Presses · Catalogue · Recovery · Rights · Copies · Methods.
|
| 34 |
|
| 35 |
+
**No dropdowns.** Every filter — region, decade, language, confidence — is a row of clickable pills in the sidebar. A dropdown hides its options: you have to open it to learn what it contains, and you never see the whole choice at once. Here everything is on screen and takes one click. The language filter is grouped into five answers (English · French · Portuguese · Arabic · African languages) rather than twenty-seven entries nobody would read; the full language of every title stays in the catalogue column and in the search box.
|
| 36 |
+
|
| 37 |
## What it contains
|
| 38 |
|
| 39 |
| Table | Rows | What it is |
|
app.py
CHANGED
|
@@ -338,10 +338,20 @@ RAISON = {
|
|
| 338 |
CONF = ["high", "medium", "low"]
|
| 339 |
|
| 340 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
def lreg(r):
|
| 342 |
return r if LANG == "en" else REGION_FR.get(r, r)
|
| 343 |
|
| 344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
# ------------------------------------------------------------------- cartes
|
| 346 |
# Emprise : le bord ouest va jusqu'a -25,5° pour que le Cabo Verde (-23,8°)
|
| 347 |
# figure sur les cartes. Un pays present dans un classement et absent de toute
|
|
@@ -557,6 +567,30 @@ def choix(options, cle, defaut=None, format_func=None, ou=st, etiquette=None):
|
|
| 557 |
label_visibility="collapsed")
|
| 558 |
|
| 559 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
def _bascule(libelles, cle):
|
| 561 |
inverse = {v: k for k, v in libelles.items()}
|
| 562 |
courant = inverse[st.session_state[cle]]
|
|
@@ -628,6 +662,23 @@ st.markdown(f"""<style>
|
|
| 628 |
hr {{ border-color: {PAL['cadre']}; }}
|
| 629 |
a {{ color: {PAL['accent']}; }}
|
| 630 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 631 |
.abrp-tiles {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(158px,1fr));
|
| 632 |
gap: .6rem; margin: 1.1rem 0 1.3rem 0; }}
|
| 633 |
.abrp-tile {{ background: {PAL['panneau']}; border: 1px solid {PAL['cadre']};
|
|
@@ -679,8 +730,33 @@ st.markdown(f"""<style>
|
|
| 679 |
[data-testid="stButtonGroup"] button[kind="pillsActive"] *,
|
| 680 |
[data-baseweb="button-group"] button[aria-checked="true"] * {{
|
| 681 |
color: {PAL['sur_accent']} !important; }}
|
| 682 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 683 |
color: {PAL['texte']} !important; }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 684 |
</style>""", unsafe_allow_html=True)
|
| 685 |
|
| 686 |
|
|
@@ -690,19 +766,47 @@ with st.sidebar:
|
|
| 690 |
st.caption(t("African authors · African presses · c. 1950–1979"))
|
| 691 |
st.divider()
|
| 692 |
st.markdown(f"**{t('Filters')}**")
|
| 693 |
-
st.caption(bil("
|
| 694 |
-
"
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 703 |
q = st.text_input(t("Search"), key="f_q",
|
| 704 |
placeholder=bil("title, author or press",
|
| 705 |
"titre, auteur ou maison"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
st.divider()
|
| 707 |
st.caption(bil(
|
| 708 |
"Every record carries its sources and a confidence flag. Nothing is "
|
|
@@ -716,8 +820,8 @@ with st.sidebar:
|
|
| 716 |
def filtrer(d):
|
| 717 |
if f_reg:
|
| 718 |
d = d[d["region"].isin(f_reg)]
|
| 719 |
-
if f_lang and "
|
| 720 |
-
d = d[d["
|
| 721 |
if f_dec and "decade" in d.columns:
|
| 722 |
d = d[d["decade"].isin(f_dec)]
|
| 723 |
if f_conf:
|
|
|
|
| 338 |
CONF = ["high", "medium", "low"]
|
| 339 |
|
| 340 |
|
| 341 |
+
LANG_GROUPE_FR = {"English": "Anglais", "French": "Français",
|
| 342 |
+
"Portuguese": "Portugais", "Arabic": "Arabe",
|
| 343 |
+
"African languages": "Langues africaines",
|
| 344 |
+
"Unrecorded": "Non renseignée"}
|
| 345 |
+
|
| 346 |
+
|
| 347 |
def lreg(r):
|
| 348 |
return r if LANG == "en" else REGION_FR.get(r, r)
|
| 349 |
|
| 350 |
|
| 351 |
+
def lgrp(g):
|
| 352 |
+
return g if LANG == "en" else LANG_GROUPE_FR.get(g, g)
|
| 353 |
+
|
| 354 |
+
|
| 355 |
# ------------------------------------------------------------------- cartes
|
| 356 |
# Emprise : le bord ouest va jusqu'a -25,5° pour que le Cabo Verde (-23,8°)
|
| 357 |
# figure sur les cartes. Un pays present dans un classement et absent de toute
|
|
|
|
| 567 |
label_visibility="collapsed")
|
| 568 |
|
| 569 |
|
| 570 |
+
def choix_multi(options, cle, etiquette, format_func=None, ou=st):
|
| 571 |
+
"""Selection multiple en pastilles cliquables — jamais de menu deroulant.
|
| 572 |
+
|
| 573 |
+
Meme raison qu'a `choix()` : un menu deroulant cache ses options, il faut
|
| 574 |
+
l'ouvrir pour savoir ce qu'il contient et on ne voit jamais l'ensemble du
|
| 575 |
+
choix. Ici les options sont toutes visibles et se prennent en un clic.
|
| 576 |
+
Repli successif sur `pills`, `segmented_control`, puis des cases a cocher,
|
| 577 |
+
de sorte que l'application tourne aussi sur une version anterieure de
|
| 578 |
+
Streamlit."""
|
| 579 |
+
ff = format_func or (lambda x: x)
|
| 580 |
+
for nom in ("pills", "segmented_control"):
|
| 581 |
+
f = getattr(ou, nom, None)
|
| 582 |
+
if f is None:
|
| 583 |
+
continue
|
| 584 |
+
try:
|
| 585 |
+
v = f(etiquette, options, selection_mode="multi", format_func=ff,
|
| 586 |
+
key=f"multi_{nom}_{cle}", label_visibility="collapsed")
|
| 587 |
+
return list(v or [])
|
| 588 |
+
except Exception: # noqa: BLE001
|
| 589 |
+
continue
|
| 590 |
+
return [o for o in options
|
| 591 |
+
if ou.checkbox(ff(o), key=f"case_{cle}_{o}")]
|
| 592 |
+
|
| 593 |
+
|
| 594 |
def _bascule(libelles, cle):
|
| 595 |
inverse = {v: k for k, v in libelles.items()}
|
| 596 |
courant = inverse[st.session_state[cle]]
|
|
|
|
| 662 |
hr {{ border-color: {PAL['cadre']}; }}
|
| 663 |
a {{ color: {PAL['accent']}; }}
|
| 664 |
|
| 665 |
+
/* Libelle de filtre : le libelle natif du widget est masque pour que les
|
| 666 |
+
pastilles remontent contre lui, on le redessine donc ici. */
|
| 667 |
+
.abrp-flabel {{ font-size: .78rem; color: {PAL['texte']}; margin: .55rem 0 .15rem 0;
|
| 668 |
+
font-weight: 500; }}
|
| 669 |
+
section[data-testid="stSidebar"] [data-testid="stButtonGroup"] button {{
|
| 670 |
+
font-size: .76rem !important; padding: .12rem .5rem !important; }}
|
| 671 |
+
/* Le bouton « effacer » : Streamlit le peint dans sa propre teinte, qui
|
| 672 |
+
disparait sur le panneau sombre. */
|
| 673 |
+
section[data-testid="stSidebar"] .stButton button {{
|
| 674 |
+
background-color: {PAL['pastille']} !important; color: {PAL['texte']} !important;
|
| 675 |
+
border: 1px solid {PAL['cadre']} !important; }}
|
| 676 |
+
section[data-testid="stSidebar"] .stButton button * {{
|
| 677 |
+
color: {PAL['texte']} !important; }}
|
| 678 |
+
section[data-testid="stSidebar"] .stButton button:hover,
|
| 679 |
+
section[data-testid="stSidebar"] .stButton button:hover * {{
|
| 680 |
+
border-color: {PAL['accent']} !important; color: {PAL['encre']} !important; }}
|
| 681 |
+
|
| 682 |
.abrp-tiles {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(158px,1fr));
|
| 683 |
gap: .6rem; margin: 1.1rem 0 1.3rem 0; }}
|
| 684 |
.abrp-tile {{ background: {PAL['panneau']}; border: 1px solid {PAL['cadre']};
|
|
|
|
| 730 |
[data-testid="stButtonGroup"] button[kind="pillsActive"] *,
|
| 731 |
[data-baseweb="button-group"] button[aria-checked="true"] * {{
|
| 732 |
color: {PAL['sur_accent']} !important; }}
|
| 733 |
+
/* La pastille active peut porter aria-checked, aria-pressed OU un kind
|
| 734 |
+
...Active selon le composant et la version : la regle « inactive » doit
|
| 735 |
+
exclure les trois, sinon elle repeint le libelle actif en teinte de texte
|
| 736 |
+
sur son aplat colore — verifie, le libelle devenait illisible. */
|
| 737 |
+
[data-testid="stButtonGroup"] button:not([aria-checked="true"]):not([aria-pressed="true"]):not([data-selected="true"]):not([kind="pillsActive"]):not([kind="segmented_controlActive"]) * {{
|
| 738 |
color: {PAL['texte']} !important; }}
|
| 739 |
+
[data-testid="stButtonGroup"] button[aria-pressed="true"],
|
| 740 |
+
[data-testid="stButtonGroup"] button[kind="pillsActive"],
|
| 741 |
+
[data-testid="stButtonGroup"] button[kind="segmented_controlActive"] {{
|
| 742 |
+
background-color: {PAL['accent']} !important;
|
| 743 |
+
border-color: {PAL['accent']} !important; }}
|
| 744 |
+
[data-testid="stButtonGroup"] button[aria-pressed="true"] *,
|
| 745 |
+
[data-testid="stButtonGroup"] button[data-selected="true"] *,
|
| 746 |
+
[data-testid="stButtonGroup"] button[kind="pillsActive"] *,
|
| 747 |
+
[data-testid="stButtonGroup"] button[kind="segmented_controlActive"] *,
|
| 748 |
+
[data-testid="stButtonGroup"] button[aria-pressed="true"] p,
|
| 749 |
+
[data-testid="stButtonGroup"] button[data-selected="true"] p,
|
| 750 |
+
[data-testid="stButtonGroup"] button[aria-checked="true"] p {{
|
| 751 |
+
color: {PAL['sur_accent']} !important; font-weight: 600 !important; }}
|
| 752 |
+
/* Le survol ne doit pas reprendre la main sur une pastille deja active :
|
| 753 |
+
sans cette exception, passer la souris dessus rendait son libelle sombre
|
| 754 |
+
sur son aplat colore. */
|
| 755 |
+
[data-testid="stButtonGroup"] button[aria-pressed="true"]:hover,
|
| 756 |
+
[data-testid="stButtonGroup"] button[data-selected="true"]:hover,
|
| 757 |
+
[data-testid="stButtonGroup"] button[aria-checked="true"]:hover {{
|
| 758 |
+
background-color: {PAL['actif']} !important;
|
| 759 |
+
color: {PAL['sur_accent']} !important; }}
|
| 760 |
</style>""", unsafe_allow_html=True)
|
| 761 |
|
| 762 |
|
|
|
|
| 766 |
st.caption(t("African authors · African presses · c. 1950–1979"))
|
| 767 |
st.divider()
|
| 768 |
st.markdown(f"**{t('Filters')}**")
|
| 769 |
+
st.caption(bil("Every option is on screen and takes one click. They apply to "
|
| 770 |
+
"the Atlas, Presses and Catalogue tabs.",
|
| 771 |
+
"Toutes les options sont à l'écran et se prennent en un clic. "
|
| 772 |
+
"Elles s'appliquent aux onglets Atlas, Maisons et Catalogue."))
|
| 773 |
+
|
| 774 |
+
st.markdown(f"<div class='abrp-flabel'>{t('Region')}</div>",
|
| 775 |
+
unsafe_allow_html=True)
|
| 776 |
+
f_reg = choix_multi(REGIONS, "reg", t("Region"), format_func=lreg)
|
| 777 |
+
|
| 778 |
+
st.markdown(f"<div class='abrp-flabel'>{t('Decade')}</div>",
|
| 779 |
+
unsafe_allow_html=True)
|
| 780 |
+
DECS = [d for d in ["1940s", "1950s", "1960s", "1970s", "1980s", "Undated"]
|
| 781 |
+
if d in set(T["decade"])]
|
| 782 |
+
f_dec = choix_multi(DECS, "dec", t("Decade"),
|
| 783 |
+
format_func=lambda d: t(d) if d == "Undated" else d)
|
| 784 |
+
|
| 785 |
+
st.markdown(f"<div class='abrp-flabel'>{t('Language')}</div>",
|
| 786 |
+
unsafe_allow_html=True)
|
| 787 |
+
# Vingt-sept langues font une liste que personne ne parcourt. Ces cinq
|
| 788 |
+
# groupes repondent a la question qu'on se pose reellement ; le detail des
|
| 789 |
+
# langues reste entier dans la colonne « Langue » du catalogue et dans le
|
| 790 |
+
# champ de recherche.
|
| 791 |
+
GROUPES = [g for g in ["English", "French", "Portuguese", "Arabic",
|
| 792 |
+
"African languages", "Unrecorded"]
|
| 793 |
+
if g in set(T["language_group"])]
|
| 794 |
+
f_lang = choix_multi(GROUPES, "lang", t("Language"), format_func=lgrp)
|
| 795 |
+
|
| 796 |
+
st.markdown(f"<div class='abrp-flabel'>{t('Confidence')}</div>",
|
| 797 |
+
unsafe_allow_html=True)
|
| 798 |
+
f_conf = choix_multi(CONF, "conf", t("Confidence"), format_func=t)
|
| 799 |
+
|
| 800 |
q = st.text_input(t("Search"), key="f_q",
|
| 801 |
placeholder=bil("title, author or press",
|
| 802 |
"titre, auteur ou maison"))
|
| 803 |
+
if f_reg or f_dec or f_lang or f_conf or q:
|
| 804 |
+
if st.button(bil("Clear all filters", "Effacer tous les filtres"),
|
| 805 |
+
key="reset", **LARGE):
|
| 806 |
+
for k in list(st.session_state):
|
| 807 |
+
if k.startswith(("multi_", "case_", "f_q")):
|
| 808 |
+
del st.session_state[k]
|
| 809 |
+
st.rerun()
|
| 810 |
st.divider()
|
| 811 |
st.caption(bil(
|
| 812 |
"Every record carries its sources and a confidence flag. Nothing is "
|
|
|
|
| 820 |
def filtrer(d):
|
| 821 |
if f_reg:
|
| 822 |
d = d[d["region"].isin(f_reg)]
|
| 823 |
+
if f_lang and "language_group" in d.columns:
|
| 824 |
+
d = d[d["language_group"].isin(f_lang)]
|
| 825 |
if f_dec and "decade" in d.columns:
|
| 826 |
d = d[d["decade"].isin(f_dec)]
|
| 827 |
if f_conf:
|
build_data.py
CHANGED
|
@@ -266,6 +266,7 @@ def build_titles(presses: pd.DataFrame) -> pd.DataFrame:
|
|
| 266 |
"decade": decade_of(year),
|
| 267 |
"language": lang,
|
| 268 |
"african_language": lang not in MAJOR_EUROPEAN_LANGS and lang != "unknown",
|
|
|
|
| 269 |
"genre": clean_str(rec.get("genre")) or "unrecorded",
|
| 270 |
"genre_group": genre_group(rec.get("genre")),
|
| 271 |
"pages": rec.get("pages"),
|
|
@@ -311,6 +312,23 @@ def build_titles(presses: pd.DataFrame) -> pd.DataFrame:
|
|
| 311 |
return df
|
| 312 |
|
| 313 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
GENRE_GROUPS = [
|
| 315 |
("Children's & folklore", r"child|folk|fable|tale|picture|juvenil|reader"),
|
| 316 |
("Fiction & popular fiction", r"novel|fiction|novella|short stor|romance|crime|thriller"),
|
|
|
|
| 266 |
"decade": decade_of(year),
|
| 267 |
"language": lang,
|
| 268 |
"african_language": lang not in MAJOR_EUROPEAN_LANGS and lang != "unknown",
|
| 269 |
+
"language_group": language_group(lang),
|
| 270 |
"genre": clean_str(rec.get("genre")) or "unrecorded",
|
| 271 |
"genre_group": genre_group(rec.get("genre")),
|
| 272 |
"pages": rec.get("pages"),
|
|
|
|
| 312 |
return df
|
| 313 |
|
| 314 |
|
| 315 |
+
# Regroupement des langues pour le filtre de l'interface. Vingt-sept langues
|
| 316 |
+
# forment une liste que personne ne parcourt ; cinq groupes repondent a la
|
| 317 |
+
# question qu'on se pose vraiment. Les langues africaines ne sont PAS fondues
|
| 318 |
+
# entre elles dans les donnees : la colonne `language` garde le detail, et le
|
| 319 |
+
# catalogue l'affiche. Ce regroupement ne sert qu'a rendre un filtre cliquable.
|
| 320 |
+
LANGUAGE_GROUPS = ["English", "French", "Portuguese", "Arabic",
|
| 321 |
+
"African languages", "Unrecorded"]
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
def language_group(lang):
|
| 325 |
+
if lang in MAJOR_EUROPEAN_LANGS:
|
| 326 |
+
return lang
|
| 327 |
+
if not lang or lang == "unknown":
|
| 328 |
+
return "Unrecorded"
|
| 329 |
+
return "African languages"
|
| 330 |
+
|
| 331 |
+
|
| 332 |
GENRE_GROUPS = [
|
| 333 |
("Children's & folklore", r"child|folk|fable|tale|picture|juvenil|reader"),
|
| 334 |
("Fiction & popular fiction", r"novel|fiction|novella|short stor|romance|crime|thriller"),
|
selftest.py
CHANGED
|
@@ -110,6 +110,16 @@ def main():
|
|
| 110 |
verifier(H["provenance"].isin(["project brief", "press register"]).all(),
|
| 111 |
"chaque piste de recherche porte sa provenance")
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
print("\n== 5. cartographie")
|
| 114 |
noms_carte = set(CT["pays"])
|
| 115 |
verifier(len(noms_carte) == 54, f"{len(noms_carte)} pays ont un polygone")
|
|
@@ -153,6 +163,11 @@ def main():
|
|
| 153 |
src = (ICI / "app.py").read_text(encoding="utf-8")
|
| 154 |
interdits = [m for m in ["pyarrow", "geopandas", "shapely", "plotly",
|
| 155 |
"matplotlib", "requests"] if f"import {m}" in src]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
verifier(not interdits,
|
| 157 |
"l'application n'importe que streamlit, pandas, numpy, altair",
|
| 158 |
"importe aussi : " + ", ".join(interdits))
|
|
|
|
| 110 |
verifier(H["provenance"].isin(["project brief", "press register"]).all(),
|
| 111 |
"chaque piste de recherche porte sa provenance")
|
| 112 |
|
| 113 |
+
GROUPES = ["English", "French", "Portuguese", "Arabic", "African languages",
|
| 114 |
+
"Unrecorded"]
|
| 115 |
+
verifier(T["language_group"].isin(GROUPES).all(),
|
| 116 |
+
"chaque titre a un groupe de langue connu",
|
| 117 |
+
", ".join(sorted(set(T["language_group"]) - set(GROUPES))))
|
| 118 |
+
verifier((T.loc[T["language_group"] == "African languages", "african_language"]).all(),
|
| 119 |
+
"le groupe 'langues africaines' ne contient que des langues africaines")
|
| 120 |
+
verifier(set(T.loc[T["african_language"], "language_group"]) == {"African languages"},
|
| 121 |
+
"toute langue africaine tombe dans le groupe 'langues africaines'")
|
| 122 |
+
|
| 123 |
print("\n== 5. cartographie")
|
| 124 |
noms_carte = set(CT["pays"])
|
| 125 |
verifier(len(noms_carte) == 54, f"{len(noms_carte)} pays ont un polygone")
|
|
|
|
| 163 |
src = (ICI / "app.py").read_text(encoding="utf-8")
|
| 164 |
interdits = [m for m in ["pyarrow", "geopandas", "shapely", "plotly",
|
| 165 |
"matplotlib", "requests"] if f"import {m}" in src]
|
| 166 |
+
verifier("st.multiselect(" not in src and "st.selectbox(" not in src.replace(
|
| 167 |
+
'st.selectbox(bil("Choose a title"', "").replace(
|
| 168 |
+
'st.selectbox(t("Country")', ""),
|
| 169 |
+
"aucun filtre en menu deroulant : tout est en pastilles cliquables",
|
| 170 |
+
"il reste un multiselect ou un selectbox de filtre")
|
| 171 |
verifier(not interdits,
|
| 172 |
"l'application n'importe que streamlit, pandas, numpy, altair",
|
| 173 |
"importe aussi : " + ", ".join(interdits))
|
titles.csv
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|