Created
July 31, 2015 17:41
-
-
Save bluej100/5b28cf7065b07f0aa96f to your computer and use it in GitHub Desktop.
parsing for https://www.fbi.gov/about-us/cjis/ucr/crime-in-the-u.s/2012/crime-in-the-u.s.-2012/tables/6tabledatadecpdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var headers = $('th.group0.valignmenttop'); | |
var getCity = function(header) { | |
var rate_row = $(header.parentNode).nextAll().slice(0, header.getAttribute('rowSpan')-1).last(); | |
return {name: header.textContent.trim(), violent: parseCell($(rate_row).find('.group3')), property: parseCell($(rate_row).find('.group8'))}; | |
} | |
var parseCell = function(cell) { | |
return parseFloat(cell.text().replace(/[^\d.]/g, '')); | |
} | |
var cities = headers.toArray().map(getCity); | |
cities = cities.filter(function(city) {return !!city.violent && !!city.property;}); | |
var rates = cities.map(function(city) {return city.violent;}); | |
var average = average = rates.reduce(function(a, b) {return a+b;}) / rates.length; | |
// 360.539265536723 | |
var slc = cities.find(function(city) {return city.name == 'Salt Lake City, UT M.S.A.';}) | |
// Object { name: "Salt Lake City, UT M.S.A.", violent: 327.5, property: 4328 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment