From f5b9057186067a241be0aa72b1d5209672147737 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 12 Jul 2019 14:36:00 -0400 Subject: [PATCH] Show average period of beacons --- src/StationRow.vue | 11 +++++++++-- src/StatusScreen.vue | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/StationRow.vue b/src/StationRow.vue index 91b5b6f..484de28 100644 --- a/src/StationRow.vue +++ b/src/StationRow.vue @@ -4,6 +4,7 @@ @@ -12,6 +13,7 @@ Never Heard Never Heard Never Heard + Never Heard @@ -66,9 +68,14 @@ export default { messages() { Object.assign( this.status, - this.messages.reduce((acc, message) => { + this.messages.reduce((acc, message, idx, arr) => { acc.lastHeard = message.date.getTime(); - acc.delta = message.date - acc.lastHeard; + if (idx === 0) { + acc.avgDelta = 0; + } else { + let delta = message.date.getTime() - arr[idx - 1].date.getTime(); + acc.avgDelta = (acc.avgDelta * (idx - 1) + delta) / idx; + } if ("data" in message && "analog" in message.data) { acc.lastVoltage = message.data.analog[0] / 10; acc.lastTemperature = message.data.analog[1]; diff --git a/src/StatusScreen.vue b/src/StatusScreen.vue index 70b326f..ae3363c 100644 --- a/src/StatusScreen.vue +++ b/src/StatusScreen.vue @@ -5,6 +5,7 @@ Callsign Last Heard Time since Last Heard + Avg. Period Last Voltage Last Temperature