From 32419d7d24c3bacf94c01898ee0f60079b46ebd3 Mon Sep 17 00:00:00 2001 From: Shougo-Fukawa Date: Tue, 30 Apr 2024 12:10:25 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=83=A9=E3=83=B3=E3=82=AD=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=81=AE=E5=AE=9F=E8=A3=85=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 0 app.js | 43 +++++++++++++++++++++++++++++++++++++++++++ compose.yaml | 0 3 files changed, 43 insertions(+) mode change 100644 => 100755 Dockerfile mode change 100644 => 100755 app.js mode change 100644 => 100755 compose.yaml diff --git a/Dockerfile b/Dockerfile old mode 100644 new mode 100755 diff --git a/app.js b/app.js old mode 100644 new mode 100755 index ad9a93a..7c81bcf --- a/app.js +++ b/app.js @@ -1 +1,44 @@ 'use strict'; +const fs = require('node:fs'); +const readline = require('node:readline'); +const rs = fs.createReadStream('./popu-pref.csv'); +const rl = readline.createInterface({ input: rs }); +const prefectureDataMap = new Map(); // key: 都道府県 value: 集計データのオブジェクト +rl.on('line', lineString => { + const columns = lineString.split(','); + const year = parseInt(columns[0]); + const prefecture = columns[1]; + const popu = parseInt(columns[3]); + if (year === 2016 || year === 2021) { + let value = null; + if (prefectureDataMap.has(prefecture)) { + value = prefectureDataMap.get(prefecture); + } else { + value = { + before: 0, + after: 0, + change: null + }; + } + if (year === 2016) { + value.before = popu; + } + if (year === 2021) { + value.after = popu; + } + prefectureDataMap.set(prefecture, value); + } +}); +rl.on('close', () => { + for (const [key, value] of prefectureDataMap) { + value.change = value.after / value.before; + } + //console.log(prefectureDataMap); + const rankingArray = Array.from(prefectureDataMap).sort((pair1, pair2) => { + return pair2[1].change - pair1[1].change; + }); + const rankingStrings = rankingArray.map(([key, value]) => { + return `${key}: ${value.before}=>${value.after} 変化率: ${value.change}`; + }); + console.log(rankingStrings); +}); \ No newline at end of file diff --git a/compose.yaml b/compose.yaml old mode 100644 new mode 100755 From 759392659d6d94f9f9d203a9e274815b7f81e227 Mon Sep 17 00:00:00 2001 From: Shougo-Fukawa Date: Tue, 30 Apr 2024 12:22:20 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=83=A9=E3=83=B3=E3=82=AD=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 0 app.js | 0 compose.yaml | 0 popu-pref.csv | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 Dockerfile mode change 100755 => 100644 app.js mode change 100755 => 100644 compose.yaml mode change 100755 => 100644 popu-pref.csv diff --git a/Dockerfile b/Dockerfile old mode 100755 new mode 100644 diff --git a/app.js b/app.js old mode 100755 new mode 100644 diff --git a/compose.yaml b/compose.yaml old mode 100755 new mode 100644 diff --git a/popu-pref.csv b/popu-pref.csv old mode 100755 new mode 100644 From 43de46b686cc56145db58cae9dbe579e2773ffc4 Mon Sep 17 00:00:00 2001 From: Shougo-Fukawa Date: Tue, 30 Apr 2024 12:34:40 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BA=BA=E3=81=8C=E6=B8=9B=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E5=89=B2=E5=90=88=E3=81=AE=E3=83=A9=E3=83=B3=E3=82=AD?= =?UTF-8?q?=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 7c81bcf..6699b4a 100644 --- a/app.js +++ b/app.js @@ -35,10 +35,10 @@ rl.on('close', () => { } //console.log(prefectureDataMap); const rankingArray = Array.from(prefectureDataMap).sort((pair1, pair2) => { - return pair2[1].change - pair1[1].change; + return pair1[1].change - pair2[1].change; }); - const rankingStrings = rankingArray.map(([key, value]) => { - return `${key}: ${value.before}=>${value.after} 変化率: ${value.change}`; + const rankingStrings = rankingArray.map(([key, value],i) => { + return `${i+1}位 ${key}: ${value.before}=>${value.after} 変化率: ${value.change}`; }); console.log(rankingStrings); }); \ No newline at end of file