-
Notifications
You must be signed in to change notification settings - Fork 0
/
idid.js
executable file
·76 lines (64 loc) · 2.51 KB
/
idid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
// ========= configurable
const PROJECT_RATES = {
project: 0,
chores: 0,
corsair: 50,
wizards: 50,
'corsair-discounted': 30,
default: 50,
}
const FILE_PATH = '/Users/Jan/Dropbox/times.txt'
// ========= includes
const readline = require('readline');
const fs = require('fs');
const moment = require('moment')
const parser = require('./lib/parser')
const formatter = require('./lib/formatter')
// ========= helpers
let lines = []
let linenumber = 0
let onReadLine = (line) => {
linenumber++;
let info = parser.extract_info(line)
if(info) {
lines.push({
...info,
number: linenumber,
});
}
};
// =============== main
const main = () => {
let blocks = parser.collectBlocks(lines)
let today = moment(moment.now())
let yesterday = moment().subtract(1, 'day')
let lastWeek = moment().subtract(1, 'week')
let lastMonth = moment().subtract(1, 'month')
let sumsToday = parser.combineBlocks(blocks, moment(today.clone().startOf('day')), moment(today.clone().endOf('day')), PROJECT_RATES)
let sumsYesterday = parser.combineBlocks(blocks, moment(yesterday.clone().startOf('day')), moment(yesterday.clone().endOf('day')), PROJECT_RATES)
let sums2days = parser.combineBlocks(blocks, moment(yesterday.clone().startOf('day')), moment(today.clone().endOf('day')), PROJECT_RATES)
let sumsWeek = parser.combineBlocks(blocks, moment(today.clone().startOf('week')), moment(today.clone().endOf('week')), PROJECT_RATES)
let sumsLastWeek = parser.combineBlocks(blocks, moment(lastWeek.clone().startOf('week')), moment(lastWeek.clone().endOf('week')), PROJECT_RATES)
let sumsMonth = parser.combineBlocks(blocks, moment(today.clone().startOf('month')), moment(today.clone().endOf('month')), PROJECT_RATES)
let sumsLastMonth = parser.combineBlocks(blocks, moment(lastMonth.clone().startOf('month')), moment(lastMonth.clone().endOf('month')), PROJECT_RATES)
let sumsYear = parser.combineBlocks(blocks, moment(today.clone().startOf('year')), moment(today.clone().endOf('year')), PROJECT_RATES)
let sumsTotal = parser.combineBlocks(blocks, null, null, PROJECT_RATES)
let namedRanges = {
"Total": sumsTotal,
"Year": sumsYear,
"Last month": sumsLastMonth,
"Month": sumsMonth,
"Last Week": sumsLastWeek,
"Week": sumsWeek,
"Last two days": sums2days,
"Yesterday": sumsYesterday,
"Today": sumsToday,
}
formatter.prettyOutput(namedRanges)
}
let rl = readline.createInterface({
input: fs.createReadStream(FILE_PATH)
});
rl.on('line', onReadLine)
rl.on('close', main)