Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
557 additions
and
171 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This is a visualization of Congress’ funding on gun issues. The data is | ||
from the [Center for Responsive Politics](https://www.opensecrets.org). | ||
The code is [open source](https://github.com/lachlanjc/gunfunded). | ||
[Lachlan Campbell](https://lachlanjc.me) made it. |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const neatCsv = require('neat-csv') | ||
const writeJsonFile = require('write-json-file') | ||
const _ = require('lodash') | ||
const records = require('./records.json') | ||
const groups = require('./groups.json') | ||
const fs = require('fs') | ||
const rawLobbying = fs.readFileSync('./data/raw/lobbying.csv') | ||
|
||
const getStats = () => ({ | ||
gunRightsTotal: _.sum(_.map(records, 'gunRightsTotal')), | ||
gunControlTotal: _.sum(_.map(records, 'gunControlTotal')), | ||
unRightsCount: _.filter(records, ['gunRightsTotal', 0]).length | ||
}) | ||
|
||
const getProfiles = () => ({ | ||
sample: _.find(records, ['id', 'VA-sen-1']), | ||
highestRights: _.last(_.sortBy(records, 'net')), | ||
highestRightsDem: _.first(_.sortBy(_.filter(records, ['party', 'Democrat'], 'net'))), | ||
highestRightsDirect: _.last(_.sortBy(records, 'gunRightsDirect')), | ||
highestControl: _.last(_.orderBy(records, 'gunControlTotal')) | ||
}) | ||
const getLobbying = () => neatCsv(rawLobbying) | ||
|
||
const getData = () => | ||
Promise.all([getLobbying(), getProfiles(), getStats()]) | ||
.catch(() => { | ||
console.error('🚨 ERROR') | ||
}) | ||
.then(([lobbying, profiles, stats]) => ({stats, profiles, lobbying})) | ||
const save = data => { | ||
writeJsonFile('./data/about.json', data).then(() => { | ||
console.log(`✅ Saved`) | ||
}) | ||
} | ||
getData().then(data => save(data)) |
Oops, something went wrong.