forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat.ts
More file actions
39 lines (32 loc) · 1.03 KB
/
stat.ts
File metadata and controls
39 lines (32 loc) · 1.03 KB
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
/**
* Copyright (c) 2022 Hengyang Zhang
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
import { judgeVirtualFast } from "./pattern"
export function isNotZeroResult(target: timer.stat.Result): boolean {
return !!target.focus || !!target.time
}
export function createZeroResult(): timer.stat.Result {
return { focus: 0, time: 0 }
}
export function mergeResult(a: timer.stat.Result, b: timer.stat.Result): timer.stat.Result {
return {
focus: (a?.focus ?? 0) + (b?.focus ?? 0),
time: (a?.time ?? 0) + (b?.time ?? 0),
}
}
export function resultOf(focus: number, time: number): timer.stat.Result {
return { focus, time }
}
export function rowOf(key: timer.stat.RowKey, item?: timer.stat.Result): timer.stat.Row {
return {
...key,
focus: item && item.focus || 0,
time: item && item.time || 0,
mergedHosts: [],
virtual: judgeVirtualFast(key.host),
}
}
export const ALL_DIMENSIONS: timer.stat.Dimension[] = ['focus', 'time']