Skip to content

Commit

Permalink
fix: fixed visualization when running on non-standard port
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Nov 23, 2022
1 parent 5f7256d commit c9a4052
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions visualization/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ function add(accumulator, a) {
return accumulator + a;
}

// TODO: Avoid hardcoding and pass port directly to AWClient constructor
const testing = url.port == 5666;
// TODO: Avoid testing-port assumption
const testing = url.port != 5600;

let today_start = new Date();
today_start.setHours(0, 0, 0, 0);
Expand All @@ -19,9 +19,12 @@ today_end.setHours(23, 59, 59, 999);
const start = url.searchParams.get("start") || today_start;
const end = url.searchParams.get("end") || today_end;
const hostname = url.searchParams.get("hostname");
console.log(hostname, start, end);
//console.log(hostname, start, end);

const aw = new aw_client.AWClient("aw-watcher-input", { testing: testing });
const aw = new aw_client.AWClient("aw-watcher-input", {
testing: testing,
baseURL: url.origin,
});

function load() {
const statusEl = document.getElementById("status");
Expand All @@ -30,22 +33,22 @@ function load() {
const bucketName = `aw-watcher-input_${hostname}`;

aw.getBuckets()
.then(bs => {
.then((bs) => {
if (bs[bucketName] === undefined) {
throw `no bucket called ${bucketName}`;
}
})
.then(() => {
return aw.getEvents(bucketName, { start: start, end: end });
})
.then(events => {
console.log(events);
const presses = events.map(e => e.data.presses).reduce(add, 0);
const clicks = events.map(e => e.data.clicks).reduce(add, 0);
.then((events) => {
console.debug(events);
const presses = events.map((e) => e.data.presses).reduce(add, 0);
const clicks = events.map((e) => e.data.clicks).reduce(add, 0);
pressesEl.append(presses);
clicksEl.append(clicks);
})
.catch(msg => statusEl.append(msg));
.catch((msg) => statusEl.append(msg));
}

load();

0 comments on commit c9a4052

Please sign in to comment.