こちらで行ったのと同じ計算を Node.js で行いました。
Python3: 接種状況ダッシュボードのデータを使ってワクチン接種済者をカウントする
必要なライブラリーのインストール
npm install csv
npm install date-utils
count_vaccination.js
#! /usr/bin/node
// ---------------------------------------------------------------
// count_vaccination.js
//
// Jan/26/2022
//
// ---------------------------------------------------------------
'use strict'
var fs = require("fs")
var csv = require('csv')
require('date-utils');
// ---------------------------------------------------------------
function get_day_6months_proc()
{
const today = new Date ()
var formatted = today.toFormat("YYYY-MM-DD");
console.log(formatted)
const date1 = new Date ()
date1.setDate(date1.getDate() - 184)
const day_6months = date1.toFormat("YYYY-MM-DD")
return day_6months
}
// ---------------------------------------------------------------
function count_proc(array_aa,day_6months)
{
var second = 0
var second_6months = 0
var third = 0
for (var it in array_aa)
{
const unit_aa = array_aa[it]
if (0 < it)
{
second += parseInt(unit_aa[2],10)
third += parseInt(unit_aa[3],10)
if (unit_aa[0] < day_6months)
{
second_6months += parseInt(unit_aa[2],10)
}
}
}
console.log("second = " + second)
console.log("second_6months = " + second_6months)
console.log("third = " + third)
}
// ---------------------------------------------------------------
console.error ("*** 開始 ***")
const file_csv=process.argv[2]
console.log (file_csv)
const day_6months = get_day_6months_proc()
console.log(day_6months)
fs.readFile(file_csv, function(err, buf)
{
csv.parse(buf.toString(),{comment:'#'}, function(err, array_aa)
{
if (err != null)
{
console.log ("*** error ***")
console.log (err)
}
console.log(array_aa.length)
count_proc(array_aa,day_6months)
console.error ("*** 終了 ***")
})
})
// ---------------------------------------------------------------
実行結果
$ ./count_vaccination.js summary_by_date.csv
*** 開始 ***
summary_by_date.csv
2022-01-26
2021-07-26
290
second = 93846301
second_6months = 29646353
third = 2892327
*** 終了 ***