Created
July 21, 2014 04:58
-
-
Save paulserraino/de595481e69b62e266f1 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Violations</title> | |
<style> | |
body { | |
padding: 20px; | |
font-family: "helvetica neue", helvetica; | |
} | |
thead { | |
font-weight: bold; | |
} | |
</style> | |
</head> | |
<body> | |
<table> | |
<thead> | |
<tr> | |
<td>Violation Type</td> | |
<td>Violation Count</td> | |
</tr> | |
</thead> | |
<tbody id="results"> | |
</tbody> | |
</table> | |
<script id="results-tmpl" type="text/x-template"> | |
<% results.forEach(function (res) { %> | |
<tr> | |
<td><%= res.violation %></td> | |
<td><%= res.count %></td> | |
<tr> | |
<% }); %> | |
</script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script> | |
<script> | |
$.ajax({ | |
type: "GET", | |
url: "violations.json" | |
}).done(function (data) { | |
console.log(data); | |
var allViolations = _.pluck(data, "violation_type"); | |
var violations = _.uniq(allViolations); | |
var results = []; | |
_.each(violations, function (v) { | |
console.log(v); | |
results.push({ | |
violation: v, | |
count: _.filter(data, function (vc) { | |
return vc.violation_type === v; | |
}).length | |
}); | |
}); | |
var tmpl = _.template($("#results-tmpl").html()); | |
$("#results").html(tmpl({results: results})); | |
}) | |
</script> | |
</body> | |
</html> |
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
{ | |
"dependencies": { | |
"request": "~2.37.0", | |
"csvjson": "~1.0.2" | |
} | |
} |
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 fs = require('fs') | |
var request = require('request') | |
var csvjson = require('csvjson') | |
var results = {}, | |
csvobj; | |
request('http://forever.codeforamerica.org/fellowship-2015-tech-interview/Violations-2012.csv', | |
function (err, resp, data) { | |
csvobj = csvjson.toObject(data).output | |
csvobj = JSON.stringify(csvobj); | |
fs.writeFile('violations.json', csvobj, function (err) { | |
if (err) throw err; | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment