book

Report

As a team, answer a subset of the questions submitted during the hackathon. But instead of using Tableau, you will need to write Javascript/Lodash code to derive your answers. Similar to before, each team member is responsible for one question. But everyone should work together to come up with a good solution. Your answer should consist of Lodash code and a brief writeup. Utilize _.map, _.filter, _.group ...etc. Do not se any for loop.

This time, the data is not already prepared for you in a nice JSON format. You will need to do it on your own, replacing the placeholder birdstrike.json with real data.

If my numbers seem too small, it's because I'm using a subset of the 1.5MB of birdstrike.json

Which airlines have the worst luck with birdstrikes in terms of damage caused?

This question was asked by (calebhsu).

var groups = _.groupBy(data, function(n) {
    return n['Aircraft: Airline/Operator'];
});
var i = 0;
var costs = _.mapValues(groups, function(d){
	var total = _.reduce(d, function(total,e){
		// some of the costs are in quotes and have commas...
		var cost = e['Cost: Total $'];
		if (_.isString(cost)){
			// remove commas
			var temp1 = cost.replace(/,/g,'');
			var temp2 = _.parseInt(temp1);
			cost = temp2;
		}
		return total+cost;
	},0);
	return total;
    
});

var sorted = _.sortBy(_.pairs(costs), function(d) {
    return d[1];
});
var desc = _(sorted).reverse().value()
return _.slice(desc,0,10);

Below are the top 10 Airlines with most total costs.

Airline Total Cost
BUSINESS 103565746
FEDEX EXPRESS 80529838
UNITED AIRLINES 74830899
US AIRWAYS 40259138
DELTA AIR LINES 20337701
MILITARY 16899033
SOUTHWEST AIRLINES 11792223
GOVERNMENT 9983201
UPS AIRLINES 8597069
PRIVATELY OWNED 7304241

What is the most common flight phase where a birdstrike occurred?

This question was asked by (KevinKGifford).

var groups = _.groupBy(data, function(n) {
    return n['When: Phase of flight'];
});

var counts = _.mapValues(groups, function(d){
    return d.length;
});
var sorted = _.sortBy(_.pairs(counts), function(d) {
    return d[1];
});

var desc = _(sorted).reverse().value()
return desc;

Flight Phase # Incidents
34738
Approach 26329
Take-off run 11914
Landing Roll 11419
Climb 10409
Descent 2032
En Route 1973
Landing 315
Taxi 215
Parked 60

What airports have the most expensive average accident?

This question was asked by (satchelspencer ).

var groups = _.groupBy(data, function(n) {
    return n['Airport: Name'];
});
var i = 0;
var costs = _.mapValues(groups, function(d){
	var avg = _.reduce(d, function(total,e){
		// some of the costs are in quotes and have commas...
		var cost = e['Cost: Total $'];
		if (_.isString(cost)){
			// remove commas and convert to int
			var temp1 = cost.replace(/,/g,'');
			cost = _.parseInt(temp1);			
		}
		return total+cost;
	},0)/_.size(d);
	return avg;
});	
var sorted = _.sortBy(_.pairs(costs), function(d) {
    return d[1];
});
var desc = _(sorted).reverse().value()
return _.slice(desc,0,10);

Below are the top 10 Airports with largest average costs.

Airline Total Cost
NICE (FRANCE) 10135286
TROY MUNICIPAL ARPT 6198875.5
ASTORIA REGIONAL 2112899.6666666665
OGDENSBURG INTL ARPT 1757025
LA ISABELA INTL ARPT 1500000
TONCONTIN INTL 1099149
BARNESVILLE-BRADFLD 976201
ANGOLA 855658
LOGAN COUNTY ARPT 852169
ROSEAU MUNI ARPT/RUDY BILLBERG FLD 760644

Which plane strikes the most birds?

This question was asked by (twagar95).

var groups = _.groupBy(data, function(n) {
    return n['Aircraft: Make/Model'];
});

var counts = _.mapValues(groups, function(d){
    return d.length;
});

var sorted = _.sortBy(_.pairs(counts), function(d) {
    return d[1];
});

var desc = _(sorted).reverse().value()

return _.slice(desc, 0,10);
The table lists the top 10 aircraft makes that had the most incidents.

Aircraft Make/Model # Incidents
UNKNOWN 24637
B-737-300 5524
A-320 4654
CL-RJ100/200 4262
B-737-700 4046
B-757-200 3945
A-319 3138
EMB-145 2067
A-300 2055
B-727-200 1771

what state had the highest number of bird strikes?

This question was asked by (drewdinger).

var groups = _.groupBy(data, 'Origin State')
var stateCount = _.mapValues(groups, function(d){
    return d.length
})

var newStateCount = _.map(stateCount, function(val,key){
	return {"state": key, "count":val}
})

_.remove(newStateCount, function(n){
 	return n.state == 'N/A'	
})

var sorted =  _.sortBy(newStateCount, "count").reverse();
return _.slice(sorted,0,10);

The table lists the top 10 States that had the most incidents.

State # Incidents
Texas 7824
California 7803
Florida 5322
New York 4986
Colorado 4214
Illinois 3987
Ohio 3537
Tennessee 3057
New Jersey 2936
Pennsylvania 2781