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.
var clean = _.reject(data, function(n){
return _.includes(n['Wildlife: Species'], 'Unknown')
})
var groups = _.groupBy(clean, function(d){
return d['Wildlife: Species']
})
var birds = _.pairs(_.mapValues(groups, function(value){
return value.length
}))
var top = _.sortBy(birds, function(n) {
return n[1]
}).reverse()
return _.slice(top, [start=0], [end=5])
[ [ "Gulls", 251 ], [ "Mourning dove", 163 ], [ "European starling", 121 ], [ "Sparrows", 98 ], [ "Rock pigeon", 95 ] ]
var data_poistive=_.filter(data,function(r){return parseInt(r['Feet above ground'])> 0})
var grps =_.groupBy(data_poistive,function(d){return d['Feet above ground']})
var result=_.mapValues(grps,function(t){return t.length})
var sorted = _.sortBy(_.pairs(result), function(d) {
return parseInt(d[0].replace(',', ''));
});
var desc = _(sorted).value()
return desc
//return result
Height | Number of birds hit |
2 | 6 |
3 | 7 |
4 | 1 |
5 | 23 |
7 | 2 |
9 | 3 |
10 | 82 |
12 | 1 |
15 | 10 |
20 | 62 |
25 | 10 |
30 | 20 |
34 | 1 |
35 | 2 |
38 | 1 |
40 | 12 |
50 | 134 |
60 | 2 |
70 | 2 |
75 | 12 |
80 | 2 |
85 | 1 |
90 | 3 |
100 | 150 |
105 | 1 |
110 | 1 |
120 | 1 |
125 | 2 |
140 | 1 |
150 | 24 |
180 | 1 |
200 | 108 |
250 | 7 |
300 | 81 |
350 | 6 |
360 | 1 |
400 | 52 |
450 | 1 |
500 | 100 |
550 | 1 |
600 | 21 |
650 | 1 |
700 | 19 |
750 | 3 |
760 | 1 |
775 | 1 |
800 | 50 |
850 | 1 |
900 | 13 |
930 | 1 |
950 | 1 |
1,000 | 88 |
1,100 | 8 |
1,150 | 1 |
1,200 | 26 |
1,300 | 7 |
1,400 | 9 |
1,500 | 65 |
1,600 | 8 |
1,700 | 8 |
1,800 | 15 |
1,900 | 11 |
2,000 | 70 |
2,081 | 1 |
2,100 | 5 |
2,200 | 4 |
2,300 | 7 |
2,400 | 3 |
2,500 | 31 |
2,600 | 4 |
2,700 | 2 |
2,800 | 3 |
2,900 | 1 |
2,970 | 1 |
3,000 | 56 |
3,100 | 1 |
3,200 | 5 |
3,300 | 4 |
3,400 | 2 |
3,500 | 13 |
3,700 | 1 |
4,000 | 27 |
4,100 | 1 |
4,200 | 1 |
4,300 | 1 |
4,700 | 1 |
5,000 | 37 |
5,100 | 2 |
5,500 | 4 |
5,600 | 1 |
5,800 | 1 |
6,000 | 11 |
6,200 | 1 |
6,300 | 1 |
6,500 | 3 |
7,000 | 20 |
7,200 | 1 |
7,500 | 1 |
7,700 | 1 |
8,000 | 12 |
8,300 | 2 |
8,500 | 1 |
8,900 | 1 |
9,000 | 3 |
9,500 | 1 |
9,650 | 1 |
10,000 | 4 |
10,500 | 2 |
10,800 | 1 |
11,000 | 6 |
12,000 | 6 |
12,300 | 1 |
12,500 | 1 |
12,600 | 1 |
13,000 | 1 |
15,000 | 1 |
16,000 | 1 |
17,000 | 1 |
21,000 | 1 |
return _.chain(data).groupBy('Origin State').mapValues(function(state){
return _.reduce(state, function(sum, incident){
return sum+parseInt(incident['Cost: Total $'].toString().replace(',', ''));
}, 0);
}).pairs().sortByOrder('1', 1).object().value();
[object Object]
var groups = _.groupBy(data, function(n){
return n['Airport: Name']
})
var valuedGroups = _.values(groups)
var result = _.chain(valuedGroups)
.map(function(arr){
return [arr[0]["Airport: Name"], arr.length]
})
.reduce(function(n, p){
if ((n[1] > p[1]) && (n[0] != "UNKNOWN")) { return n; } else {return p; }
}).value()
return result
DENVER INTL AIRPORT,156
var groups = _.groupBy(data, function(n){
return n['Aircraft: Airline/Operator']
})
var pairs = _.pairs(_.mapValues(groups, function(item){
var costs = _.map(item, function(value){
return parseInt(value['Cost: Total $'].toString().replace(',', '')) })
return _.sum(costs)
}))
var top = _.sortBy(pairs, function(n){
return n[1]
}).reverse()
top = _.slice(top, [start =0], [end=10])
return top
BUSINESS,3528807,MILITARY,1748247,NORTHWEST AIRLINES,840942,AMERICAN EAGLE AIRLINES,801820,FEDEX EXPRESS,711967,SOUTHWEST AIRLINES,669519,KLM ROYAL DUTCH AIRLINES,534547,AMERICAN AIRLINES,511087,EXECUTIVE JET AVIATION,492513,CONTINENTAL AIRLINES,490932