Guest User

gen_graphs.js

a guest
Jun 7th, 2022
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import fs from "fs";
  2. import { open } from "sqlite";
  3. import SQL from 'sql-template-strings';
  4. import sqlite3 from "sqlite3";
  5.  
  6. const hydrus_path = "/path/to/your/hydrus/db/";
  7.  
  8. const db = await open({ filename: `${hydrus_path}client.db`, driver: sqlite3.Database });
  9.  
  10. const timestamps = await db.all(SQL`
  11.   SELECT timestamp FROM current_files_3
  12. `);
  13.  
  14. timestamps.sort((a, b) => a.timestamp - b.timestamp);
  15.  
  16. const dates = {};
  17. const hours = {};
  18.  
  19. for(const { timestamp } of timestamps) {
  20.   const time = new Date(timestamp * 1000);
  21.   const date = `${time.getFullYear()}-${time.getMonth() + 1}-${time.getDate()}`;
  22.   const hour = time.getHours();
  23.  
  24.   dates[date] ||= 0;
  25.   dates[date]++;
  26.   hours[hour] ||= 0;
  27.   hours[hour]++;
  28. }
  29.  
  30. let agg = 0;
  31.  
  32. const datesText = Object.entries(dates)
  33.                         .map(([date, count]) => {
  34.                           agg += count;
  35.                           return date + "\t" + agg;
  36.                         })
  37.                         .join("\n");
  38. const hoursText = Object.entries(hours)
  39.                         .map(([hour, count]) => hour + "\t" + count)
  40.                         .sort()
  41.                         .join("\n");
  42.  
  43. fs.writeFileSync("dates.tsv", datesText);
  44. fs.writeFileSync("hours.tsv", hoursText);
  45.  
Advertisement
Add Comment
Please, Sign In to add comment