Skip to content

Commit

Permalink
Compare neighborhood home size to city average
Browse files Browse the repository at this point in the history
  • Loading branch information
WesTyler committed Jul 31, 2015
1 parent de3eaff commit dd6ee1e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 6 deletions.
54 changes: 54 additions & 0 deletions client/app/components/graphContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<small>{point.key}</small><table>',
pointFormat: '<tr><td style="color: {series.color}">{series.name}: </td>' +
'<td style="text-align: right"><b>{point.y}</b></td></tr>',
footerFormat: '</table>',
},
credits: {
enabled: false
}
});
});
};


};

Expand All @@ -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}),
]);
};

Expand Down
8 changes: 8 additions & 0 deletions client/app/components/searchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions client/app/models/Location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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})
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion client/public/sass/graphContainer.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.costCompare, .commuteTime {
.costCompare, .commuteTime, .sizeCompare {
margin-top: 30px;
}

Expand Down
2 changes: 1 addition & 1 deletion client/public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ h3, h4 {

/* END general styling */

.costCompare, .commuteTime {
.costCompare, .commuteTime, .sizeCompare {
margin-top: 30px; }

.gaugeContainer {
Expand Down
3 changes: 1 addition & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ app.post('/', function (req, res){
}
// Attach Zillow data to response
httpResponseBody.zillowData = houseData
console.log(houseData)
})
} else {
httpResponseBody.zillowData = {}
Expand All @@ -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);
});
Expand Down
11 changes: 9 additions & 2 deletions server/lib/calculateLivability.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit dd6ee1e

Please sign in to comment.