From dd6ee1e8dd0f58ca73ccbd304e4f85702e609676 Mon Sep 17 00:00:00 2001 From: WesTyler Date: Fri, 31 Jul 2015 13:33:05 -0500 Subject: [PATCH] Compare neighborhood home size to city average --- client/app/components/graphContainer.js | 54 +++++++++++++++++++++++++ client/app/components/searchBox.js | 8 ++++ client/app/models/Location.js | 7 ++++ client/public/sass/graphContainer.scss | 2 +- client/public/style.css | 2 +- server/index.js | 3 +- server/lib/calculateLivability.js | 11 ++++- 7 files changed, 81 insertions(+), 6 deletions(-) diff --git a/client/app/components/graphContainer.js b/client/app/components/graphContainer.js index c2b7462..96c0459 100644 --- a/client/app/components/graphContainer.js +++ b/client/app/components/graphContainer.js @@ -273,6 +273,59 @@ exports.controller = function(options) { }); }; + ctrl.initSizeCompare = function (element, isInit, context) { + + //Initialize number of restaurants chart + $(function () { + var userData = Location.zillowSizeNeighborhood() + var averageData = Location.zillowSizeCity() + var colors; + if (userData > averageData*1.2) { + colors = ['#55BF3B', '#434348'] + } else if (userData < averageData*0.8) { + colors = ['#DF5353', '#434348'] + } else { + colors = ['#DDDF0D', '#434348'] + } + $('.sizeCompare').highcharts({ + colors: colors, + chart: { + type: 'column', + spacing: 50 + }, + title: { + text: 'Median Neighborhood Home Size' + }, + xAxis: { + categories: [''] + }, + yAxis: { + title: { + text: 'Home Size (sq ft)' + } + }, + series: [{ + name: 'Your Search', + data: [Location.zillowSizeNeighborhood()] + }, { + name: 'City of Austin (average)', + // data: [Location.search().restaurants] + data: [Location.zillowSizeCity()] + }], + tooltip: { + useHTML: true, + headerFormat: '{point.key}', + pointFormat: '' + + '', + footerFormat: '
{series.name}: {point.y}
', + }, + credits: { + enabled: false + } + }); + }); + }; + }; @@ -283,6 +336,7 @@ exports.view = function(ctrl, options) { m('.col-sm-4 .restaurantNumber', {config: ctrl.initRestNumber}), m('.col-sm-4 .commuteTime', {config: ctrl.initCommuteTime}), m('.col-sm-4 .costCompare', {config: ctrl.initCostCompare}), + m('.col-sm-4 .sizeCompare', {config: ctrl.initSizeCompare}), ]); }; diff --git a/client/app/components/searchBox.js b/client/app/components/searchBox.js index 455dae8..496d2ce 100644 --- a/client/app/components/searchBox.js +++ b/client/app/components/searchBox.js @@ -85,6 +85,14 @@ exports.view = function (ctrl, options) { )] )] )], + [m('.col-sm-6', + [m('h4', 'Home Size: ' + Location.sizeWeight())], + [m('.slider', + [m('input[type="range"]' + ,{min: 0, max: 100, step: 1, value: Location.sizeWeight(), onchange: m.withAttr('value', Location.sizeWeight)} + )] + )] + )], [m('input.addressInput.addressInput-submit[type="submit"][value="Try your luck"]')] //input form ), //form-group ] //form diff --git a/client/app/models/Location.js b/client/app/models/Location.js index 84faf95..a8e0e48 100644 --- a/client/app/models/Location.js +++ b/client/app/models/Location.js @@ -45,8 +45,11 @@ var Locations = module.exports = { workAddress: m.prop(''), commuteTime: m.prop(''), costWeight: m.prop(''), + sizeWeight: m.prop(''), zillowIncomeNeighborhood: m.prop(0), zillowIncomeCity: m.prop(0), + zillowSizeNeighborhood: m.prop(0), + zillowSizeCity: m.prop(0), postToFetchRestaurantData: function(address, workAddress, callback) { Locations.address(address); @@ -73,6 +76,7 @@ var Locations = module.exports = { "restaurants": Locations.restWeight() || 50, "commute" : workAddress !== '' ? Locations.commuteWeight() || 50 : 0, "affordability": Locations.costWeight() || 50, + "size": Locations.sizeWeight() || 0, // Default to zero if user does not specify } }; return m.request({method: "POST", url: "", 'Content-Type': 'application/json', data: locationData}) @@ -82,6 +86,9 @@ var Locations = module.exports = { Locations.search(data); Locations.zillowIncomeNeighborhood(data.zillow.neighborhood.medianIncomeNeighborhood); Locations.zillowIncomeCity(data.zillow.neighborhood.medianIncomeCity); + Locations.zillowSizeNeighborhood(data.zillow.neighborhood.houseSizeNeighborhood); + Locations.zillowSizeCity(data.zillow.neighborhood.houseSizeCity); + } Locations.saveSearch(Locations.address(), res.livibility); return callback(data); diff --git a/client/public/sass/graphContainer.scss b/client/public/sass/graphContainer.scss index 9a15218..218767b 100644 --- a/client/public/sass/graphContainer.scss +++ b/client/public/sass/graphContainer.scss @@ -1,4 +1,4 @@ -.costCompare, .commuteTime { +.costCompare, .commuteTime, .sizeCompare { margin-top: 30px; } diff --git a/client/public/style.css b/client/public/style.css index 632703f..8e9dcf5 100644 --- a/client/public/style.css +++ b/client/public/style.css @@ -68,7 +68,7 @@ h3, h4 { /* END general styling */ -.costCompare, .commuteTime { +.costCompare, .commuteTime, .sizeCompare { margin-top: 30px; } .gaugeContainer { diff --git a/server/index.js b/server/index.js index 6ba676f..639d883 100644 --- a/server/index.js +++ b/server/index.js @@ -178,7 +178,6 @@ app.post('/', function (req, res){ } // Attach Zillow data to response httpResponseBody.zillowData = houseData - console.log(houseData) }) } else { httpResponseBody.zillowData = {} @@ -187,7 +186,7 @@ app.post('/', function (req, res){ }) // Send response back to client .then(function (httpResponseBody){ - var weights = req.body.weights || {restaurants: 50, crimes: 50, affordability: 50}; + var weights = req.body.weights || {restaurants: 50, crimes: 50, affordability: 50, size: 0}; calculateLivability(weights, httpResponseBody, req.body.radius); res.json(httpResponseBody); }); diff --git a/server/lib/calculateLivability.js b/server/lib/calculateLivability.js index b8308a5..c255aa1 100644 --- a/server/lib/calculateLivability.js +++ b/server/lib/calculateLivability.js @@ -48,9 +48,15 @@ var linEqHandler = function(data, tag){ } case 'affordability': return { - pnt1: {x: data.zillowData.neighborhood.medianIncomeCity/1000, y: 75}, - pnt2: {x: (data.zillowData.neighborhood.medianIncomeCity*0.5)/1000, y: 100}, // For every change of 10% in income vs city average, the affordability livability portion changes by 2.5 + pnt1: {x: data.zillowData.neighborhood.medianIncomeCity/1000, y: 80}, + pnt2: {x: (data.zillowData.neighborhood.medianIncomeCity*0.5)/1000, y: 100}, input: data.zillowData.neighborhood.medianIncomeNeighborhood/1000 + } + case 'size': + return { + pnt1: {x: data.zillowData.neighborhood.houseSizeCity, y: 80}, + pnt2: {x: (data.zillowData.neighborhood.houseSizeCity*0.7), y: 50}, + input: data.zillowData.neighborhood.houseSizeNeighborhood }; } } @@ -80,6 +86,7 @@ var linEq = function(handler){ //The purpose is to provide linEq w/ the correct handler, and to keep the score in the range 0-100 var calculateScore = function(handler, weight){ var score = linEq(handler); + console.log('score',score, 'weight', weight) return score < 0 ? 0 : score > 100 ? weight * 100 : score * weight }