Merge pull request #15 from senaduka/graph_fixing
FIxed graphs / inverted the tankFull bit!
This commit is contained in:
BIN
app/app.tar.gz
Normal file
BIN
app/app.tar.gz
Normal file
Binary file not shown.
@@ -22,16 +22,13 @@ Template.state_details.rendered = function() {
|
||||
.range([0, $(self.timelineWrapper).width()])
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
function sensor_data_collection() {
|
||||
var controllerId = Session.get('controller_id');
|
||||
return SensorData.find({
|
||||
controllerId: controllerId
|
||||
}, {
|
||||
sort: {
|
||||
created_at: -1
|
||||
created_at: 1
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -60,9 +57,13 @@ Template.state_details.rendered = function() {
|
||||
*/
|
||||
function buildTemperatureGraph() {
|
||||
|
||||
var sensorReadings = sensor_data_collection();
|
||||
var unfilteredReadings = sensor_data_collection();
|
||||
|
||||
// we want to show only 11 points from all data
|
||||
var breakingPoint = Math.floor(countValues(unfilteredReadings) / 10);
|
||||
|
||||
var sensorReadings = filterDataPoints(unfilteredReadings, breakingPoint);
|
||||
|
||||
console.log("Added: ", sensorReadings.count());
|
||||
var times = sensorReadings.map(function(reading) {
|
||||
return moment(reading.created_at).format("HH:mm:ss");
|
||||
});
|
||||
@@ -70,6 +71,8 @@ function buildTemperatureGraph() {
|
||||
return reading.temperatureValue;
|
||||
});
|
||||
|
||||
var breakingPoint = Math.floor(times.length / 11);
|
||||
|
||||
return new Chartist.Line('#temperature_graph', {
|
||||
labels: times,
|
||||
series: [values]
|
||||
@@ -85,10 +88,13 @@ function buildTemperatureGraph() {
|
||||
* Function to draw the graph
|
||||
*/
|
||||
function buildHumidityGraph() {
|
||||
var unfilteredReadings = sensor_data_collection();
|
||||
// we want to show only 11 points from all data - filtering will add
|
||||
// the last one so 10 + 1 = 11
|
||||
var breakingPoint = Math.floor(countValues(unfilteredReadings) / 10);
|
||||
|
||||
var sensorReadings = sensor_data_collection();
|
||||
var sensorReadings = filterDataPoints(unfilteredReadings, breakingPoint);
|
||||
|
||||
console.log("Added: ", sensorReadings.count());
|
||||
var times = sensorReadings.map(function(reading) {
|
||||
return moment(reading.created_at).format("HH:mm:ss");
|
||||
});
|
||||
@@ -96,6 +102,8 @@ function buildHumidityGraph() {
|
||||
return reading.humidityValue;
|
||||
});
|
||||
|
||||
|
||||
|
||||
return new Chartist.Line('#humidity_graph', {
|
||||
labels: times,
|
||||
series: [values]
|
||||
@@ -106,3 +114,40 @@ function buildHumidityGraph() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function filterDataPoints(data, breakingPoint) {
|
||||
|
||||
if (breakingPoint === 0) {
|
||||
return data;
|
||||
}
|
||||
var result = [];
|
||||
var index = 0;
|
||||
var lastUnpushedRow = null;
|
||||
data.forEach(function(row) {
|
||||
if (index % breakingPoint === 0) {
|
||||
result.push(row);
|
||||
lastUnpushedRow = null;
|
||||
} else {
|
||||
lastUnpushedRow = row;
|
||||
}
|
||||
index++;
|
||||
});
|
||||
|
||||
// in order to always have the latest value
|
||||
if(lastUnpushedRow) {
|
||||
|
||||
result.push(lastUnpushedRow);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// dirty hack for the complicated way of getting
|
||||
// acual number of values
|
||||
function countValues(data) {
|
||||
var count = 0;
|
||||
data.forEach(function(row) {
|
||||
count++;
|
||||
});
|
||||
return count;
|
||||
};
|
||||
|
||||
@@ -4,29 +4,10 @@ if (Meteor.isServer) {
|
||||
SyncedCron.start();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// Global API configuration
|
||||
var Api = new Restivus({
|
||||
useDefaultAuth: true,
|
||||
prettyJson: true
|
||||
});
|
||||
|
||||
// Api.addRoute('sensorData', {
|
||||
// authRequired: false
|
||||
// }, {
|
||||
// post: function() {
|
||||
// SensorData.insert({
|
||||
// temperatureValue: parseFloat(this.bodyParams.temperatureValue),
|
||||
// humidityValue: parseFloat(this.bodyParams.humidityValue),
|
||||
// tankFull: this.bodyParams.tankFull,
|
||||
// owner: this.bodyParams.owner,
|
||||
// created_at: new Date()
|
||||
// });
|
||||
// return [];
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ import RPi.GPIO as GPIO
|
||||
# Try to read the state of GPIO_PIN_TANKFULL
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(config.GPIO_PIN_TANKFULL, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
tankFull = GPIO.input(config.GPIO_PIN_TANKFULL)
|
||||
|
||||
# tank sensor has inverse logic - 0 when it is full 1 when it is not
|
||||
# so we are inverting its value here
|
||||
tankFull = (not GPIO.input(config.GPIO_PIN_TANKFULL))
|
||||
GPIO.cleanup()
|
||||
print 'Bacva puna: {}'.format(tankFull)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user