{"id":196,"date":"2022-03-14T16:33:33","date_gmt":"2022-03-14T15:33:33","guid":{"rendered":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/?p=196"},"modified":"2022-05-03T11:27:15","modified_gmt":"2022-05-03T09:27:15","slug":"projet-votrex","status":"publish","type":"post","link":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/2022\/03\/14\/projet-votrex\/","title":{"rendered":"Projet Vortex"},"content":{"rendered":"\n<p>  Ouvrir le fichier BORDEAUX matches.csv<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"696\" height=\"948\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-12.png\" alt=\"\" class=\"wp-image-197\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-12.png 696w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-12-220x300.png 220w\" sizes=\"(max-width: 696px) 100vw, 696px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"661\" height=\"472\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-13.png\" alt=\"\" class=\"wp-image-200\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-13.png 661w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-13-300x214.png 300w\" sizes=\"(max-width: 661px) 100vw, 661px\" \/><\/figure>\n\n\n\n<p>Version google colab:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"925\" height=\"474\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-15.png\" alt=\"\" class=\"wp-image-204\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-15.png 925w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-15-300x154.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-15-768x394.png 768w\" sizes=\"(max-width: 925px) 100vw, 925px\" \/><\/figure>\n\n\n\n<p>Ce fichier nous donne des informations sur les partie jou\u00e9es en Janvier \u00e0 Bordeaux<\/p>\n\n\n\n<p>Une ligne correspond \u00e0 une partie et le nombre de joueurs constituant l\u2019\u00e9quipe pour cette partie est donn\u00e9 par la colonne \u2018v\u2019.<\/p>\n\n\n\n<p>Gr\u00e2ce \u00e0 la colonne &lsquo;game&rsquo;,  on peut identifier deux jeux diff\u00e9rents<\/p>\n\n\n\n<p class=\"has-text-color\" style=\"color:#00ff17\"><strong>Objectif: Ecrire un programme capable de produire un fichier Excel<\/strong><\/p>\n\n\n\n<p class=\"has-white-color has-text-color\">&gt; Abr\u00e9ger les donn\u00e9es par date avec le nombre de joueurs de parties et le d\u00e9tail pour chacun d&rsquo;eux. On va s&rsquo;en servir d&rsquo;un autre fichier qui d\u00e9finit les codes des jeux:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"406\" height=\"309\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-14.png\" alt=\"\" class=\"wp-image-202\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-14.png 406w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-14-300x228.png 300w\" sizes=\"(max-width: 406px) 100vw, 406px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color\" style=\"color:#b978ff\"><strong>Les \u00e9tapes:<\/strong><\/p>\n\n\n\n<p>\u21a6 Importer des fichiers n\u00e9cessaires<\/p>\n\n\n\n<p>\u21a6 Identifier les jeux<\/p>\n\n\n\n<p>\u21a6 Lire un fichier csv matches.csv<\/p>\n\n\n\n<p>\u21a6 Filtrer les donn\u00e9es<\/p>\n\n\n\n<p>\u21a6 Traitement de &lsquo;StartDateTime&rsquo; soit en rempla\u00e7ant une table, soit en cr\u00e9er une autre sans prendre compte l&rsquo;heure<\/p>\n\n\n\n<p>\u21a6 S\u00e9parer les deux tables en fonction du jeu <\/p>\n\n\n\n<p>\u21a6 Agr\u00e9ger par date par rapport \u00e0 l&rsquo;exploitation apocalypse <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Le lien vers mon colab:<\/p>\n\n\n\n<p><a href=\"https:\/\/colab.research.google.com\/drive\/1ybyM7ZSGX8LlwUTYVV7WbWRhnel8ENbU?usp=sharing\">https:\/\/colab.research.google.com\/drive\/1ybyM7ZSGX8LlwUTYVV7WbWRhnel8ENbU?usp=sharing<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"606\" height=\"626\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-17.png\" alt=\"\" class=\"wp-image-218\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-17.png 606w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-17-290x300.png 290w\" sizes=\"(max-width: 606px) 100vw, 606px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"723\" height=\"572\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-18.png\" alt=\"\" class=\"wp-image-219\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-18.png 723w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-18-300x237.png 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/figure>\n\n\n\n<p>On remarque que \u00e7a a bien tri\u00e9 les deux types de jeux. Maintenant on lit le fichier en triant les jeux<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"834\" height=\"814\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-20.png\" alt=\"\" class=\"wp-image-222\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-20.png 834w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-20-300x293.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-20-768x750.png 768w\" sizes=\"(max-width: 834px) 100vw, 834px\" \/><\/figure>\n\n\n\n<p>On filtre par date:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"840\" height=\"624\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-21.png\" alt=\"\" class=\"wp-image-223\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-21.png 840w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-21-300x223.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-21-768x571.png 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<p>On a modifi\u00e9 la colonne date en supprimant l&rsquo;heure:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"607\" height=\"592\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-22.png\" alt=\"\" class=\"wp-image-226\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-22.png 607w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/03\/image-22-300x293.png 300w\" sizes=\"(max-width: 607px) 100vw, 607px\" \/><\/figure>\n\n\n\n<p>Correction:<\/p>\n\n\n\n<p>import pandas as pd<\/p>\n\n\n\n<p>from google.colab import files<br>data_to_load = files.upload()<\/p>\n\n\n\n<p>matches= pd.read_csv(&lsquo;BORDEAUX matches.csv&rsquo;,encoding = \u00ab\u00a0ISO-8859-1\u00a0\u00bb)<\/p>\n\n\n\n<p>def simplifie_date(val):<br>return str(val).split(&lsquo;T&rsquo;)[0]<\/p>\n\n\n\n<p>indexNames = matches[matches[&lsquo;startDatetime&rsquo;].isnull()|matches[&lsquo;game&rsquo;].isnull()|matches[&lsquo;__v&rsquo;].isnull()].index<br>matches.drop(indexNames , inplace=True)<\/p>\n\n\n\n<p>matches[&lsquo;date&rsquo;]=matches[&lsquo;startDatetime&rsquo;].apply(simplifie_date)<br>matches[&lsquo;\u00e9quipe&rsquo;]=1<\/p>\n\n\n\n<p>games = matches.groupby(\u00ab\u00a0game\u00a0\u00bb)<br>origine= games.get_group(&lsquo;5fc126fcabc9c6bb54078531&rsquo;)<br>apocalypse=games.get_group(&lsquo;604743157d0d2804c8abb4f8&rsquo;)<\/p>\n\n\n\n<p>origine_players=origine.groupby([&lsquo;date&rsquo;])[&lsquo;__v&rsquo;].agg(&lsquo;sum&rsquo;).to_frame()<br>origine_equipe=origine.groupby([&lsquo;date&rsquo;])[&lsquo;\u00e9quipe&rsquo;].agg(&lsquo;sum&rsquo;).to_frame()<br>origine_matches=pd.DataFrame()<br>origine_players_equipe = pd.merge(origine_players,origine_equipe, on=&rsquo;date&rsquo;)<\/p>\n\n\n\n<p>dico={&lsquo;__v&rsquo;:&rsquo;players_origine&rsquo;,&rsquo;\u00e9quipe&rsquo;:&rsquo;equipe_origine&rsquo;}<br>origine_players_equipe.rename(columns=dico,inplace=True)<\/p>\n\n\n\n<p>apocalypse_players=apocalypse.groupby([&lsquo;date&rsquo;])[&lsquo;__v&rsquo;].agg(&lsquo;sum&rsquo;).to_frame()<br>apocalypse_equipe=apocalypse.groupby([&lsquo;date&rsquo;])[&lsquo;\u00e9quipe&rsquo;].agg(&lsquo;sum&rsquo;).to_frame()<br>apocalypse_matches=pd.DataFrame()<br>apocalypse_players_equipe = pd.merge(apocalypse_players,apocalypse_equipe, on=&rsquo;date&rsquo;)<br>apocalypse_players_equipe.rename(columns={&lsquo;__v&rsquo;:&rsquo;players_apocalypse&rsquo;,&rsquo;\u00e9quipe&rsquo;:&rsquo;equipe_apocalypse&rsquo;},inplace=True)<\/p>\n\n\n\n<p>origine_apocalypse_jour = pd.merge(origine_players_equipe,apocalypse_players_equipe, on=&rsquo;date&rsquo;)<\/p>\n\n\n\n<p>origine_apocalypse_jour[&lsquo;players&rsquo;]=origine_apocalypse_jour[&lsquo;players_origine&rsquo;]+origine_apocalypse_jour[&lsquo;players_apocalypse&rsquo;]<br>origine_apocalypse_jour[&lsquo;equipes&rsquo;]=origine_apocalypse_jour[&lsquo;equipe_origine&rsquo;]+origine_apocalypse_jour[&lsquo;equipe_apocalypse&rsquo;]<\/p>\n\n\n\n<p>origine_apocalypse_jour.to_excel(&lsquo;1matches_origine_apocalypse_jour.xlsx&rsquo;,sheet_name=&rsquo;bordeaux&rsquo;)<\/p>\n\n\n\n<p>import matplotlib.pyplot as plt<br>graphiques=[&lsquo;players_origine&rsquo;,&rsquo;players_apocalypse&rsquo;,&rsquo;players&rsquo;,&rsquo;equipe_origine&rsquo;,&rsquo;equipe_apocalypse&rsquo;,&rsquo;equipes&rsquo;]<br>ax=origine_apocalypse_jour.plot(y=graphiques,grid=True,kind=\u00a0\u00bbbar\u00a0\u00bb,figsize=(20,10))<br>ax.set_ylabel(&lsquo;nombre de joueurs par jour&rsquo;)<br>ax.set_xlabel(&lsquo;date&rsquo;)<br>plt.show()<\/p>\n\n\n\n<p class=\"has-extra-large-font-size\"><strong>Sous &#8211; projet<\/strong> 2<\/p>\n\n\n\n<p>Enlever l&rsquo;heure de la colonne \u00ab\u00a0Enregistr\u00e9 le\u00a0\u00bb<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"524\" src=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/04\/image-2-1024x524.png\" alt=\"\" class=\"wp-image-278\" srcset=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/04\/image-2-1024x524.png 1024w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/04\/image-2-300x154.png 300w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/04\/image-2-768x393.png 768w, http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-content\/uploads\/sites\/2\/2022\/04\/image-2.png 1271w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><a href=\"https:\/\/colab.research.google.com\/drive\/1cFmFQSsANwMNNxTIfQF8vHqQwjHMA5dZ#scrollTo=Njf8kq3o-Fon\">https:\/\/colab.research.google.com\/drive\/1cFmFQSsANwMNNxTIfQF8vHqQwjHMA5dZ#scrollTo=Njf8kq3o-Fon<\/a><\/p>\n\n\n\n<p>solution:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from google.colab import files\r\ndata_to_load = files.upload()\r\n\r\n# import des librairies\r\nimport pandas as pd\r\nimport matplotlib.pyplot as plt \r\n\r\n# lecture fichier excel\r\nventes = pd.read_excel('LYON vortex.xlsx',sheet_name='1 6 D\u00e9tails des ventes')\r\n\r\n#Filtrage fichier\r\nventes.query('Cat\u00e9gorie ==&#091;\"R\u00e9servation\",\"BILLETERIE\",\"CE ET ENTREPRISES\"]',inplace=True)\r\nindexNames = ventes&#091; ventes&#091;'Montant TTC'] &amp;lt;0 |ventes&#091;'Enregistr\u00e9 le'].isnull()|ventes&#091;'Cat\u00e9gorie'].isnull()].index\r\nventes.drop(indexNames , inplace=True)\r\n\r\n#modification de la colonne \"enregistr\u00e9 le\" et ajout d'une colonne partie\r\nventes&#091;'Enregistr\u00e9 le']=ventes&#091;'Enregistr\u00e9 le'].apply(lambda t : t.split()&#091;0])\r\nventes&#091;'partie']=1\r\n\r\n#agr\u00e9gation des lignes par jour avec sommation des quantit\u00e9s\r\njoueurs_par_jour=ventes.groupby(&#091;'Enregistr\u00e9 le' ])&#091;'Quantit\u00e9'].agg('sum').to_frame()\r\n\r\n#agr\u00e9gation des lignes par jour avec sommation des parties\r\nparties_par_jour=ventes.groupby(&#091;'Enregistr\u00e9 le'])&#091;'partie'].agg('sum').to_frame()\r\n\r\n#cr\u00e9ation de 3 lots en fonction du 'produit' vendu\r\nventes_lot1=ventes.query('Produit ==&#091;\"VORTEX APOCALYPSE\",\"VORTEX ORIGINE\",\"VORTEX NOEL 12 17 ANS\",\\\r\n                            \"VORTEX ORIGINE Tarif \u00e9tudiants\",\"VORTEX APOCALYPSE Tarif Etudiants\"]')\r\n\r\njoueurs_par_jour_lot1=ventes_lot1.groupby(&#091;'Enregistr\u00e9 le' ])&#091;'Quantit\u00e9'].agg('sum').to_frame()\r\njoueurs_par_jour_lot1.rename(columns={'Quantit\u00e9':\"lot1\"},inplace=True)\r\n\r\nventes_lot2=ventes.query('Produit ==&#091;\"RESERVATION GIFT CARD VORTEX ORIGINE\",\"RESERVATION GIFT CARD VORTEX APOCALYPSE\"]')\r\njoueurs_par_jour_lot2=ventes_lot2.groupby(&#091;'Enregistr\u00e9 le' ])&#091;'Quantit\u00e9'].agg('sum').to_frame()\r\njoueurs_par_jour_lot2.rename(columns={'Quantit\u00e9':\"lot2\"},inplace=True)\r\n\r\nventes_lot3=ventes.query('Produit ==&#091;\"CARTE CADEAU 1E ENTREE\",\"Vortex Team building\",\"Vortex Team Building Privatisation\"]')\r\njoueurs_par_jour_lot3=ventes_lot3.groupby(&#091;'Enregistr\u00e9 le' ])&#091;'Quantit\u00e9'].agg('sum').to_frame()\r\njoueurs_par_jour_lot3.rename(columns={'Quantit\u00e9':\"lot3\"},inplace=True)\r\n\r\n#concat\u00e9nation des trois lots et ajout des valeurs manquantes et du total des lots\r\nstats=pd.concat(&#091;joueurs_par_jour_lot1,joueurs_par_jour_lot2,joueurs_par_jour_lot3], ignore_index=False,axis=1)\r\nstats.sort_values(by=&#091;'Enregistr\u00e9 le'],inplace=True)\r\nstats.fillna(0,inplace =True)\r\nstats&#091;'total']=stats&#091;'lot1']+stats&#091;'lot2']+stats&#091;'lot3']\r\n\r\n#visualisation\r\nstats.to_excel('stats.xlsx')\r\n\r\nax=stats.plot(y=&#091;'lot1','lot2','lot3'],grid=True,kind=\"bar\",figsize=(20,10)) \r\nax.set_ylabel('nombre de parties par jour')\r\nax.set_xlabel('date')<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ouvrir le fichier BORDEAUX matches.csv Version google colab: Ce fichier nous donne des informations sur les partie jou\u00e9es en Janvier \u00e0 Bordeaux Une ligne correspond \u00e0 une partie et le nombre de joueurs constituant l\u2019\u00e9quipe pour cette partie est donn\u00e9 par la colonne \u2018v\u2019. Gr\u00e2ce \u00e0 la colonne &lsquo;game&rsquo;, on peut identifier deux jeux diff\u00e9rents&hellip; <a class=\"more-link\" href=\"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/2022\/03\/14\/projet-votrex\/\">Poursuivre la lecture <span class=\"screen-reader-text\">Projet Vortex<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-json\/wp\/v2\/posts\/196"}],"collection":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-json\/wp\/v2\/comments?post=196"}],"version-history":[{"count":25,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-json\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":294,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-json\/wp\/v2\/posts\/196\/revisions\/294"}],"wp:attachment":[{"href":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-json\/wp\/v2\/media?parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-json\/wp\/v2\/categories?post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yb-isn.fr\/2021\/nsi\/olga\/wp-json\/wp\/v2\/tags?post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}