ken_nogi/NodeJS/Care7/2_DataAnalyze.js
Kenichiro NOGI 51a95c5e21 NodeJS
2025-07-10 10:12:37 +09:00

59 lines
2.0 KiB
JavaScript

function analyze(csvData, year, month) {
const rows = csvData.trim().split('\n');
const dataArray = rows.map(row => row.split(','));
const holidays = getHolidayTable(year, month);
}
//プリザンターの祝日テーブルから祝日データを取得する
async function getHolidayTable(year, month) {
const holidayTable = '281723';
const location = 'neo999.next-he.net'; // プリザンターのホスト名を指定
const holidays = [];
//引数のyear,monthの前後1ヶ月の日付おw開始時間終了時間として日付文字列を作成
year = 2024
month = 5
year = Number(year);
month = Number(month);
const startDate = new Date(year, month - 2, 1);
const endDate = new Date(year, month + 1, 0);
const startTime = `${startDate.getFullYear()}/${startDate.getMonth() + 1}/1 00:00:00`;
const endTime = `${endDate.getFullYear()}/${endDate.getMonth() + 1}/${endDate.getDate()} 23:59:59`;
//プリザンターからデータを取得
const apiKey = '6504c8a807677a3a576e10327f3c19876c55736ee45d4a845796b9e7f5e087bfd4bd0d8184863da8cf1733ca635111432ab334aea59102b06a96ee6d2c05190d';
const url = 'https://' + location + '/pleasanter/api/items/' + holidayTable + '/get';
const jsonBody = {
'ApiVersion': 1.1,
'ApiKey': apiKey,
'View': {
'ColumnFilterHash': {
'DateA': `["${startTime}","${endTime}"]`,
},
}
}
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(jsonBody)
});
const resData = await res.json();
for (let data of resData.Response.Data) {
const holiday = new Date(data.DateHash.DateA);
const holidayStr = holiday.getFullYear() + '-' +
(holiday.getMonth() + 1).toString().padStart(2, '0') + '-' +
(holiday.getDate()).toString().padStart(2, '0');
holidays.push(holidayStr);
}
return holidays;
}