Skip to content

Commit 810c4b3

Browse files
committed
feat: added basic custom visualization
1 parent 5ffcacd commit 810c4b3

File tree

7 files changed

+225
-1
lines changed

7 files changed

+225
-1
lines changed

README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,31 @@ Run `poetry run aw-watcher-input --help` for usage instructions.
2020
We might eventually create binary builds (like the ones bundled with ActivityWatch for aw-watcher-afk and aw-watcher-window) to make it easier to get this watcher up and running, but it's still a bit too early for that.
2121

2222

23+
## Custom visualization
24+
25+
This watcher ships with an **experimental** custom visualization which needs special configuration.
26+
27+
**NOTE:** This is a work-in-progress. Custom visualizations is an experimental feature with little to no decent documentation, so far.
28+
29+
First, you need to build it, which you can do by:
30+
31+
```sh
32+
cd visualization/
33+
npm install -g pug browserify # might need sudo
34+
npm install
35+
make build
36+
```
37+
38+
You can then configure aw-server (aw-server-rust not yet supported) to host the custom visualization by adding the following to your aw-server config file:
39+
40+
```toml
41+
[server.custom_static]
42+
aw-watcher-input = "/home/user/path/to/aw-watcher-input/visualization/dist"
43+
```
44+
2345
# Notes
2446

25-
This was massively inspired by ulogm by @karpathy, here's a screenshot for how it looks:
47+
This was massively inspired by ulogme by @karpathy, here's a screenshot of how it looks:
2648

2749
![screenshot of ulogme](https://karpathy.github.io/assets/ulogme_sv2.jpeg)
2850

visualization/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

visualization/Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
build: dist/index.html dist/bundle.js
3+
4+
dist/bundle.js: src/index.js
5+
browserify $< -o $@
6+
7+
dist/index.html: src/index.pug
8+
pug src/index.pug -o dist/

visualization/package-lock.json

+96
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

visualization/package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "aw-watcher-input-vis",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/ActivityWatch/aw-watcher-input.git"
12+
},
13+
"author": "",
14+
"license": "MPL-2.0",
15+
"bugs": {
16+
"url": "https://github.com/ActivityWatch/aw-watcher-input/issues"
17+
},
18+
"homepage": "https://github.com/ActivityWatch/aw-watcher-input#readme",
19+
"dependencies": {
20+
"aw-client": "^0.3.0"
21+
}
22+
}

visualization/src/index.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const aw_client = require("aw-client");
2+
3+
const url = new URL(window.location.href); // www.test.com/?filename=test
4+
5+
// Helper for sum-reduce
6+
function add(accumulator, a) {
7+
return accumulator + a;
8+
}
9+
10+
// TODO: Avoid hardcoding and pass port directly to AWClient constructor
11+
const testing = url.port == 5666;
12+
13+
let today_start = new Date();
14+
today_start.setHours(0, 0, 0, 0);
15+
16+
let today_end = new Date();
17+
today_end.setHours(23, 59, 59, 999);
18+
19+
const start = url.searchParams.get("start") || today_start;
20+
const stop = url.searchParams.get("stop") || today_end;
21+
const hostname = url.searchParams.get("hostname");
22+
console.log(hostname, start, stop);
23+
24+
const aw = new aw_client.AWClient("aw-watcher-input", { testing: true });
25+
26+
function load() {
27+
const statusEl = document.getElementById("status");
28+
const pressesEl = document.getElementById("presses");
29+
const clicksEl = document.getElementById("clicks");
30+
const bucketName = `aw-watcher-input_${hostname}`;
31+
32+
aw.getBuckets()
33+
.then(bs => {
34+
if (bs[bucketName] === undefined) {
35+
throw `no bucket called ${bucketName}`;
36+
}
37+
})
38+
.then(() => {
39+
return aw.getEvents(bucketName, { start: start, stop: stop });
40+
})
41+
.then(events => {
42+
console.log(events);
43+
const presses = events.map(e => e.data.presses).reduce(add, 0);
44+
const clicks = events.map(e => e.data.clicks).reduce(add, 0);
45+
pressesEl.append(presses);
46+
clicksEl.append(clicks);
47+
})
48+
.catch(msg => statusEl.append(msg));
49+
}
50+
51+
load();

visualization/src/index.pug

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
html
2+
head
3+
title aw-watcher-input visualization
4+
style
5+
| th { text-align: left; }
6+
body
7+
p#status
8+
9+
table
10+
tr
11+
th Keyboard
12+
tr
13+
td Presses
14+
td#presses
15+
tr
16+
td &nbsp;
17+
tr
18+
th Mouse
19+
tr
20+
td Clicks
21+
td#clicks
22+
23+
script(src="bundle.js")

0 commit comments

Comments
 (0)