Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. const fs = require('fs');
  2.  
  3. const lines = fs
  4. .readFileSync('./logs.txt', 'utf-8')
  5. .split('\n')
  6. .map((line) => line.trim());
  7.  
  8.  
  9. // [08:31, 7/31/2018] Nikolay: 90.3
  10. // [07:18, 12/16/2018] Nikolay: 94,6
  11. const WEIGHT_RECORD_REGEXP = /(\d+\/\d+\/\d+)\] Nikolay: (\d+[,.]\d+)/;
  12.  
  13. // [07:05, 7/18/2018] Nikolay: 105/75/70
  14. const PRESSURE_RECORD_REGEXP = /(\d+\/\d+\/\d+)\] Nikolay: (\d+\/\d+\/\d+)/;
  15.  
  16. const START_DATE = new Date(2018, 6, 1, 0, 0, 0);
  17. const END_DATE = new Date();
  18.  
  19. const weightRecords = {};
  20. const pressureRecords = {};
  21. lines.forEach((line) => {
  22. const weightRecordMatches = line.match(WEIGHT_RECORD_REGEXP);
  23. const pressureRecordMatches = line.match(PRESSURE_RECORD_REGEXP);
  24.  
  25. if(weightRecordMatches !== null) {
  26. const weight = parseFloat(weightRecordMatches[2].replace(',', '.'));
  27. weightRecords[weightRecordMatches[1]] = weight;
  28. }
  29. else if (pressureRecordMatches !== null) {
  30. pressureRecords[pressureRecordMatches[1]] = pressureRecordMatches[2].split('/');
  31. }
  32. });
  33.  
  34. // Export weight records
  35. // for(let date = START_DATE.getTime(); date < END_DATE; date += 24 * 3600 *1000) {
  36. // const day = new Date(date);
  37. // const key = `${day.getDate()}/${day.getMonth()+1}/${day.getFullYear()}`;
  38. // console.log(`${key};${weightRecords[key] ? weightRecords[key]: ''}`);
  39. // }
  40.  
  41. // Export pressure records
  42. for(let date = START_DATE.getTime(); date < END_DATE; date += 24 * 3600 *1000) {
  43. const day = new Date(date);
  44. const key = `${day.getDate()}/${day.getMonth()+1}/${day.getFullYear()}`;
  45.  
  46. console.log(`${key};;${pressureRecords[key] ? pressureRecords[key].join(';'): ''}`);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement