-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathstat.ts
More file actions
81 lines (64 loc) · 2.52 KB
/
stat.ts
File metadata and controls
81 lines (64 loc) · 2.52 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
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
77
78
79
80
81
import { identifySiteKey } from "./site"
/**
* Copyright (c) 2022 Hengyang Zhang
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
export function isNotZeroResult(target: timer.core.Result): boolean {
return !!target.focus || !!target.time
}
export function resultOf(focus: number, time: number): timer.core.Result {
return { focus, time }
}
export const ALL_DIMENSIONS: timer.core.Dimension[] = ['focus', 'time']
export function identifyTargetKey(targetKey: timer.stat.TargetKey): string {
if ('cateKey' in targetKey) {
return `cate_${targetKey.cateKey}`
} else if ('siteKey' in targetKey) {
return identifySiteKey(targetKey.siteKey)
} else {
return `group_${targetKey.groupKey}`
}
}
export function identifyStatKey(rowKey: timer.stat.StatKey) {
const { date } = rowKey || {}
return [identifyTargetKey(rowKey), date ?? ''].join('_')
}
export const isNormalSite = (row: timer.stat.Row): row is timer.stat.SiteRow => {
return 'siteKey' in row && row.siteKey.type === 'normal'
}
export const isMergedSite = (row: timer.stat.Row): row is timer.stat.SiteRow => {
return 'siteKey' in row && row.siteKey.type === 'merged'
}
export const isGroup = (row: timer.stat.Row): row is timer.stat.GroupRow => {
return 'groupKey' in row
}
export const isSite = (row: timer.stat.Row): row is timer.stat.SiteRow => {
return 'siteKey' in row
}
export const isCate = (row: timer.stat.Row): row is timer.stat.CateRow => {
return 'cateKey' in row
}
export const getHost = (row: timer.stat.Row): string | undefined => {
return 'siteKey' in row ? row.siteKey.host : undefined
}
export const getAlias = (row: timer.stat.Row): string | undefined => {
return 'alias' in row ? row.alias : undefined
}
export const getIconUrl = (row: timer.stat.Row): string | undefined => {
return 'iconUrl' in row ? row.iconUrl : undefined
}
export const getRelatedCateId = (row: timer.stat.Row): number | undefined => {
if ('cateId' in row) return row.cateId
if ('cateKey' in row) return row.cateKey
return undefined
}
export const getComposition = (row: timer.stat.Row, dimension: timer.core.Dimension): timer.stat.RemoteCompositionVal[] => {
return 'composition' in row ? row.composition?.[dimension] ?? [] : []
}
export const getGroupName = (groupMap: Record<string, chrome.tabGroups.TabGroup>, row: timer.stat.GroupRow): string => {
const { groupKey } = row
const title = groupMap[groupKey]?.title
return title ?? `ID: ${groupKey}`
}