Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import os
|
3 |
import dash
|
4 |
import json
|
@@ -707,40 +706,6 @@ def getGitFilesFromRepo(DIRECTORY):
|
|
707 |
})
|
708 |
return all_files
|
709 |
|
710 |
-
def load_json_files(directory_path: str = "./BCC-Application/JSON"):
|
711 |
-
if not os.path.exists(directory_path):
|
712 |
-
print(f"Erreur: Le répertoire {directory_path} n'existe pas.")
|
713 |
-
return
|
714 |
-
|
715 |
-
# Récupérer la liste des fichiers CSV dans le répertoire
|
716 |
-
json_files = glob.glob(os.path.join(directory_path, "*.json"))
|
717 |
-
|
718 |
-
if not json_files:
|
719 |
-
print(f"Aucun fichier JSON trouvé dans le répertoire {directory_path}.")
|
720 |
-
return
|
721 |
-
|
722 |
-
print(f"Fichiers JSON trouvés: {len(json_files)}")
|
723 |
-
#for file in json_files:
|
724 |
-
# print(f"- {file}")
|
725 |
-
return json_files
|
726 |
-
|
727 |
-
def load_json_AVID_files(directory_path: str = "./VD-Agent/JSON"):
|
728 |
-
if not os.path.exists(directory_path):
|
729 |
-
print(f"Erreur: Le répertoire {directory_path} n'existe pas.")
|
730 |
-
return
|
731 |
-
|
732 |
-
# Récupérer la liste des fichiers CSV dans le répertoire
|
733 |
-
json_files = glob.glob(os.path.join(directory_path, "*.json"))
|
734 |
-
|
735 |
-
if not json_files:
|
736 |
-
print(f"Aucun fichier JSON trouvé dans le répertoire {directory_path}.")
|
737 |
-
return
|
738 |
-
|
739 |
-
print(f"Fichiers JSON trouvés: {len(json_files)}")
|
740 |
-
#for file in json_files:
|
741 |
-
# print(f"- {file}")
|
742 |
-
return json_files
|
743 |
-
|
744 |
# Fonction pour extraire les catégories et enseignements
|
745 |
def extract_categories_enseignements(data: Dict) -> pd.DataFrame:
|
746 |
"""Extraire les catégories et enseignements associés dans un DataFrame."""
|
@@ -1134,7 +1099,7 @@ app_page = dmc.MantineProvider(
|
|
1134 |
className="g-0"
|
1135 |
),
|
1136 |
html.H4(id="text-enseignement-dropdown", className="mb-3 text-success", style={"font-size": "0.7rem"}),
|
1137 |
-
dbc.Textarea(id="enseignement-dropdown", className="mb-3", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"}),
|
1138 |
], md=6),
|
1139 |
dbc.Col([
|
1140 |
dbc.Row(
|
@@ -1148,7 +1113,7 @@ app_page = dmc.MantineProvider(
|
|
1148 |
className="g-0"
|
1149 |
),
|
1150 |
html.H4("Choisir d'abord une maquette de formation avec propositions BCC", className="mb-3", style={"font-size": "0.7rem"}),
|
1151 |
-
dbc.Textarea(id="classification-dropdown", className="mb-3", placeholder="Choisir d'abord une maquette avec propositions BCC", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"}),
|
1152 |
], md=6)
|
1153 |
]),
|
1154 |
dbc.Row([
|
@@ -1164,7 +1129,7 @@ app_page = dmc.MantineProvider(
|
|
1164 |
className="g-0"
|
1165 |
),
|
1166 |
html.H4("Choisir d'abord une maquette de formation avec propositions BCC", className="mb-3", style={"font-size": "0.7rem"}),
|
1167 |
-
dbc.Textarea(id="situation-dropdown", className="mb-3", placeholder="Choisir d'abord une maquette avec propositions BCC", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"}),
|
1168 |
], md=6),
|
1169 |
dbc.Col([
|
1170 |
dbc.Row(
|
@@ -1523,7 +1488,7 @@ app_avid_page = dmc.MantineProvider(
|
|
1523 |
className="g-0"
|
1524 |
),
|
1525 |
html.H4(id="text-enseignement-dropdown", className="mb-3 text-success", style={"font-size": "0.7rem"}),
|
1526 |
-
dbc.Textarea(id="enseignement-dropdown", className="mb-3", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"}),
|
1527 |
], md=6),
|
1528 |
dbc.Col([
|
1529 |
dbc.Row(
|
@@ -1537,7 +1502,7 @@ app_avid_page = dmc.MantineProvider(
|
|
1537 |
className="g-0"
|
1538 |
),
|
1539 |
html.H4("Choisir d'abord une maquette de formation avec propositions BCC AVID", className="mb-3", style={"font-size": "0.7rem"}),
|
1540 |
-
dbc.Textarea(id="classification-dropdown", className="mb-3", placeholder="Choisir d'abord une maquette avec propositions BCC AVID", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"}),
|
1541 |
], md=6)
|
1542 |
]),
|
1543 |
dbc.Row([
|
@@ -1553,7 +1518,7 @@ app_avid_page = dmc.MantineProvider(
|
|
1553 |
className="g-0"
|
1554 |
),
|
1555 |
html.H4("Choisir d'abord une maquette de formation avec propositions BCC AVID", className="mb-3", style={"font-size": "0.7rem"}),
|
1556 |
-
dbc.Textarea(id="situation-dropdown", className="mb-3", placeholder="Choisir d'abord une maquette avec propositions BCC AVID", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"}),
|
1557 |
], md=6),
|
1558 |
dbc.Col([
|
1559 |
dbc.Row(
|
@@ -1805,28 +1770,31 @@ def update_skills_dropdown(categorie_selected, pathname):
|
|
1805 |
)
|
1806 |
def update_enseignements_dropdown(categorie_selected, pathname):
|
1807 |
"""Mettre à jour les options du dropdown d'enseignements en fonction de la catégorie sélectionnée."""
|
1808 |
-
|
1809 |
-
|
1810 |
-
|
1811 |
-
|
1812 |
-
|
1813 |
-
|
1814 |
-
|
1815 |
-
|
|
|
1816 |
|
1817 |
-
|
1818 |
-
|
1819 |
-
|
1820 |
-
|
1821 |
-
|
1822 |
-
|
1823 |
-
|
1824 |
-
|
1825 |
-
|
1826 |
sort_keys = True, ensure_ascii=False), "Choisir d'abord une maquette de formation avec propositions BCC : " + default_text + jsonData.get("niveau", ""), modal_text
|
1827 |
-
|
1828 |
-
|
1829 |
-
|
|
|
|
|
1830 |
|
1831 |
@app.callback(
|
1832 |
Output("classification-dropdown", "placeholder"),
|
@@ -1837,41 +1805,44 @@ def update_enseignements_dropdown(categorie_selected, pathname):
|
|
1837 |
)
|
1838 |
def update_classification_dropdown(categorie_selected, pathname):
|
1839 |
"""Mettre à jour les options du dropdown d'enseignements en fonction de la catégorie sélectionnée."""
|
1840 |
-
|
1841 |
-
|
1842 |
-
|
1843 |
-
|
1844 |
-
|
1845 |
-
|
1846 |
-
|
1847 |
-
|
|
|
1848 |
|
1849 |
-
|
1850 |
-
|
1851 |
-
|
1852 |
-
|
1853 |
-
|
1854 |
-
|
1855 |
-
|
1856 |
-
|
1857 |
-
|
1858 |
-
|
1859 |
-
|
1860 |
-
|
1861 |
-
|
1862 |
-
|
1863 |
-
|
1864 |
-
|
1865 |
-
|
1866 |
-
|
1867 |
-
|
1868 |
|
1869 |
-
|
1870 |
-
|
1871 |
sort_keys = True, ensure_ascii=False),modal_text
|
1872 |
-
|
1873 |
-
|
1874 |
sort_keys = True, ensure_ascii=False),modal_text
|
|
|
|
|
1875 |
|
1876 |
@app.callback(
|
1877 |
Output("situation-dropdown", "placeholder"),
|
@@ -1882,43 +1853,46 @@ def update_classification_dropdown(categorie_selected, pathname):
|
|
1882 |
)
|
1883 |
def update_situations_dropdown(categorie_selected, pathname):
|
1884 |
"""Mettre à jour les options du dropdown d'enseignements en fonction de la catégorie sélectionnée."""
|
1885 |
-
if not categorie_selected:
|
1886 |
-
default_text = "par défaut : "
|
1887 |
-
if pathname == "/bcc":
|
1888 |
-
categorie_selected = 'JSON/L1-Anglais.json'
|
1889 |
-
elif pathname == "/bcc-avid":
|
1890 |
-
categorie_selected = 'VD/JSON/L1-Lettres-Modernes.json'
|
1891 |
-
else:
|
1892 |
-
default_text = ""
|
1893 |
-
|
1894 |
-
url = f"https://api.github.com/repos/{OWNER}/{REPO}/contents/{categorie_selected}"
|
1895 |
-
res = requests.get(url, headers=headers, params=params)
|
1896 |
try:
|
1897 |
-
if
|
1898 |
-
|
1899 |
-
modal_text = "**Description des situations d'apprentissage :**"
|
1900 |
if pathname == "/bcc":
|
1901 |
-
|
1902 |
-
for key, value in textarea_value.items():
|
1903 |
-
modal_text += f"\n\n- **{key}**: {value}"
|
1904 |
elif pathname == "/bcc-avid":
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
|
1910 |
-
|
1911 |
-
|
1912 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1913 |
|
1914 |
-
|
1915 |
-
|
1916 |
sort_keys = True, ensure_ascii=False), modal_text
|
1917 |
-
|
1918 |
-
|
1919 |
sort_keys = True, ensure_ascii=False), modal_text
|
|
|
|
|
1920 |
except:
|
1921 |
-
|
1922 |
|
1923 |
@app.callback(
|
1924 |
Output("selection-display", "children"),
|
|
|
|
|
1 |
import os
|
2 |
import dash
|
3 |
import json
|
|
|
706 |
})
|
707 |
return all_files
|
708 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
709 |
# Fonction pour extraire les catégories et enseignements
|
710 |
def extract_categories_enseignements(data: Dict) -> pd.DataFrame:
|
711 |
"""Extraire les catégories et enseignements associés dans un DataFrame."""
|
|
|
1099 |
className="g-0"
|
1100 |
),
|
1101 |
html.H4(id="text-enseignement-dropdown", className="mb-3 text-success", style={"font-size": "0.7rem"}),
|
1102 |
+
dcc.Loading(dbc.Textarea(id="enseignement-dropdown", className="mb-3", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"})),
|
1103 |
], md=6),
|
1104 |
dbc.Col([
|
1105 |
dbc.Row(
|
|
|
1113 |
className="g-0"
|
1114 |
),
|
1115 |
html.H4("Choisir d'abord une maquette de formation avec propositions BCC", className="mb-3", style={"font-size": "0.7rem"}),
|
1116 |
+
dcc.Loading(dbc.Textarea(id="classification-dropdown", className="mb-3", placeholder="Choisir d'abord une maquette avec propositions BCC", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"})),
|
1117 |
], md=6)
|
1118 |
]),
|
1119 |
dbc.Row([
|
|
|
1129 |
className="g-0"
|
1130 |
),
|
1131 |
html.H4("Choisir d'abord une maquette de formation avec propositions BCC", className="mb-3", style={"font-size": "0.7rem"}),
|
1132 |
+
dcc.Loading(dbc.Textarea(id="situation-dropdown", className="mb-3", placeholder="Choisir d'abord une maquette avec propositions BCC", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"})),
|
1133 |
], md=6),
|
1134 |
dbc.Col([
|
1135 |
dbc.Row(
|
|
|
1488 |
className="g-0"
|
1489 |
),
|
1490 |
html.H4(id="text-enseignement-dropdown", className="mb-3 text-success", style={"font-size": "0.7rem"}),
|
1491 |
+
dcc.Loading(dbc.Textarea(id="enseignement-dropdown", className="mb-3", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"})),
|
1492 |
], md=6),
|
1493 |
dbc.Col([
|
1494 |
dbc.Row(
|
|
|
1502 |
className="g-0"
|
1503 |
),
|
1504 |
html.H4("Choisir d'abord une maquette de formation avec propositions BCC AVID", className="mb-3", style={"font-size": "0.7rem"}),
|
1505 |
+
dcc.Loading(dbc.Textarea(id="classification-dropdown", className="mb-3", placeholder="Choisir d'abord une maquette avec propositions BCC AVID", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"})),
|
1506 |
], md=6)
|
1507 |
]),
|
1508 |
dbc.Row([
|
|
|
1518 |
className="g-0"
|
1519 |
),
|
1520 |
html.H4("Choisir d'abord une maquette de formation avec propositions BCC AVID", className="mb-3", style={"font-size": "0.7rem"}),
|
1521 |
+
dcc.Loading(dbc.Textarea(id="situation-dropdown", className="mb-3", placeholder="Choisir d'abord une maquette avec propositions BCC AVID", style={"height":"200px", "max-height":"250px", "font-size": "0.75rem","color":"white","border":"border 1px solid rgb(67,167,255)!important", "background-color":"transparent"})),
|
1522 |
], md=6),
|
1523 |
dbc.Col([
|
1524 |
dbc.Row(
|
|
|
1770 |
)
|
1771 |
def update_enseignements_dropdown(categorie_selected, pathname):
|
1772 |
"""Mettre à jour les options du dropdown d'enseignements en fonction de la catégorie sélectionnée."""
|
1773 |
+
try:
|
1774 |
+
if not categorie_selected:
|
1775 |
+
default_text = "par défaut : "
|
1776 |
+
if pathname == "/bcc":
|
1777 |
+
categorie_selected = 'JSON/L1-Anglais.json'
|
1778 |
+
elif pathname == "/bcc-avid":
|
1779 |
+
categorie_selected = 'VD/JSON/L1-Lettres-Modernes.json'
|
1780 |
+
else:
|
1781 |
+
default_text = "formation sélectionnée : "
|
1782 |
|
1783 |
+
url = f"https://api.github.com/repos/{OWNER}/{REPO}/contents/{categorie_selected}"
|
1784 |
+
res = requests.get(url, headers=headers, params=params)
|
1785 |
+
if res.status_code == 200:
|
1786 |
+
jsonData = json.loads(base64.b64decode(res.json()['content']))
|
1787 |
+
modal_text = "**Description des catégories d'enseignements : **\n\n"
|
1788 |
+
for item in jsonData.get("categories", []):
|
1789 |
+
modal_text += f"- **{item['nom']}**:\n\n{item['description']}\n\n"
|
1790 |
+
if pathname == "/bcc":
|
1791 |
+
return "Choisir d'abord une maquette de formation avec proposition BCC", json.dumps(jsonData.get("categories", []), indent = 6, separators =(",", ":"),
|
1792 |
sort_keys = True, ensure_ascii=False), "Choisir d'abord une maquette de formation avec propositions BCC : " + default_text + jsonData.get("niveau", ""), modal_text
|
1793 |
+
elif pathname == "/bcc-avid":
|
1794 |
+
return "Choisir d'abord une maquette de formation avec proposition BCC", json.dumps(jsonData.get("categories", []), indent = 6, separators =(",", ":"),
|
1795 |
+
sort_keys = True, ensure_ascii=False), "Choisir d'abord une maquette de formation avec propositions BCC : " + default_text + jsonData.get("niveau_etude", ""), modal_text
|
1796 |
+
except:
|
1797 |
+
print("Aucun fichier chargé")
|
1798 |
|
1799 |
@app.callback(
|
1800 |
Output("classification-dropdown", "placeholder"),
|
|
|
1805 |
)
|
1806 |
def update_classification_dropdown(categorie_selected, pathname):
|
1807 |
"""Mettre à jour les options du dropdown d'enseignements en fonction de la catégorie sélectionnée."""
|
1808 |
+
try:
|
1809 |
+
if not categorie_selected:
|
1810 |
+
default_text = "par défaut : "
|
1811 |
+
if pathname == "/bcc":
|
1812 |
+
categorie_selected = 'JSON/L1-Anglais.json'
|
1813 |
+
elif pathname == "/bcc-avid":
|
1814 |
+
categorie_selected = 'VD/JSON/L1-Lettres-Modernes.json'
|
1815 |
+
else:
|
1816 |
+
default_text = ""
|
1817 |
|
1818 |
+
url = f"https://api.github.com/repos/{OWNER}/{REPO}/contents/{categorie_selected}"
|
1819 |
+
res = requests.get(url, headers=headers, params=params)
|
1820 |
+
if res.status_code == 200:
|
1821 |
+
jsonData = json.loads(base64.b64decode(res.json()['content']))
|
1822 |
+
modal_text = "**Classification des enseignements :**"
|
1823 |
+
if pathname == "/bcc":
|
1824 |
+
textarea_value = jsonData.get("classified_teachings", [])
|
1825 |
+
for key, value in textarea_value.items():
|
1826 |
+
modal_text += f"\n\n- **{key}**: "
|
1827 |
+
for i in range(0,len(value)):
|
1828 |
+
modal_text += f"{value[i]}\t"
|
1829 |
+
elif pathname == "/bcc-avid":
|
1830 |
+
textarea_value = jsonData.get("dataframe", [])
|
1831 |
+
test = " "
|
1832 |
+
for item in sorted(textarea_value, key=lambda x: x['categorie'] if x['categorie'] else ""):
|
1833 |
+
if test != item['categorie']:
|
1834 |
+
modal_text += f"\n\n- **{item['categorie']}**: "
|
1835 |
+
modal_text += f"{item['enseignements']}\t"
|
1836 |
+
test = item['categorie']
|
1837 |
|
1838 |
+
if pathname == "/bcc":
|
1839 |
+
return "Choisir d'abord une maquette de formation avec proposition BCC", json.dumps(textarea_value, indent = 6, separators =(",", ":"),
|
1840 |
sort_keys = True, ensure_ascii=False),modal_text
|
1841 |
+
elif pathname == "/bcc-avid":
|
1842 |
+
return "Choisir d'abord une maquette de formation avec proposition BCC", json.dumps(textarea_value, indent = 6, separators =(",", ":"),
|
1843 |
sort_keys = True, ensure_ascii=False),modal_text
|
1844 |
+
except:
|
1845 |
+
print("Aucun fichier chargé")
|
1846 |
|
1847 |
@app.callback(
|
1848 |
Output("situation-dropdown", "placeholder"),
|
|
|
1853 |
)
|
1854 |
def update_situations_dropdown(categorie_selected, pathname):
|
1855 |
"""Mettre à jour les options du dropdown d'enseignements en fonction de la catégorie sélectionnée."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1856 |
try:
|
1857 |
+
if not categorie_selected:
|
1858 |
+
default_text = "par défaut : "
|
|
|
1859 |
if pathname == "/bcc":
|
1860 |
+
categorie_selected = 'JSON/L1-Anglais.json'
|
|
|
|
|
1861 |
elif pathname == "/bcc-avid":
|
1862 |
+
categorie_selected = 'VD/JSON/L1-Lettres-Modernes.json'
|
1863 |
+
else:
|
1864 |
+
default_text = ""
|
1865 |
+
|
1866 |
+
url = f"https://api.github.com/repos/{OWNER}/{REPO}/contents/{categorie_selected}"
|
1867 |
+
res = requests.get(url, headers=headers, params=params)
|
1868 |
+
try:
|
1869 |
+
if res.status_code == 200:
|
1870 |
+
jsonData = json.loads(base64.b64decode(res.json()['content']))
|
1871 |
+
modal_text = "**Description des situations d'apprentissage :**"
|
1872 |
+
if pathname == "/bcc":
|
1873 |
+
textarea_value = jsonData.get("learning_situations", [])
|
1874 |
+
for key, value in textarea_value.items():
|
1875 |
+
modal_text += f"\n\n- **{key}**: {value}"
|
1876 |
+
elif pathname == "/bcc-avid":
|
1877 |
+
textarea_value = jsonData.get("situations_apprentissage", [])
|
1878 |
+
for item in textarea_value:
|
1879 |
+
modal_text += f"\n\n- **Situation d'apprentissage**: {item['situation']}"
|
1880 |
+
if item['objectifs']:
|
1881 |
+
modal_text += f"\n\nObjectifs : "
|
1882 |
+
for objectif in item['objectifs']:
|
1883 |
+
modal_text += f"\n-{objectif}"
|
1884 |
+
modal_text += f"\n\nLien avec les thématiques ODD11 : {item['lien_odd11']}"
|
1885 |
|
1886 |
+
if pathname == "/bcc":
|
1887 |
+
return "Choisir d'abord une maquette de formation avec proposition BCC", json.dumps(textarea_value, indent = 6, separators =(",", ":"),
|
1888 |
sort_keys = True, ensure_ascii=False), modal_text
|
1889 |
+
elif pathname == "/bcc-avid":
|
1890 |
+
return "Choisir d'abord une maquette de formation avec proposition BCC", json.dumps(textarea_value, indent = 6, separators =(",", ":"),
|
1891 |
sort_keys = True, ensure_ascii=False), modal_text
|
1892 |
+
except:
|
1893 |
+
return "Choisir d'abord une maquette de formation avec proposition BCC", "", "**Aucune situation d'apprentissage définie pour cette maquette de formation.**"
|
1894 |
except:
|
1895 |
+
print("aucun fichier chargé")
|
1896 |
|
1897 |
@app.callback(
|
1898 |
Output("selection-display", "children"),
|