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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
from reportlab.lib.pagesizes import letter
|
| 6 |
+
from reportlab.pdfgen import canvas
|
| 7 |
+
from reportlab.lib.utils import ImageReader
|
| 8 |
+
|
| 9 |
+
# Fonction pour générer un rapport PDF
|
| 10 |
+
|
| 11 |
+
def generate_pdf(data, filtered_data, years, keywords, author):
|
| 12 |
+
buffer = BytesIO()
|
| 13 |
+
c = canvas.Canvas(buffer, pagesize=letter)
|
| 14 |
+
width, height = letter
|
| 15 |
+
|
| 16 |
+
# Titre du rapport
|
| 17 |
+
c.setFont("Helvetica-Bold", 18)
|
| 18 |
+
c.drawString(100, height - 40, "Rapport d'Analyse des Publications Scientifiques")
|
| 19 |
+
|
| 20 |
+
# Information sur les filtres
|
| 21 |
+
c.setFont("Helvetica", 12)
|
| 22 |
+
filter_info = f"Filtres appliqués:\n- Années: {', '.join(map(str, years))}\n- Mots-clés: {', '.join(keywords)}"
|
| 23 |
+
if author:
|
| 24 |
+
filter_info += f"\n- Auteur: {author}"
|
| 25 |
+
text_lines = filter_info.split('\n')
|
| 26 |
+
y_position = height - 80
|
| 27 |
+
for line in text_lines:
|
| 28 |
+
c.drawString(50, y_position, line)
|
| 29 |
+
y_position -= 20
|
| 30 |
+
|
| 31 |
+
# Statistiques Générales
|
| 32 |
+
total_publications = len(filtered_data)
|
| 33 |
+
total_citations = filtered_data['Citation Count'].sum()
|
| 34 |
+
avg_citations_per_publication = filtered_data['Citation Count'].mean()
|
| 35 |
+
top_cited_publication = filtered_data.loc[filtered_data['Citation Count'].idxmax()]
|
| 36 |
+
|
| 37 |
+
stats = [
|
| 38 |
+
f"Nombre total de publications: {total_publications}",
|
| 39 |
+
f"Nombre total de citations: {total_citations}",
|
| 40 |
+
f"Citations moyennes par publication: {avg_citations_per_publication:.2f}",
|
| 41 |
+
f"Publication avec le plus de citations: {top_cited_publication['Title']} ({top_cited_publication['Citation Count']} citations)"
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
c.drawString(50, y_position - 20, "Statistiques Générales:")
|
| 45 |
+
for i, stat in enumerate(stats):
|
| 46 |
+
c.drawString(70, y_position - 40 - 20 * i, stat)
|
| 47 |
+
|
| 48 |
+
# Génération des visualisations
|
| 49 |
+
plots = [
|
| 50 |
+
("Distribution des Citations par Publication", lambda ax: ax.hist(filtered_data['Citation Count'], bins=20, color='skyblue', edgecolor='black')),
|
| 51 |
+
("Citations par Année", lambda ax: ax.plot(filtered_data.groupby('Year')['Citation Count'].sum().reset_index()['Year'], filtered_data.groupby('Year')['Citation Count'].sum().reset_index()['Citation Count'], marker='o', color='skyblue')),
|
| 52 |
+
("Nombre de Publications par Mot-Clé", lambda ax: ax.pie(filtered_data['Keyword'].value_counts(), labels=filtered_data['Keyword'].value_counts().index, autopct='%1.1f%%', colors=plt.cm.Paired(range(len(filtered_data['Keyword'].value_counts()))))),
|
| 53 |
+
("Nombre de Publications par Année", lambda ax: ax.plot(filtered_data.groupby('Year').size().reset_index(name='Nombre de Publications')['Year'], filtered_data.groupby('Year').size().reset_index(name='Nombre de Publications')['Nombre de Publications'], marker='o', color='skyblue')),
|
| 54 |
+
("Auteurs les Plus Cités", lambda ax: ax.bar(filtered_data.groupby('Authors')['Citation Count'].sum().reset_index().sort_values(by='Citation Count', ascending=False).head(10)['Authors'], filtered_data.groupby('Authors')['Citation Count'].sum().reset_index().sort_values(by='Citation Count', ascending=False).head(10)['Citation Count'], color='skyblue', edgecolor='black')),
|
| 55 |
+
("Sujets les Plus Publiés", lambda ax: ax.bar(filtered_data['Keyword'].value_counts().head(10).index, filtered_data['Keyword'].value_counts().head(10), color='skyblue', edgecolor='black'))
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
for i, (title, plot_func) in enumerate(plots):
|
| 59 |
+
fig, ax = plt.subplots()
|
| 60 |
+
plot_func(ax)
|
| 61 |
+
ax.set_title(title)
|
| 62 |
+
|
| 63 |
+
if 'Nombre de Publications' not in title and 'Mot-Clé' not in title:
|
| 64 |
+
ax.set_xlabel('Année')
|
| 65 |
+
ax.set_ylabel('Nombre de Citations' if 'Citations' in title else 'Nombre de Publications')
|
| 66 |
+
|
| 67 |
+
plt.tight_layout()
|
| 68 |
+
|
| 69 |
+
# Sauvegarder la figure dans un objet BytesIO
|
| 70 |
+
img_buffer = BytesIO()
|
| 71 |
+
fig.savefig(img_buffer, format='png')
|
| 72 |
+
img_buffer.seek(0)
|
| 73 |
+
c.drawImage(ImageReader(img_buffer), 50, height - 320 - 150 * (i + 1), width=500, height=120)
|
| 74 |
+
|
| 75 |
+
c.save()
|
| 76 |
+
buffer.seek(0)
|
| 77 |
+
return buffer
|
| 78 |
+
|
| 79 |
+
# Exemple d'utilisation de la fonction dans Streamlit
|
| 80 |
+
if st.sidebar.button("Générer le Rapport PDF"):
|
| 81 |
+
years = [2020, 2021, 2022]
|
| 82 |
+
keywords = ["NLP", "Artificial Intelligence"]
|
| 83 |
+
author = "John Doe"
|
| 84 |
+
|
| 85 |
+
# Simuler le chargement des données
|
| 86 |
+
data = pd.read_csv('scopus_data_all_cleaned.csv')
|
| 87 |
+
filtered_data = data[(data['Year'].isin(years)) & (data['Keyword'].isin(keywords))]
|
| 88 |
+
|
| 89 |
+
buffer = generate_pdf(data, filtered_data, years, keywords, author)
|
| 90 |
+
|
| 91 |
+
st.sidebar.success("Rapport PDF généré avec succès !")
|
| 92 |
+
st.sidebar.download_button(
|
| 93 |
+
label="Télécharger le PDF",
|
| 94 |
+
data=buffer,
|
| 95 |
+
file_name="rapport_publications_scientifiques.pdf",
|
| 96 |
+
mime="application/pdf"
|
| 97 |
+
)
|
| 98 |
+
# Chargement des données
|
| 99 |
+
data = pd.read_csv('scopus_data_all_cleaned.csv')
|
| 100 |
+
|
| 101 |
+
# Titre et description
|
| 102 |
+
st.title("Analyse des Publications Scientifiques avec l'API Scopus")
|
| 103 |
+
st.markdown("""
|
| 104 |
+
Ce tableau de bord vous permet d'analyser les publications scientifiques récupérées depuis l'API Scopus.
|
| 105 |
+
Utilisez les filtres pour explorer les données et visualiser différentes statistiques.
|
| 106 |
+
""")
|
| 107 |
+
|
| 108 |
+
# Menu de navigation
|
| 109 |
+
menu = ["Statistiques Générales", "Visualisations"]
|
| 110 |
+
choice = st.sidebar.selectbox("Menu", menu)
|
| 111 |
+
|
| 112 |
+
# Filtre pour les années, mots-clés et auteurs
|
| 113 |
+
years = st.sidebar.multiselect('Sélectionnez les années', options=data['Year'].unique(), default=data['Year'].unique())
|
| 114 |
+
keywords = st.sidebar.multiselect('Sélectionnez les mots-clés', options=data['Keyword'].unique(), default=data['Keyword'].unique())
|
| 115 |
+
author = st.sidebar.text_input('Rechercher par auteur')
|
| 116 |
+
|
| 117 |
+
# Filtrage des données
|
| 118 |
+
filtered_data = data[(data['Year'].isin(years)) & (data['Keyword'].isin(keywords))]
|
| 119 |
+
if author:
|
| 120 |
+
filtered_data = filtered_data[filtered_data['Authors'].str.contains(author, case=False, na=False)]
|
| 121 |
+
|
| 122 |
+
if choice == "Statistiques Générales":
|
| 123 |
+
st.subheader("Données Filtrées")
|
| 124 |
+
st.write(filtered_data)
|
| 125 |
+
|
| 126 |
+
total_publications = len(filtered_data)
|
| 127 |
+
total_citations = filtered_data['Citation Count'].sum()
|
| 128 |
+
avg_citations_per_publication = filtered_data['Citation Count'].mean()
|
| 129 |
+
top_cited_publication = filtered_data.loc[filtered_data['Citation Count'].idxmax()]
|
| 130 |
+
|
| 131 |
+
st.subheader("Statistiques")
|
| 132 |
+
st.write(f"**Nombre total de publications :** {total_publications}")
|
| 133 |
+
st.write(f"**Nombre total de citations :** {total_citations}")
|
| 134 |
+
st.write(f"**Citations moyennes par publication :** {avg_citations_per_publication:.2f}")
|
| 135 |
+
st.write("**Publication avec le plus de citations :**")
|
| 136 |
+
st.write(top_cited_publication)
|
| 137 |
+
|
| 138 |
+
if st.button("Télécharger le rapport en PDF"):
|
| 139 |
+
buffer = generate_pdf(data, filtered_data, years, keywords, author)
|
| 140 |
+
st.download_button(
|
| 141 |
+
label="Télécharger le PDF",
|
| 142 |
+
data=buffer,
|
| 143 |
+
file_name="rapport_publications_scientifiques.pdf",
|
| 144 |
+
mime="application/pdf"
|
| 145 |
+
)
|
| 146 |
+
else:
|
| 147 |
+
st.subheader("Visualisations")
|
| 148 |
+
|
| 149 |
+
fig, ax = plt.subplots()
|
| 150 |
+
ax.hist(filtered_data['Citation Count'], bins=20, color='skyblue', edgecolor='black')
|
| 151 |
+
ax.set_title("Distribution des Citations par Publication")
|
| 152 |
+
ax.set_xlabel("Nombre de Citations")
|
| 153 |
+
ax.set_ylabel("Nombre de Publications")
|
| 154 |
+
st.pyplot(fig)
|
| 155 |
+
|
| 156 |
+
citations_per_year = filtered_data.groupby('Year')['Citation Count'].sum().reset_index()
|
| 157 |
+
fig, ax = plt.subplots()
|
| 158 |
+
ax.plot(citations_per_year['Year'], citations_per_year['Citation Count'], marker='o', color='skyblue')
|
| 159 |
+
ax.set_title("Citations par Année")
|
| 160 |
+
ax.set_xlabel("Année")
|
| 161 |
+
ax.set_ylabel("Nombre de Citations")
|
| 162 |
+
st.pyplot(fig)
|
| 163 |
+
|
| 164 |
+
if author:
|
| 165 |
+
publications_per_author = filtered_data['Authors'].value_counts().reset_index()
|
| 166 |
+
publications_per_author.columns = ['Auteur', 'Nombre de Publications']
|
| 167 |
+
fig, ax = plt.subplots()
|
| 168 |
+
ax.bar(publications_per_author['Auteur'], publications_per_author['Nombre de Publications'], color='skyblue', edgecolor='black')
|
| 169 |
+
ax.set_title("Répartition des Publications par Auteur")
|
| 170 |
+
ax.set_xlabel("Auteur")
|
| 171 |
+
ax.set_ylabel("Nombre de Publications")
|
| 172 |
+
ax.tick_params(axis='x', rotation=90)
|
| 173 |
+
st.pyplot(fig)
|
| 174 |
+
|
| 175 |
+
fig, ax = plt.subplots()
|
| 176 |
+
ax.scatter(filtered_data['Year'], filtered_data['Citation Count'], color='skyblue', edgecolor='black')
|
| 177 |
+
ax.set_title("Corrélation entre le Nombre de Citations et les Années de Publication")
|
| 178 |
+
ax.set_xlabel("Année")
|
| 179 |
+
ax.set_ylabel("Nombre de Citations")
|
| 180 |
+
st.pyplot(fig)
|
| 181 |
+
|
| 182 |
+
publications_per_keyword = filtered_data['Keyword'].value_counts().reset_index()
|
| 183 |
+
publications_per_keyword.columns = ['Keyword', 'Nombre de Publications']
|
| 184 |
+
fig, ax = plt.subplots()
|
| 185 |
+
ax.pie(publications_per_keyword['Nombre de Publications'], labels=publications_per_keyword['Keyword'], autopct='%1.1f%%', colors=plt.cm.Paired(range(len(publications_per_keyword))))
|
| 186 |
+
ax.set_title("Nombre de Publications par Mot-Clé")
|
| 187 |
+
st.pyplot(fig)
|
| 188 |
+
|
| 189 |
+
publications_per_year = filtered_data.groupby('Year').size().reset_index(name='Nombre de Publications')
|
| 190 |
+
fig, ax = plt.subplots()
|
| 191 |
+
ax.plot(publications_per_year['Year'], publications_per_year['Nombre de Publications'], marker='o', color='skyblue')
|
| 192 |
+
ax.set_title("Nombre de Publications par Année")
|
| 193 |
+
ax.set_xlabel("Année")
|
| 194 |
+
ax.set_ylabel("Nombre de Publications")
|
| 195 |
+
st.pyplot(fig)
|
| 196 |
+
|
| 197 |
+
top_authors = filtered_data.groupby('Authors')['Citation Count'].sum().reset_index().sort_values(by='Citation Count', ascending=False).head(10)
|
| 198 |
+
fig, ax = plt.subplots()
|
| 199 |
+
ax.bar(top_authors['Authors'], top_authors['Citation Count'], color='skyblue', edgecolor='black')
|
| 200 |
+
ax.set_title("Auteurs les Plus Cités")
|
| 201 |
+
ax.set_xlabel("Auteur")
|
| 202 |
+
ax.set_ylabel("Nombre de Citations")
|
| 203 |
+
ax.tick_params(axis='x', rotation=90)
|
| 204 |
+
st.pyplot(fig)
|
| 205 |
+
|
| 206 |
+
top_keywords = filtered_data['Keyword'].value_counts().reset_index().head(10)
|
| 207 |
+
top_keywords.columns = ['Keyword', 'Nombre de Publications']
|
| 208 |
+
fig, ax = plt.subplots()
|
| 209 |
+
ax.bar(top_keywords['Keyword'], top_keywords['Nombre de Publications'], color='skyblue', edgecolor='black')
|
| 210 |
+
ax.set_title("Sujets les Plus Publiés")
|
| 211 |
+
ax.set_xlabel("Mot-Clé")
|
| 212 |
+
ax.set_ylabel("Nombre de Publications")
|
| 213 |
+
ax.tick_params(axis='x', rotation=90)
|
| 214 |
+
st.pyplot(fig)
|
pfm_Python_finale.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scopus_data_All.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scopus_data_all_cleaned.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|