Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

resolving conflict

  • Loading branch information...
commit e11a6a2396adb76626caa89fa20956c42e562a27 2 parents b751a27 + c1f0645
Matus authored
92 WeatherPrediction/PredictFuture.js
View
@@ -1,92 +0,0 @@
-// NASA Space Challenge
-// April 19, 2013
-// Toronto, ROM
-// Hamid Tizhoosh, Univesity of Waterloo
-
-function PredictFuture(SunData){
- // This function takes a matrix SunData as input with 10 columns and some 52
- // rows. Each column represents one year. The values are average weekly
- // irradiance values (W/m^2).
- // The function predicts teh next three years and rturns a matrix with 3
- // columns and 52 rows.
-
- // how much data?
- var numWeeks = SunData.length
- var numYears = SunData[0].length;
-
- // initialize return matrix
- var SunDataFuture = Array(numWeeks);
- for(var x = 0; x < numWeeks; x++){
- SunDataFuture[x] = Array(3);
- }
-
- // start the prediction tool
- for(var i = 1; i <=numWeeks; i++){
- // get one row of data: teh same week for many years
- //a = SunData(i,:);
- var a = SunData[i].slice(0);
- // based on that row estimate the parameters
- var returnValue = estimateFuncParam(a);
- var bigA = returnValue[0];
- var maxError = returnValue[1];
- // can we say the error is low?
- var isErrorLow = 1 - (maxError < 1? maxError : 1);
- // Predict the next year
- //SunDataFuture(i,1) = (1-isErrorLow)*mean(a) + isErrorLow*sum(A.*a(1:length(a)-1));
- SunDataFuture[i][1] = (1 - isErrorLow) * mean(a) + isErrorLow * sum(vectorMultiplication(A,a,a.length-1);
- // Predict the second year
- //b = [a(2:length(a)) SunDataFuture(i,1)];
- var b = Array(a.length);
- for(var x = 0; x < data.length - 1; x++){
- b[x] = a[x+1];
- }
- b[a.length-1] = SunDataFuture(i,1);
- //SunDataFuture(i,2) = (1-isErrorLow)*mean(b) + isErrorLow*sum(A.*b(1:length(b)-1));
- SunDataFuture(i,2) = (1 - isErrorLow) * mean(b) + isErrorLow * sum(vectorMultiplication(A,a,a.length-1);
- // Predict the third year
- //b = [a(3:length(a)) SunDataFuture(i,1) SunDataFuture(i,2)];
- for(var x = 0; x < data.length - 2; x++){
- b[x] = a[x+2];
- }
- b[a.length-2] = SunDataFuture(i,1);
- b[a.length-1] = SunDataFuture(i,2);
- //SunDataFuture(i,3) = (1-isErrorLow)*mean(b) + isErrorLow* sum(A.*b(1:length(b)-1));
- SunDataFuture(i,3) = (1 - isErrorLow) * mean(b) + isErrorLow * sum(vectorMultiplication(A,a,a.length-1);
- }
- return SunDataFuture;
-}
-
-function mean(data){
- var mean = 0;
- for(var x = 0; x < data.length; x++){
- mean += data[x] / scores[x];
- }
- return mean;
-}
-
-function sum(data){
- var sum = 0;
- for(var x = 0; x < data.length; x++){
- sum += data[x];
- }
- return sum;
-}
-
-function vectorMultiplication(vectorOne,vectorTwo,vectorSize){
- if(!vectorSize)vectorSize = vectorOne.length;
- var out = 0;
- for(var x = 0; x < vectorSize; x++){
- out += vectorOne[x] * vectorTwo[x];
- }
- return out;
-}
-
-function resizeArray(array, rows, cols){
- array.length = rows;
- for(var x = 0; x < array.length; x++){
- array[x].length = cols;
- }
- return array;
-}
-
-
6 app.js
View
@@ -3,6 +3,8 @@
* Module dependencies.
*/
+
+//Defining our routes.
var express = require('express')
, solar = require('./controllers/solar.js')
, wind = require('./controllers/wind.js')
@@ -12,7 +14,7 @@ var express = require('express')
, http = require('http')
, path = require('path');
-
+//This is a hackathon, put it in express mode we don't have time to setup.
var app = express();
app.configure(function(){
@@ -35,6 +37,8 @@ app.configure('development', function(){
app.use(express.errorHandler());
});
+
+//more routes
app.get('/', routes.index);
app.get('/users', user.list);
app.get('/ajax', routes.ajax);
9 controllers/solar.js
View
@@ -50,17 +50,24 @@ var solar = (function() {
}
};
+
+ //Get the prediction data.
solar.prototype.getPrediction = function(userLongitude, userLatitude, callback) {
console.log("solar: getPrediction ", userLongitude, userLatitude);
solarReturnFun = callback;
+ //Getting the closest dataset to what you've entered.
solarDatabaseConn.query("SELECT (ABS(" + solarDatabaseConn.escape(userLongitude) + " - solar_prediction_coordinates.longitude) + ABS(" + solarDatabaseConn.escape(userLatitude) + " - solar_prediction_coordinates.latitude)) AS closeness, solar_prediction_coordinates.longitude, solar_prediction_coordinates.latitude FROM `solar_prediction_coordinates` ORDER BY closeness ASC LIMIT 1", this.getPredictionCallback)
};
+
+ //Get some solar data (the long version)
solar.prototype.getPredictionCallback = function(data) {
console.log("solar: getPredictionCallback ", data);
if(!data[0]){
- console.log("solar: getPredictionCallback: input data is empty")
+ //Found nothing in the database!
+ console.log("solar: getPredictionCallback: input data is empty");
solarReturnFun(-1);
}else{
+ //Get the data for every week over the past 8 years.
solarDatabaseConn.query("SELECT solar_prediction_data.week, solar_prediction_data.year, solar_prediction_data.unit FROM `solar_prediction_data` JOIN `solar_prediction_coordinates` ON solar_prediction_coordinates.id = solar_prediction_data.coordinates WHERE solar_prediction_coordinates.longitude=\""+data[0].longitude+"\" and solar_prediction_coordinates.latitude=\""+data[0].latitude+"\" ORDER BY solar_prediction_data.week ASC, solar_prediction_data.year ASC", solarReturnFun)
}
};
63 public/javascripts/index.js
View
@@ -47,15 +47,20 @@ $(document).ready(function() {
//Make the bg transparent
$("body").prepend("<a class='location_home' href='#'><div class='location_name'>"+locationName+"</div><img src='images/location white.png'></a>")
- $(".location_home").addClass("location_home_animate");
$(".landingMain").append(data);
$(".background_image").css("opacity", "0");
+
+ //Now animate the stuff from the right inwards
setTimeout(function() {
+ $(".location_home").addClass("location_home_animate");
$('.overview_columns').addClass("animate_left_no3d");
+ //initializing some rankings
var highest = 0;
var best = ""
var count = 1;
+
+ //Now we fill in all of these rankings (the circles) and determine whos best
$("#wind_column").find(".rating_circle").each(function() {
if(highest < count) {
highest = count;
@@ -63,10 +68,11 @@ $(document).ready(function() {
}
if (count <= ratings.windRating) {
$(this).css("background-color", "#9FCE62");
- console.log("ffff")
}
count += 1;
})
+
+ //Solar info
count = 1;
$("#solar_column").find(".rating_circle").each(function() {
if(highest < count) {
@@ -79,6 +85,8 @@ $(document).ready(function() {
}
count += 1;
})
+
+ //Geo info
count = 1;
$("#geo_column").find(".rating_circle").each(function() {
if(highest < count) {
@@ -91,13 +99,16 @@ $(document).ready(function() {
}
count += 1;
})
+ //Yay! Show who is the bestest.
$(".winner_large").html(best)
}, 100);
+ //Returning to landing page
+
+ //Just reverse what we did to show this stuff. animate out and in.
$(".location_home").bind("click", function(e) {
e.preventDefault();
$(".background_image").css("opacity", "1");
- console.log("cliiiiicked")
$(".location_home").remove();
$(".overview_columns").removeClass("animate_left_no3d");
$(".title").removeClass("animate_left")
@@ -107,11 +118,14 @@ $(document).ready(function() {
}, 1000)
})
+ //Clicking on an information column.
$(".column").click(function(e) {
if (!($(e.target).hasClass("column"))) {
$(e.target).parent().trigger("click");
return
}
+
+
if ($(e.target).hasClass("disabled"))
return
$(e.target).append("<div class='loading_spinner'><img src='images/loading.gif'></img></div>");
@@ -125,7 +139,7 @@ $(document).ready(function() {
}
console.log(resource)
-
+ //Sliding the summary block n.
var id = e.target.id;
console.log(id)
var left = $("#" + id).position().left;
@@ -133,44 +147,58 @@ $(document).ready(function() {
$("#" + id).clone().appendTo(".overview_columns").css({"position": "absolute", "top": top + "px", "left": left + "px",
"-webkit-transition": "all 1s ease"}).addClass("slide_column")
-
+ //Disable the functionality of the other columns
$(".column").each(function() {
if (!($(this).hasClass("slide_column")))
$(this).addClass("disabled");
})
+ //Clicking the back button during the summary
$(".slide_column").click(function(e2) {
if (!($(e2.target).hasClass("column"))) {
$(e2.target).parent().trigger("click");
return
}
- $(e2.target).remove();
- $(".summaryContainer").remove();
+
+ //Remove the summary container
+ $(e2.target).css("left", "-150%");
+ $(".summaryContainer").css("left", "150%");
+
$(".column").each(function() {
$(this).removeClass("disabled");
})
+ setTimeout(function() {
+ $(e2.target).remove();
+ $(".summaryContainer").remove();
+
+ }, 1000)
+
})
+ //This is getting the data we pull in for the summary
setTimeout(function() {
$.ajax({
type: "get",
url: "/summary",
success: function(data) {
$(".overview_columns").append(data);
+
+ //Done loading!
$(".loading_spinner").remove();
setTimeout(function() {
+ //Sliding things around. Hiding the other 3 columns
$(".slide_column").css({"left": "12.5%", "margin-left": "3%", "margin-right": "3%"});
$(".summaryContainer").css("left", "29.4%");
+ //Spinning the little back button
$(".slide_column").find(".next_container").find("img").css("-webkit-transform", "rotateY(180deg)");
- //$("#predict_button").find("img").click(function() {
-
- //})
+
+
console.log(resource)
if (resource == "wind") {
$("#kwhTitle").html((ratings.windInfo[0].unit / 1000).toFixed(2) + " kwh/m&#178;");
$("#fun_fact").html("Between 2008 and 2012, wind power has provided 36.5% of all new generating capacity in the United States.")
- //$(".prof_links").html("<a href='http://www.advancedgreenbuilders.com'>Advanced Green Builders</a> <br> <br><a href='http://www.awstruepower.com/'>AWS True Power</a>")
+ //Change the fun stuff based on whats being shown
} else if (resource == "solar") {
$("#kwhTitle").html(ratings.solarInfo[0].unit + " kwh");
$("#fun_fact").html("Every hour the sun beams onto Earth more than enough energy to satisfy global energy needs for an entire year.")
@@ -180,6 +208,8 @@ $(document).ready(function() {
//$(".prof_links").html("<a href='http://www.silverstaterenewables.com/'>Silver State Renewables, Inc</a> <br> <br><a href='http://www.quantumgeothermal.com/'>Quantum Geothermal</a>")
$("#kwhTitle").html(ratings.geoInfo[0].unit + " &#186;C/m");
}
+
+ //Close the map. Make it fancy. Slide.
function closemap() {
$(".prof_map").html("");
$("#close_map").css("display", "none");
@@ -234,7 +264,7 @@ $(document).ready(function() {
})
}, 1000)
}
- });
+ }); //timeout
}, 1000);
})
@@ -244,14 +274,5 @@ $(document).ready(function() {
});
});
- //var items = (0,9)
- //items[0][0] = 1;
- //items[1][2] =2;
-
- //console.log(items[0][0]);
-
-
-
-
});
22 public/javascripts/location.js
View
@@ -50,6 +50,24 @@ $(function(){
map_canvas = $(".map_canvas");
geocoder = new google.maps.Geocoder();
+
+//Creating a new map style to get rid of the 'report an error' on google maps
+//because it was so close to the get started button.
+//YES this is okay by their TOS.
+ var MAP_STYLE = [
+ {
+ featureType: "road",
+ elementType: "all",
+ stylers: [
+ { visibility: "on" }
+ ]
+ }
+];
+ var styleOptions = {
+ name: "No Report Style"
+ };
+
+
//Set the starting position to Toronto
var latlng = new google.maps.LatLng(43.647566,-79.384847);
var mapOptions = {
@@ -61,6 +79,10 @@ $(function(){
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(map_canvas[0], mapOptions);
+ //Applying the map style
+ var mapType = new google.maps.StyledMapType(MAP_STYLE, styleOptions);
+ map.mapTypes.set("No Report Style", mapType);
+ map.setMapTypeId("No Report Style");
//Getting the enter key. How is this not default behaviour? blah.
4 public/stylesheets/overview.css
View
@@ -1,12 +1,12 @@
.location_home {
position: absolute;
- left:-20%;
+ left:-10%;
top: 20%;
height: 35%;
width: 3em;
z-index: 10;
background-color: #434343;
- -webkit-transition: all 2s ease;
+ -webkit-transition: all 1s ease;
}
.location_home_animate {
left:0;
18 routes/index.js
View
@@ -6,6 +6,8 @@
//solarjs.solar.getEverything(function(message) {
// console.log(message);
//})
+
+//Pull in all the database scripts
var wind = require("../controllers/wind.js");
var windObject = new wind();
var solar = require("../controllers/solar.js");
@@ -15,9 +17,13 @@ var geoObject = new geo();
exports.index = function(req, res){
res.render('index', { title: 'REX-Renewable Energy Explorer' });
};
+
+//ajax!
exports.ajax = function(req, res){
res.render('ajax', {});
}
+
+//The overview (3 columns)
exports.overview = function (req, res) {
res.render('overview', {});
}
@@ -32,7 +38,10 @@ exports.sendCoordinates = function (req, res){
var windInfo;
var solarInfo;
- //The callback waterfall.
+ //The callback waterfall. This is just making sure we have all the data
+ //before moving on. I assure you this is O(1) or so....
+
+ //Just runs through all the callbacks to get all of the ratings.
windObject.getRating(req.body.data[0], req.body.data[1], function(a) {
console.log(a);
windRating = a;
@@ -48,6 +57,7 @@ exports.sendCoordinates = function (req, res){
solarInfo = a;
windObject.get(req.body.data[0], req.body.data[1], function(a) {
windInfo = a;
+ //Now send it back to the callback function.
res.send({"windInfo": windInfo, "windRating": windRating, "solarInfo": solarInfo, "geoInfo": geoInfo, "solarRating": solarRating, "geoRating": geoRating});
})
})
@@ -59,14 +69,18 @@ exports.sendCoordinates = function (req, res){
}
+
+//The summary slide
exports.summary = function(req, res) {
res.render("summary", {});
}
+
+//Getting the prediction information
exports.predict = function(req, res) {
var coordinates = [req.body.data[0], req.body.data[1]];
console.log(coordinates)
solarObject.getPrediction(coordinates[0], coordinates[1], function(a) {
-
+ //back to the callback with you
res.send(a)
});
4 views/index.jade
View
@@ -10,14 +10,16 @@ block content
script(src="../javascripts/index.js")
div(class="landingMain")
div(class="title")
- |Meet Rex
+ |Meet REX
br
|Your personal renewable energy explorer for all your energy needs
+ //The map search bar thing is here
div(class="map_bar")
div(class="map_canvas")
div(class="map_search")
div(class="map_search_inner")
img(src="images/location.png")
+ //apparently inputs have breaks infront of them always. annoying.
div(class="anti_break")
input(type="text", class="inputLocation", id="location", placeholder="Where are you from?")
a(class="get_started_button", href="#")
Please sign in to comment.
Something went wrong with that request. Please try again.