{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import json\n", "import plotly.express as px" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "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", " \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", "
usernamesemaildurees_audio_secdate_inscriptiondates_transcriptionYearMonthYear_Month
018202e69-afba-430b-a7f2-cf33c0a173b5test1@gmail.com56.7533112023-06-14 13:59:03.1408472023-06-14 13:59:03.140847202362023_06
118202e69-afba-430b-a7f2-cf33c0a173b5test1@gmail.com56.7533112023-06-14 13:59:03.1408472023-06-14 14:01:42.171527202362023_06
218202e69-afba-430b-a7f2-cf33c0a173b5test1@gmail.com56.7533112023-06-14 13:59:03.1408472023-06-14 14:03:44.971361202362023_06
318202e69-afba-430b-a7f2-cf33c0a173b5test1@gmail.com232.4085422023-06-14 13:59:03.1408472023-06-15 00:10:08.233341202362023_06
4401507b3-9030-4690-969b-524b37ba5bc9odashmx135@gmail.com56.7533112023-06-14 14:05:49.3988372023-06-14 14:05:49.398837202362023_06
\n", "
" ], "text/plain": [ " usernames email \n", "0 18202e69-afba-430b-a7f2-cf33c0a173b5 test1@gmail.com \\\n", "1 18202e69-afba-430b-a7f2-cf33c0a173b5 test1@gmail.com \n", "2 18202e69-afba-430b-a7f2-cf33c0a173b5 test1@gmail.com \n", "3 18202e69-afba-430b-a7f2-cf33c0a173b5 test1@gmail.com \n", "4 401507b3-9030-4690-969b-524b37ba5bc9 odashmx135@gmail.com \n", "\n", " durees_audio_sec date_inscription dates_transcription \n", "0 56.753311 2023-06-14 13:59:03.140847 2023-06-14 13:59:03.140847 \\\n", "1 56.753311 2023-06-14 13:59:03.140847 2023-06-14 14:01:42.171527 \n", "2 56.753311 2023-06-14 13:59:03.140847 2023-06-14 14:03:44.971361 \n", "3 232.408542 2023-06-14 13:59:03.140847 2023-06-15 00:10:08.233341 \n", "4 56.753311 2023-06-14 14:05:49.398837 2023-06-14 14:05:49.398837 \n", "\n", " Year Month Year_Month \n", "0 2023 6 2023_06 \n", "1 2023 6 2023_06 \n", "2 2023 6 2023_06 \n", "3 2023 6 2023_06 \n", "4 2023 6 2023_06 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "##### Affichage utilisation de l'utilisateur #####\n", "# Chargement du fichier des utilisateurs\n", "with open(\"users_info.json\", 'r') as file:\n", " dict_user = json.load(file)\n", "\n", "# Transformation en dataframe\n", "df_user = pd.DataFrame(dict_user).T.reset_index()\n", "df_user.rename(columns={\"index\":\"usernames\"},inplace = True)\n", "\n", "# Separation des lignes de listes en plusieurs lignes pour les colonees duree_audio_sec et dates_transcription\n", "df_duree = df_user.drop(['dates_transcription'],axis=1) \n", "df_duree = df_duree.explode('durees_audio_sec')\n", "df_duree = df_duree.reset_index(drop=True)\n", "\n", "df_transcription = df_user.drop(['durees_audio_sec'],axis=1)\n", "df_transcription = df_transcription.explode('dates_transcription')\n", "df_transcription = df_transcription.reset_index(drop=True)\n", "\n", "# Regroupement des dataframes\n", "df_user = df_duree.copy()\n", "df_user[\"dates_transcription\"] = df_transcription[\"dates_transcription\"]\n", "\n", "df_user['date_inscription'] = pd.to_datetime(df_user['date_inscription'],format = \"%Y-%m-%d %H:%M:%S.%f\")\n", "df_user['dates_transcription'] = pd.to_datetime(df_user['dates_transcription'],format = \"%Y-%m-%d %H:%M:%S.%f\")\n", "\n", "# Calcul annee-mois de trascription\n", "df_user['Year'] = df_user['dates_transcription'].dt.year\n", "df_user['Month'] = df_user['dates_transcription'].dt.month\n", "df_user['Year_Month'] = df_user['Year'].astype(str) + '_' + df_user['Month'].astype(str).str.zfill(2)\n", "df_user\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "hovertemplate": "dates_transcription=%{x}
durees_audio_sec=%{y}", "legendgroup": "", "line": { "color": "#636efa", "dash": "solid" }, "marker": { "symbol": "circle" }, "mode": "lines", "name": "", "orientation": "v", "showlegend": false, "type": "scatter", "x": [ "2023-06-14T13:59:03.140847", "2023-06-14T14:01:42.171527", "2023-06-14T14:03:44.971361", "2023-06-15T00:10:08.233341" ], "xaxis": "x", "y": [ 56.75331065759637, 56.75331065759637, 56.75331065759637, 232.40854166666668 ], "yaxis": "y" } ], "layout": { "annotations": [ { "font": { "color": "red" }, "showarrow": false, "text": "SEUIL DE 20H = 72000 secondes", "x": "2023-06-15T00:10:08.233341", "xshift": -40, "y": 72000, "yshift": 20 } ], "legend": { "tracegroupgap": 0 }, "margin": { "t": 60 }, "shapes": [ { "line": { "color": "red", "dash": "dash", "width": 2 }, "type": "line", "x0": "2023-06-14T13:59:03.140847", "x1": "2023-06-15T00:10:08.233341", "y0": 72000, "y1": 72000 } ], "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" } ], "heatmapgl": [ { "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": "heatmapgl" } ], "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" } ], "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 } } }, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "title": { "text": "dates_transcription" } }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "title": { "text": "durees_audio_sec" } } } } }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Tracer X en fonction de Y en utilisant Plotly\n", "#df_user[\"durees_audio_sec\"] = df_user[\"durees_audio_sec\"]/3600\n", "a =df_user[(df_user[\"usernames\"] == \"18202e69-afba-430b-a7f2-cf33c0a173b5\") & (df_user[\"Year_Month\"] == \"2023_06\")]\n", "fig = px.line(a, x='dates_transcription', y='durees_audio_sec')\n", "\n", "# Ajouter la limite de temps\n", "fig.add_shape(type=\"line\",\n", " x0=fig['data'][0]['x'][0],\n", " x1=fig['data'][0]['x'][-1],\n", " y0=72000,\n", " y1=72000,\n", " line=dict(color='red', width=2, dash='dash'))\n", "\n", "fig.add_annotation(x=fig['data'][0]['x'][-1],\n", " y=72000,\n", " text=\"SEUIL DE 20H = 72000 secondes\",\n", " showarrow=False,\n", " font=dict(color=\"red\"),\n", " xshift=-40, # Shift the label to the left\n", " yshift=20) # Shift the label downwards\n", "# Afficher la figure interactive\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "402.6684736394558" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[\"durees_audio_sec\"].sum()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "72000" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3600 *20" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2023-06-14 13:59:03.140847\n" ] } ], "source": [ "from datetime import datetime\n", "\n", "date_string = \"2023-06-14 13:59:03.140847\"\n", "format = \"%Y-%m-%d %H:%M:%S.%f\"\n", "\n", "datetime_obj = datetime.strptime(date_string, format)\n", "print(datetime_obj)\n" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "18" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "datetime_obj.month + 12" ] } ], "metadata": { "kernelspec": { "display_name": "whisper", "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.9.16" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }