Skip to content

Commit

Permalink
Merge pull request #84 from dataforgoodfr/scorreia/cleanup
Browse files Browse the repository at this point in the history
Traduction en français
  • Loading branch information
scorreia authored May 27, 2024
2 parents 29e4d71 + 491ee9e commit 04c24f1
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 54 deletions.
77 changes: 43 additions & 34 deletions app/odi_streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ def load_data(file: str) -> pd.DataFrame:
# Renommer la colonne title -> TITRE
data.rename(columns={"title": "TITRE"}, inplace=True)

# Supprimer les données sensibles
# TODO supprimer les colonnes email et autres pouvant identifier le répondant

# Et Supprimer les lignes où toutes les valeurs sont NaN
df = data.dropna(how="all")


# Nettoyage du data set

# mettre les titres en majuscule
Expand Down Expand Up @@ -243,9 +247,9 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:

# Afficher un bar chart des titres les plus fréquents
# Affichage d'un bar chart horizontal

# TODO afficher les titres en français
with st.container():
st.subheader("Productions les plus fréquentes")
st.subheader("Productions ayant le plus de réponses")
col_freq_film_select, col_freq_film_vide, col_freq_film_graph = st.columns(
[2, 0.5, 5],
)
Expand Down Expand Up @@ -304,7 +308,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
)

st.markdown(
(f"Les oeuvres analysées sont sorties sur une période qui s'étend"
(f"Les oeuvres analysées sont sorties sur une période qui s'étend "
f"de **:blue[{date_min}]** à **:blue[{date_max}]**."
f" \n\n**:blue[{date_value_pareto}%]** des années de sorties sont égales ou "
f"postérieures à **:blue[{date_pareto}]**."
Expand Down Expand Up @@ -382,7 +386,8 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
"Année de sortie":True, "Pays":True})
st.plotly_chart(fig_pays_annee, use_container_width=True)

st.markdown("***(Passer le curseur sur 'International' pour voir le détail des pays)***")
st.markdown("***(Passer le curseur sur 'International' pour voir le détail "
"des pays producteurs)***")

st.divider()

Expand Down Expand Up @@ -487,7 +492,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
part2 = (
f"\n\nLa majorité des contenus visionnés en :blue[{canal1}] ont pour "
f"pays d'origine :blue[{top_country}] (:blue[%]), alors que la "
f"majorité des contenus français sont visionnés xxx (xxx%)."
f"majorité des contenus français sont visionnés xxx (xxx%)." # TODO fix xxx
)

canal_graph_country_df = canal_group_df.groupby(["channel","Pays"])\
Expand Down Expand Up @@ -554,7 +559,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:

### Analyses des Genres Cinématographiques
with st.container():
st.subheader("Genres Cinématographiques")
st.subheader("Genres cinématographiques")

# Préparation du dataframe pour créer une ligne par genre, pays, continent poour chaque film
genre_df = df[["genres","production_countries","pays_rework","contient_list",
Expand Down Expand Up @@ -757,7 +762,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
)

with col_choix_film_prod:
# Combine all parts and use markdown
# TODO Combine all parts and use markdown
prod_comment = ("*Texte d'analyse ? Filtre ?*")
st.markdown(prod_comment)

Expand Down Expand Up @@ -926,7 +931,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
go.Bar(
x=counts.index,
y=counts["total_count"],
name="Frequency", # Name, which appears in the legend
name="Fréquence des récits", # Name, which appears in the legend
marker_color="indianred",
),
)
Expand All @@ -936,7 +941,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
go.Bar(
x=counts.index,
y=counts["oui_count"],
name="Frequency with environmental issues",
name="Fréquence des récits relatant des problèmes environnementaux",
marker_color="lightsalmon",
),
)
Expand All @@ -945,7 +950,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
go.Scatter(
x=counts.index,
y=counts["ratio_percentage"],
name="Ratio with environmental issues",
name="Pourcentage de récits relatant des problèmes environnementaux",
mode="lines+markers",
yaxis="y2",
),
Expand All @@ -954,21 +959,22 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
# Change the bar mode to group to display bars side by side
fig.update_layout(
barmode="overlay",
title="Frequency of Each Story Era",
title="Nombre de récits selon les époques avec ou "
"sans mention de problèmes environnementaux.",
xaxis_tickangle=-45,
xaxis_title="Story Era",
xaxis_title="Période du récit",
yaxis=dict(
title="Frequency",
title="Nombre",
side="left",
),
yaxis2=dict(
title="Ratio",
title="Pourcentage",
side="right", # Secondary y-axis on the right
overlaying="y", # This axis overlays the primary y-axis
range=[0, 100],
),
legend=dict(
x=1.05, # Places the legend to the right of the plot
x=0, # Places the legend to the right of the plot
y=1, # Aligns the top of the legend with the top of the plot
xanchor="left", # Anchors the legend from its left side
yanchor="top", # Anchors the legend from its top
Expand Down Expand Up @@ -1082,12 +1088,12 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
job_sector_counts,
x="Job Sector",
y="Frequency",
title="Frequency of Job Sectors",
labels={"Job Sector": "Job Sector", "Frequency": "Frequency"},
title="Fréquence par secteur de métier",
labels={"Job Sector": "Secteur", "Frequency": "Nombre"},
)

# Update layout for better visualization
fig.update_layout(xaxis_title="Job Sector", yaxis_title="Count", xaxis_tickangle=-45)
fig.update_layout(xaxis_title="Secteur", yaxis_title="Nombre", xaxis_tickangle=-45)

# Show the plot
st.plotly_chart(fig)
Expand All @@ -1110,8 +1116,8 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
ct,
text_auto=True,
aspect="auto",
labels={"x":"Interest in Ecology", "y":"Job Sector", "color":"Count"},
title="Heatmap of Job Sectors and Interest in Ecology",
labels={"x":"Intérêt pour l'écologie", "y":"Secteur de métier", "color":"Nombre"},
title="Répartition des récits selon l'intérêt pour l'écologie par secteur de métier",
)

# Update layout for clarity
Expand All @@ -1133,8 +1139,8 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
ct,
text_auto=True,
aspect="auto",
labels={"x":"Interest in Ecology", "y":"Job", "color":"Count"},
title="Heatmap of Job and Interest in Ecology",
labels={"x":"Intérêt pour l'écologie", "y":"Métier", "color":"Nombre"},
title="Répartition des récits selon l'intérêt pour l'écologie par métier",
)

# Update layout for clarity
Expand Down Expand Up @@ -1174,27 +1180,29 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
color="Frequency",
barmode="stack",
title="Utilisation de la technologie par appareil et fréquence",
labels={"count": "Count of Responses"},
labels={"Technology": "Outil technologique", "Frequency": "Fréquence"},
color_discrete_map=color_map,
category_orders=category_orders,
)
fig.update_layout( # xaxis_title='Technology Tool',
fig.update_layout(
xaxis_title="Outil technologique",
yaxis_title=label_nb_characters,
legend_title="Fréquence",
xaxis={"categoryorder": "total descending"},
# xaxis={"categoryorder": "total descending"}, # noqa: ERA001
xaxis_tickangle=-45,
)
st.plotly_chart(fig)


# Par genre, type d'appareil et fréquence.
# TODO ajouter des filtres par genre plutôt
fig = px.histogram(
melted_data_all,
x="Technology",
color="Frequency",
barmode="stack",
facet_col="gender",
title="Utilisation de la technologie par genre, type d'appareil et fréquence",
labels={"count": "Count of Responses"},
labels={"Technology": "Outil technologique", "Frequency": "Fréquence"},
color_discrete_map=color_map,
category_orders=category_orders,
)
Expand Down Expand Up @@ -1316,7 +1324,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
# Create the heatmap using Plotly Express
fig = px.imshow(
heatmap_data,
labels={"x":"Column", "y":"Value", "color":"Frequency"},
labels={"x":"Enjeu", "y":"Mention", "color":"Fréquence"},
x=heatmap_data.columns,
y=heatmap_data.index,
title="Fréquence des mentions des enjeux écologiques selon le type d'enjeu",
Expand Down Expand Up @@ -1389,7 +1397,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
"Senior (plus de 50 ans)": "0a3555",
"Plus de 70 ans": "#101727",
},
title="Répartition de l'age des personnages",
title="Répartition de l'âge des personnages",
)
fig.update_traces(marker={"cornerradius": 5})

Expand Down Expand Up @@ -1443,7 +1451,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
text_auto=True,
aspect="auto",
labels={"x": "", "y": "", "color": ""},
title="Age vs Gendre",
title="Age vs Genre",
color_continuous_scale="Bluyl",
)

Expand Down Expand Up @@ -1473,7 +1481,7 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
st.plotly_chart(fig)

fig = px.treemap(data, path=[data["Ethnicites"]],
title="Répartition de l'ethnicités des personnages",
title="Répartition de l'ethnicité des personnages",
color_discrete_sequence=["#e44f43","#0b5773",
],
)
Expand All @@ -1496,13 +1504,13 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
data["character3_sentiment"],
data["character1_sentiment"], strict=False) for val in quad]
data["Sentiment"] = pd.DataFrame(blended_column)
st.write(data["Sentiment"])
# st.write(data["Sentiment"]) # noqa: ERA001

# Remplacer NaN avec None pour data["Ethnicites"]
data["Sentiment"]= data["Sentiment"].fillna(value=None, method="ffill")

#creer treemap
st.plotly_chart(fig)
st.plotly_chart(fig) # TODO A supprimer ? Graphique déjà créé plus haut.

fig = px.treemap(data, path=["Sentiment"],color= data["Sentiment"], color_discrete_map = {
"Positive": "#0b5773",
Expand Down Expand Up @@ -1531,11 +1539,12 @@ def get_chart_82052330(df: pd.DataFrame, liste: list[str], titre: str) -> None:
data["character2_importance"],data["character3_importance"],
data["character1_importance"], strict=False) for val in quad]
data["Importance"] = pd.DataFrame(blended_column)
st.write(data["Importance"])
# st.write(data["Importance"]) # noqa: ERA001

# Remplacer NaN avec None pour data["Ethnicites"]
data["Importance"]= data["Importance"].fillna(value=None, method="ffill")

# TODO A supprimer ? graphique déjà affiché plus haut.
st.plotly_chart(fig)

fig = px.treemap(data, path=["Importance"],
Expand Down
Loading

0 comments on commit 04c24f1

Please sign in to comment.