Created
October 26, 2020 13:30
-
-
Save OwlyCode/b880fab7e92fbe55b489b0a3b826281e to your computer and use it in GitHub Desktop.
Total des décès calculés de janvier à septembre selon l'INSEE : https://www.insee.fr/fr/information/4190491
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Téléchargez les données de l'INSEE dans le même dossier que ce script. Renommez deces-2020-m1.csv en Deces_2020_M01.csv | |
afin de suivre la convention des mois suivants. | |
Mes résultats : | |
2018/01 : 60525 | |
2018/02 : 52822 | |
2018/03 : 61074 | |
2018/04 : 51008 | |
2018/05 : 48425 | |
2018/06 : 45569 | |
2018/07 : 48861 | |
2018/08 : 47761 | |
2018/09 : 46193 | |
Total 2018 janvier à septembre : 462238 | |
2019/01 : 61148 | |
2019/02 : 56463 | |
2019/03 : 54330 | |
2019/04 : 49720 | |
2019/05 : 49671 | |
2019/06 : 46993 | |
2019/07 : 48669 | |
2019/08 : 47566 | |
2019/09 : 46596 | |
Total 2019 janvier à septembre : 461156 | |
2020/01 : 57952 | |
2020/02 : 51884 | |
2020/03 : 63629 | |
2020/04 : 67405 | |
2020/05 : 49527 | |
2020/06 : 46601 | |
2020/07 : 47405 | |
2020/08 : 49170 | |
2020/09 : 40055 | |
Total 2020 janvier à septembre : 473628 | |
*/ | |
$row = 1; | |
function countDeaths($year) | |
{ | |
$total = 0; | |
$monthes = ['01' => 0, '02' => 0, '03' => 0, '04' => 0, '05' => 0, '06' => 0, '07' => 0, '08' => 0, '09' => 0]; | |
if (($handle = fopen("deces-${year}.csv", 'r')) !== false) { | |
while (($data = fgetcsv($handle, 1000, ';')) !== false) { | |
if ($data[6] === 'datedeces') { // ignorer l'entête | |
continue; | |
} | |
$date = new \DateTime($data[6]); | |
if ($date >= new \DateTime("${year}-01-01") && $date < new \DateTime("${year}-10-01")) { | |
$monthes[$date->format('m')]++; | |
$total++; | |
} | |
} | |
foreach ($monthes as $key => $value) { | |
echo "$year/$key : $value\n"; | |
} | |
echo "Total ${year} janvier à septembre : ".$total."\n\n"; | |
fclose($handle); | |
} | |
} | |
function countDeaths2020() | |
{ | |
$total = 0; | |
$monthes = ['01' => 0, '02' => 0, '03' => 0, '04' => 0, '05' => 0, '06' => 0, '07' => 0, '08' => 0, '09' => 0]; | |
foreach (array_keys($monthes) as $month) { | |
if (($handle = fopen("Deces_2020_M${month}.csv", 'r')) !== false) { | |
while (($data = fgetcsv($handle, 1000, ';')) !== false) { | |
if ($data[6] === 'datedeces') { // ignorer l'entête | |
continue; | |
} | |
$date = new \DateTime($data[6]); | |
if ($date >= new \DateTime('2020-01-01') && $date < new \DateTime('2020-10-01')) { | |
$monthes[$date->format('m')]++; | |
$total++; | |
} | |
} | |
fclose($handle); | |
} | |
} | |
foreach ($monthes as $key => $value) { | |
echo "2020/$key : $value\n"; | |
} | |
echo 'Total 2020 janvier à septembre : '.$total."\n\n"; | |
} | |
countDeaths(2018); | |
countDeaths(2019); | |
countDeaths2020(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment