Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Commented nearly everything

  • Loading branch information...
commit 9f933863a082decce28ffa85cb68413203dd487f 1 parent eeb93ee
@VicV VicV authored
View
6 app.js
@@ -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);
View
9 controllers/solar.js
@@ -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) + " - longitude) + ABS(" + solarDatabaseConn.escape(userLatitude) + " - latitude)) AS closeness, longitude, latitude FROM `solar_prediction` 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 week, year, unit FROM `solar_prediction` WHERE longitude=\""+data[0].longitude+"\" and latitude=\""+data[0].latitude+"\" ORDER BY week ASC, year ASC", solarReturnFun)
}
};
View
47 public/javascripts/index.js
@@ -47,11 +47,16 @@ $(document).ready(function() {
$(".landingMain").append(data);
$(".background_image").css("opacity", "0");
+
+ //Now animate the stuff from the right inwards
setTimeout(function() {
$('.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;
@@ -59,10 +64,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) {
@@ -75,6 +81,8 @@ $(document).ready(function() {
}
count += 1;
})
+
+ //Geo info
count = 1;
$("#geo_column").find(".rating_circle").each(function() {
if(highest < count) {
@@ -87,13 +95,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")
@@ -103,11 +114,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>");
@@ -121,7 +135,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;
@@ -129,17 +143,19 @@ $(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
}
+ //Remove the summary container
$(e2.target).remove();
$(".summaryContainer").remove();
$(".column").each(function() {
@@ -147,17 +163,23 @@ $(document).ready(function() {
})
})
+ //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 (NO LONGER VALD)
$("#predict_button").find("img").click(function() {
$.ajax({
type: 'post',
@@ -171,11 +193,13 @@ $(document).ready(function() {
}
})
})
+
+ //A bunch of things to fill in the voids. Fun facts, etc.
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.")
@@ -185,6 +209,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 + " units");
}
+
+ //Close the map. Make it fancy. Slide.
function closemap() {
$(".prof_map").html("");
$("#close_map").css("display", "none");
@@ -201,7 +227,7 @@ $(document).ready(function() {
}, 1);
}
- });
+ }); //timeout
}, 1000);
})
@@ -211,14 +237,5 @@ $(document).ready(function() {
});
});
- //var items = (0,9)
- //items[0][0] = 1;
- //items[1][2] =2;
-
- //console.log(items[0][0]);
-
-
-
-
});
View
22 public/javascripts/location.js
@@ -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.
View
18 routes/index.js
@@ -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)
});
View
4 views/index.jade
@@ -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.