Permalink
Browse files

Added backend functionality for solar prediction, added sample data t…

…o new table
  • Loading branch information...
1 parent 232acf2 commit bd78788702e75147413f2464b7a8a3cba6bb99cc Matus committed Apr 21, 2013
Showing with 463 additions and 10 deletions.
  1. +2 −2 app.js
  2. +17 −1 controllers/solar.js
  3. +443 −6 db/rex.sql
  4. +1 −1 models/database.js
View
@@ -17,8 +17,8 @@ var app = express();
app.configure(function(){
//// Testing of output only
-// var myEnergy = new wind();
-// myEnergy.getRating(1,1,function(message){console.log("SOLAR-BB-TEST: ",message);});
+// var myEnergy = new solar();
+// myEnergy.getPrediction(1,1,function(message){console.log("SOLAR-BB-TEST: ",message);});
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
View
@@ -1,10 +1,11 @@
var solarReturnFun;
+var solarDatabaseConn;
var solar = (function() {
// constructor
function solar(){
var database = require("../models/database.js");
- this._databaseConn = new database();
+ solarDatabaseConn = new database();
var energy = require("./energy.js");
this._parent = new energy("solar");
};
@@ -46,6 +47,21 @@ var solar = (function() {
solarReturnFun(5);
}
};
+
+ solar.prototype.getPrediction = function(userLongitude, userLatitude, callback) {
+ console.log("solar: getPrediction ", userLongitude, userLatitude);
+ solarReturnFun = callback;
+ solarDatabaseConn.query("SELECT (ABS(" + solarDatabaseConn.escape(userLongitude) + " - longitude) + ABS(" + solarDatabaseConn.escape(userLatitude) + " - latitude)) AS closeness, longitude, latitude FROM `solar_prediction` ORDER BY closeness ASC LIMIT 1", this.getPredictionCallback)
+ };
+ solar.prototype.getPredictionCallback = function(data) {
+ console.log("solar: getPredictionCallback ", data);
+ if(!data[0]){
+ console.log("solar: getPredictionCallback: input data is empty")
+ solarReturnFun(-1);
+ }else{
+ solarDatabaseConn.query("SELECT year, week, unit FROM `solar_prediction` WHERE longitude=\""+data[0].longitude+"\" and latitude=\""+data[0].latitude+"\" ORDER BY year ASC, week ASC", solarReturnFun)
+ }
+ };
return solar;
})();
Oops, something went wrong.

0 comments on commit bd78788

Please sign in to comment.