Skip to content

Commit

Permalink
Update dash.js
Browse files Browse the repository at this point in the history
  • Loading branch information
wildstray authored Aug 2, 2018
1 parent c1ea6a6 commit 4e9950e
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions public/javascripts/dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ var dash = {
realtimeTrendChart: null,
realtimeTrendLastSample: 0,

dailyUsageChart: null,
monthlyUsageChart: null,
init: function(deviceId) {
this.deviceId = deviceId;
if (this.deviceId) {
$('.' + deviceId).addClass('active');
}
this.initRealtimeGauge();
this.initRealtimeTrendChart();
this.initDailyUsageChart();
this.initMonthlyUsageChart();
this.initWsConnection();
},
dailyUsageChart: null,
monthlyUsageChart: null,

init: function(deviceId) {
this.deviceId = deviceId;

if (this.deviceId) {
$('.' + deviceId).addClass('active');
}

this.initRealtimeGauge();
this.initRealtimeTrendChart();
this.initDailyUsageChart();
this.initMonthlyUsageChart();

this.initWsConnection();
},

initWsConnection: function() {
var wsUri = 'ws://' + window.location.host + '/ws'
Expand Down Expand Up @@ -212,9 +212,9 @@ var dash = {

refreshRealtimeDisplay: function(realtime) {

var power = Math.round((realtime.power_mw) ? (realtime.power_mw/1000) : realtime.power);
var current = ((realtime.current_ma) ? (realtime.current_ma/1000) : realtime.current).toFixed(2);
var voltage = Math.round((realtime.voltage_mv) ? (realtime.voltage_mv/1000) : realtime.voltage);
var power = Math.round(('power_mw' in realtime) ? (realtime.power_mw/1000) : realtime.power);
var current = (('current_ma' in realtime) ? (realtime.current_ma/1000) : realtime.current).toFixed(2);
var voltage = Math.round(('voltage_mv' in realtime) ? (realtime.voltage_mv/1000) : realtime.voltage);

this.realtimeGauge.set(power);
// might switch to Vue.js if this gets tedious
Expand All @@ -240,7 +240,7 @@ var dash = {

dash.dailyUsageChart.data.labels.push(day.format('MMM D'));
dash.dailyUsageChart.data.datasets.forEach(function(dataset) {
dataset.data.push((entry.energy_wh) ? (entry.energy_wh/1000) : entry.energy);
dataset.data.push(('energy_wh' in entry) ? (entry.energy_wh/1000) : entry.energy);
});
});

Expand All @@ -254,10 +254,10 @@ var dash = {
return d.day === moment().date() && d.month === (moment().month()+1) && d.year === moment().year()
});

var energy = (dailyTotal.energy_wh) ? (dailyTotal.energy_wh/1000) : dailyTotal.energy
var energy = ('energy_wh' in dailyTotal) ? (dailyTotal.energy_wh/1000) : dailyTotal.energy
$("#total-day").text(energy.toFixed(2));

var total = usageData.reduce(function(t, d) {return t + ((d.energy_wh) ? (d.energy_wh/1000) : d.energy)}, 0);
var total = usageData.reduce(function(t, d) {return t + (('energy_wh' in d) ? (d.energy_wh/1000) : d.energy)}, 0);
var avg = total/usageData.length;
console

Expand All @@ -279,7 +279,7 @@ var dash = {

dash.monthlyUsageChart.data.labels.push(month.format('MMM'));
dash.monthlyUsageChart.data.datasets.forEach(function(dataset) {
dataset.data.push((entry.energy_wh) ? (entry.energy_wh/1000) : entry.energy);
dataset.data.push(('energy_wh' in entry) ? (entry.energy_wh/1000) : entry.energy);
});
});

Expand All @@ -292,10 +292,10 @@ var dash = {
var monthlyTotal = usageData.find(function(m) {
return m.month === (moment().month()+1) && m.year === moment().year()
});
var energy = (monthlyTotal.energy_wh) ? (monthlyTotal.energy_wh/1000) : monthlyTotal.energy
var energy = ('energy_wh' in monthlyTotal) ? (monthlyTotal.energy_wh/1000) : monthlyTotal.energy
$("#total-month").text(energy.toFixed(2));

var total = usageData.reduce(function(t, m) {return t + ((m.energy_wh) ? (m.energy_wh/1000) : m.energy)}, 0);
var total = usageData.reduce(function(t, m) {return t + (('energy_wh' in m) ? (m.energy_wh/1000) : m.energy)}, 0);
var avg = total/usageData.length;

$("#avg-month").text(avg.toFixed(2));
Expand Down

0 comments on commit 4e9950e

Please sign in to comment.