Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const lines = fs
- .readFileSync('./logs.txt', 'utf-8')
- .split('\n')
- .map((line) => line.trim());
- // [08:31, 7/31/2018] Nikolay: 90.3
- // [07:18, 12/16/2018] Nikolay: 94,6
- const WEIGHT_RECORD_REGEXP = /(\d+\/\d+\/\d+)\] Nikolay: (\d+[,.]\d+)/;
- // [07:05, 7/18/2018] Nikolay: 105/75/70
- const PRESSURE_RECORD_REGEXP = /(\d+\/\d+\/\d+)\] Nikolay: (\d+\/\d+\/\d+)/;
- const START_DATE = new Date(2018, 6, 1, 0, 0, 0);
- const END_DATE = new Date();
- const weightRecords = {};
- const pressureRecords = {};
- lines.forEach((line) => {
- const weightRecordMatches = line.match(WEIGHT_RECORD_REGEXP);
- const pressureRecordMatches = line.match(PRESSURE_RECORD_REGEXP);
- if(weightRecordMatches !== null) {
- const weight = parseFloat(weightRecordMatches[2].replace(',', '.'));
- weightRecords[weightRecordMatches[1]] = weight;
- }
- else if (pressureRecordMatches !== null) {
- pressureRecords[pressureRecordMatches[1]] = pressureRecordMatches[2].split('/');
- }
- });
- // Export weight records
- // for(let date = START_DATE.getTime(); date < END_DATE; date += 24 * 3600 *1000) {
- // const day = new Date(date);
- // const key = `${day.getDate()}/${day.getMonth()+1}/${day.getFullYear()}`;
- // console.log(`${key};${weightRecords[key] ? weightRecords[key]: ''}`);
- // }
- // Export pressure records
- for(let date = START_DATE.getTime(); date < END_DATE; date += 24 * 3600 *1000) {
- const day = new Date(date);
- const key = `${day.getDate()}/${day.getMonth()+1}/${day.getFullYear()}`;
- console.log(`${key};;${pressureRecords[key] ? pressureRecords[key].join(';'): ''}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement