NASASpaceApps/REX

resolving conflict

2 parents b751a27 + c1f0645 commit e11a6a2396adb76626caa89fa20956c42e562a27 Matus committed Apr 21, 2013
 @@ -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; -} - -
 @@ -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);
 @@ -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) } };
 @@ -47,26 +47,32 @@ \$(document).ready(function() { //Make the bg transparent \$("body").prepend("
"+locationName+"
") - \$(".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; best = "WIND POWER" } 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("
"); @@ -125,52 +139,66 @@ \$(document).ready(function() { } console.log(resource) - + //Sliding the summary block n. var id = e.target.id; console.log(id) var left = \$("#" + id).position().left; var top = \$("#" + id).position().top; \$("#" + 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²"); \$("#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("Advanced Green Builders

AWS True Power") + //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("Silver State Renewables, Inc

Quantum Geothermal") \$("#kwhTitle").html(ratings.geoInfo[0].unit + " º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]); - - - - });
 @@ -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.
 @@ -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;