-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathliskin-arbtt-stats
More file actions
executable file
·116 lines (97 loc) · 2.64 KB
/
Copy pathliskin-arbtt-stats
File metadata and controls
executable file
·116 lines (97 loc) · 2.64 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
set -eu -o pipefail
shopt -s lastpipe
shopt -u checkwinsize
filter=()
exclude=()
# shellcheck source-path=..
. "$HOME"/bin/.o
function parse-day {
if [[ ${1:?} == ^* ]]; then
date -d "$(task calc "${1#^}")" +%F
else
date -d "$1" +%F
fi
}
function date-range {
d1=$(parse-day "${1:-today - 3 hour}")
d2=$(parse-day "${2:-$d1 + 1 day}")
t1="03:00"
t2="03:00"
filter+=(--filter="\$date >= ${d1}${t1} && \$date < ${d2}${t2}")
}
function arbtt-stats-foreach {
for log in ~/.arbtt/capture-:?.log; do
if (( $(stat -c%s "$log") > 17 )); then
o arbtt-stats --logfile="$log" "$@"
echo
fi
done
}
function activity-chart { #complete
date-range "$@"
{
arbtt-stats-foreach "${filter[@]}" "${exclude[@]}" --min-percentage=0 --category=Activity --output-format=csv \
| sed 's/^(total time)/(screen)/; s/^(unmatched time)/Activity:(???)/; s/UNKNOWN/(???)/'
arbtt-stats-strava
} | arbtt-chart --subtags --totals-re '^\(screen\)$'
}
function arbtt-stats-strava {
[[ -f ~/.local/share/strava_offline/strava.sqlite ]] || return 0
o sqlite3 ~/.local/share/strava_offline/strava.sqlite \
".mode csv" ".headers on" \
"
SELECT
CASE
WHEN type='Workout' AND name GLOB 'VR*' THEN 'Activity:Games-VR'
ELSE 'Activity:Sport-' || type
END as Tag,
SUM(elapsed_time) as Time
FROM activity
WHERE datetime(start_date,'localtime') BETWEEN '${d1} ${t1}' AND '${d2} ${t2}'
GROUP BY 1
"
}
function activity { #complete
date-range "$@"
arbtt-stats-foreach "${filter[@]}" "${exclude[@]}" --min-percentage=0 --category=Activity
}
function details { #complete
date-range "$@"
arbtt-stats-foreach "${filter[@]}" "${exclude[@]}" --each-category
}
function dump-samples { #complete
date-range "$@"
arbtt-stats-foreach "${filter[@]}" "${exclude[@]}" --dump-samples
}
function dump-current-window { #complete
dump-samples "$@" | grep -F '(*)' | sort | uniq --count | sort -n
}
function with-uncategorized { #complete
exclude+=(--exclude=Activity:)
"$@"
}
function all-activity-categories {
arbtt-stats-foreach --min-percentage=0 --category=Activity --output-format=csv \
| grep -E -o '^Activity:[^,]+' \
| sort -u
}
function with-uncategorized-nounknown { #complete
local -a activity_categories
all-activity-categories \
| grep -v UNKNOWN \
| readarray -t activity_categories
exclude+=("${activity_categories[@]/#/--exclude=}")
"$@"
}
function with-uncategorized-nofallback { #complete
local -a activity_categories
all-activity-categories \
| grep -v 'ⁱ$' \
| readarray -t activity_categories
exclude+=("${activity_categories[@]/#/--exclude=}")
"$@"
}
make --silent -C ~/.arbtt
(( $# )) || set -- activity-chart
"$@"