{ "cells": [ { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "import plotly.express as px\n", "import pandas as pd\n", "import json\n", "import plotly.graph_objects as go\n", "import streamlit as st\n" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "articles = pd.read_csv('/Users/zsapey/Documents/Code/libe-datalab/Sciences-POC/extract_sciences_po.csv')\n", "\n", "with open('/Users/zsapey/Documents/Code/libe-datalab/Sciences-POC/output_favarel_et_al.txt', 'r') as f : \n", " out_dict = json.loads(f.read())" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'Unnamed: 0': 33,\n", " 'item_id': 'XFBX7NDGN5CMPL3OU5ZXFF6YCE',\n", " 'date_published': '2024-10-08 08:33:14',\n", " 'url': 'https://www.liberation.fr/environnement/climat/marseille-se-reveille-les-pieds-dans-leau-apres-de-fortes-pluies-20241008_XFBX7NDGN5CMPL3OU5ZXFF6YCE/',\n", " 'titre': 'Marseille se réveille les pieds dans l’eau après de fortes pluies – Libération',\n", " 'description': 'Des pluies diluviennes se sont abattues en région Provence Alpes Côte d’Azur tôt ce mardi 8 octobre. Les images de Marseille inondée sont impressionnantes.',\n", " 'type': 'article',\n", " 'author': ' LIBERATION',\n", " 'section': 'Climat',\n", " 'subhead': 'Précipitations',\n", " 'premium': False,\n", " 'texte': '{\"Le Sud-Est sous l’eau, Marseille les pieds dedans. Entre 15 et 30 millimètres de pluie sont tombés depuis le début de la nuit de lundi à ce mardi 8 octobre dans le sud-est de la France, alors que Météo France a placé les Bouches-du-Rhône, les Alpes-de-Haute-Provence et le Vaucluse en vigilance jaune «pluie inondation» et «orages» pour ce mardi 8 octobre. «On est dans le gros des précipitations actuellement [à 8 heures ce mardi matin, ndlr], pose l’antenne Météo-France d’Aix-en-Provence. On en a encore pour deux à trois heures avant que cela ne se calme.»\",\"Conséquence de ces cumuls de pluie : l’eau déborde, notamment à Marseille, où plusieurs quartiers sont inondés, comme le rapporte la Provence. Les images et vidéos partagées sur les réseaux sociaux ce matin sont impressionnantes.\",\"Les précipitations ont pris de court les usagers des trams et métros, fortement touchés par les intempéries.\",\"Sur le réseau social X, le maire de Marseille Benoît Payan appelle à la prudence : «Suite aux intempéries qui ont touché Marseille cette nuit et certains services publics, l’ensemble des agents de la ville et les marins pompiers sont à pied d’œuvre pour un retour à la normale. J’invite les Marseillaises et les Marseillais à la prudence lors de leurs déplacements.»\"}'}]" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "articles.sample(1).to_dict(orient='records')" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame.from_dict(out_dict)\n", "count_principale = df.groupby('categorie_principale').item_id.count()\n", "count_secondaire = df.groupby('categorie_secondaire').item_id.count()\n", "\n" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "display_principale = count_principale.reset_index()\n", "display_principale.columns = ['theta', 'r']\n", "display_secondaire = count_secondaire.reset_index()\n", "display_secondaire.columns = ['theta', 'r']" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "application/vnd.microsoft.datawrangler.viewer.v0+json": { "columns": [ { "name": "index", "rawType": "int64", "type": "integer" }, { "name": "theta", "rawType": "object", "type": "string" }, { "name": "r", "rawType": "int64", "type": "integer" } ], "conversionMethod": "pd.DataFrame", "ref": "9be6c32e-d22c-4176-a9d6-794020bebae4", "rows": [ [ "0", "EDUCATE ME", "82" ], [ "1", "ENTERTAIN ME", "5" ], [ "2", "GIVE ME PERSPECTIVE", "22" ], [ "3", "INSPIRE ME", "27" ], [ "4", "KEEP ME ON TREND", "4" ], [ "5", "UPDATE ME", "78" ] ], "shape": { "columns": 2, "rows": 6 } }, "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
thetar
0EDUCATE ME82
1ENTERTAIN ME5
2GIVE ME PERSPECTIVE22
3INSPIRE ME27
4KEEP ME ON TREND4
5UPDATE ME78
\n", "
" ], "text/plain": [ " theta r\n", "0 EDUCATE ME 82\n", "1 ENTERTAIN ME 5\n", "2 GIVE ME PERSPECTIVE 22\n", "3 INSPIRE ME 27\n", "4 KEEP ME ON TREND 4\n", "5 UPDATE ME 78" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "display_principale" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "fill": "toself", "name": "Catégorie Primaire", "r": { "bdata": "UgUWGwRO", "dtype": "i1" }, "theta": [ "EDUCATE ME", "ENTERTAIN ME", "GIVE ME PERSPECTIVE", "INSPIRE ME", "KEEP ME ON TREND", "UPDATE ME" ], "type": "scatterpolar" }, { "fill": "toself", "name": "Catégorie Secondaire", "r": { "bdata": "VQVYEgcP", "dtype": "i1" }, "theta": [ "EDUCATE ME", "ENTERTAIN ME", "GIVE ME PERSPECTIVE", "INSPIRE ME", "KEEP ME ON TREND", "UPDATE ME" ], "type": "scatterpolar" } ], "layout": { "polar": { "radialaxis": { "range": [ 0, 88 ], "visible": true } }, "showlegend": false, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermap": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermap" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } } } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "template =\"ggplot2\"\n", "\n", "categories = ['processing cost','mechanical properties','chemical stability',\n", " 'thermal stability', 'device integration']\n", "\n", "fig = go.Figure()\n", "\n", "fig.add_trace(go.Scatterpolar(\n", " r=display_principale['r'],\n", " theta=display_principale['theta'],\n", " fill='toself',\n", " name='Catégorie Primaire'\n", "))\n", "fig.add_trace(go.Scatterpolar(\n", " r=display_secondaire['r'],\n", " theta=display_secondaire['theta'],\n", " fill='toself',\n", " name='Catégorie Secondaire'\n", "))\n", "\n", "fig.update_layout(\n", " polar=dict(\n", " radialaxis=dict(\n", " visible=True,\n", " range=[0, max(max(display_principale.r), max(display_secondaire.r))]\n", " )),\n", " showlegend=False\n", ")\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-04-03 16:44:04.066 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-04-03 16:44:04.071 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-04-03 16:44:04.074 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-04-03 16:44:04.296 \n", " \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n", " command:\n", "\n", " streamlit run /Users/zsapey/Documents/Code/libe-datalab/Sciences-POC/.venv/lib/python3.11/site-packages/ipykernel_launcher.py [ARGUMENTS]\n", "2025-04-03 16:44:04.297 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n" ] }, { "data": { "text/plain": [ "DeltaGenerator()" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st.plotly_chart(fig)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.11" } }, "nbformat": 4, "nbformat_minor": 2 }