@scrabble-solver/logger 2.9.0 → 2.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2021 Kamil Mielnik <kamil.adam.mielnik@gmail.com>
1
+ Copyright (c) 2022 Kamil Mielnik <kamil@kamilmielnik.com>
2
2
 
3
3
  Attribution-NonCommercial-NoDerivatives 4.0 International
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrabble-solver/logger",
3
- "version": "2.9.0",
3
+ "version": "2.9.2",
4
4
  "description": "Scrabble Solver 2 - Logger",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  },
11
11
  "author": {
12
12
  "name": "Kamil Mielnik",
13
- "email": "kamil.adam.mielnik@gmail.com",
14
- "url": "https://kamilmielnik.com/"
13
+ "email": "kamil@kamilmielnik.com",
14
+ "url": "https://kamilmielnik.com"
15
15
  },
16
16
  "license": "CC-BY-NC-ND-4.0",
17
17
  "bugs": {
@@ -21,7 +21,8 @@
21
21
  "scripts": {
22
22
  "build": "tsc --project .",
23
23
  "clean": "rimraf build/ node_modules/",
24
- "clean:force": "npm run clean && rimraf package-lock.json"
24
+ "clean:force": "npm run clean && rimraf package-lock.json",
25
+ "stats": "node scripts/stats.js"
25
26
  },
26
27
  "dependencies": {
27
28
  "winston": "^3.8.2"
@@ -29,5 +30,5 @@
29
30
  "devDependencies": {
30
31
  "@types/winston": "^2.4.4"
31
32
  },
32
- "gitHead": "f100d9d52460a68f1fb5a1059cd335029d5e46a8"
33
+ "gitHead": "f50d782088cb89544f0c2c504f31fca81a6ff409"
33
34
  }
@@ -0,0 +1,52 @@
1
+ const fs = require('fs');
2
+ const os = require('os');
3
+ const path = require('path');
4
+ const { argv } = require('process');
5
+
6
+ const DAY = 24 * 60 * 60 * 1000;
7
+
8
+ const getStats = (event, lines, since) => {
9
+ const daysCount = Math.ceil((Date.now() - Number(new Date(since))) / DAY);
10
+ const days = {};
11
+
12
+ let nextIndex = 0;
13
+ while (nextIndex !== -1) {
14
+ nextIndex = lines.indexOf(event, nextIndex + 1);
15
+
16
+ if (nextIndex) {
17
+ const timestampLine = lines[nextIndex + 1];
18
+ const day = timestampLine.substr(` timestamp: '`.length, 'YYYY-MM-DD'.length);
19
+ days[day] = days[day] || 0;
20
+ days[day]++;
21
+ }
22
+ }
23
+
24
+ const filteredDays = Object.fromEntries(
25
+ Object.entries(days).filter(([key]) => {
26
+ return key.localeCompare(since) !== -1;
27
+ }),
28
+ );
29
+
30
+ const sum = Object.entries(filteredDays).reduce((result, [, value]) => result + value, 0);
31
+
32
+ return { daysCount, event, filteredDays, sum };
33
+ };
34
+
35
+ const printStats = ({ daysCount, event, filteredDays, sum }) => {
36
+ console.log('--------------------------------------');
37
+ console.log(event);
38
+ console.log('--------------------------------------');
39
+ console.log(`Sum: ${sum}`);
40
+ console.log(`Avg: ${sum / daysCount}`);
41
+ console.table(filteredDays);
42
+ };
43
+
44
+ const filepath = path.resolve(os.homedir(), '.scrabble-solver', 'logs', 'all.log');
45
+ const file = fs.readFileSync(filepath, 'utf-8');
46
+ const lines = file.split('\n');
47
+ const since = argv[2] || '2021-06-01';
48
+ const events = [` message: 'visit - request',`, ` message: 'solve - request',`, ` message: 'dictionary - request',`];
49
+
50
+ for (const event of events) {
51
+ printStats(getStats(event, lines, since));
52
+ }