Skip to content

Commit

Permalink
Merge pull request #3 from wildstray/patch-1
Browse files Browse the repository at this point in the history
Updated dash.js with bug fix for "millis"
  • Loading branch information
jamesbarnett91 authored Aug 2, 2018
2 parents 158e5a4 + 4e9950e commit 052b34e
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions public/javascripts/dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ var dash = {

refreshRealtimeDisplay: function(realtime) {

var power = Math.round(realtime.power);
var current = realtime.current.toFixed(2);
var voltage = Math.round(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);
dataset.data.push(('energy_wh' in entry) ? (entry.energy_wh/1000) : entry.energy);
});
});

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

$("#total-day").text(dailyTotal.energy.toFixed(2));
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}, 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

$("#avg-day").text(avg.toFixed(2));

Expand All @@ -277,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);
dataset.data.push(('energy_wh' in entry) ? (entry.energy_wh/1000) : entry.energy);
});
});

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

$("#total-month").text(monthlyTotal.energy.toFixed(2));

var total = usageData.reduce(function(t, m) {return t + 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 052b34e

Please sign in to comment.