texas2020 = {
const moneyball = cleanMoneyball(await d3.csv(`https://docs.google.com/spreadsheets/d/1BHRitvRqsS2pIl1Bft8-Mr6VgqYFB0I36xu1WQwsMjc/gviz/tq?tqx=out:csv&sheet=Texas Moneyball 2020`))
const FTM = cleanFTM(await d3.csv(`https://docs.google.com/spreadsheets/d/1BHRitvRqsS2pIl1Bft8-Mr6VgqYFB0I36xu1WQwsMjc/gviz/tq?tqx=out:csv&sheet=Texas FTM 2020`))
return _.chain(FTM)
.union(_.filter(FTM2018, d => d.legislature === 'SD'))
.groupBy('office')
.map((candidates, office) => {
const [,legislature] = office.split('-')
const pending = _.filter(candidates, d => d.status === 'PENDING')
const won = _.filter(candidates, d => d.status === 'WON')
let money = _.find(moneyball, d => d.office === office)
if (!money) {
const between = pending.length ? pending : won
const incumbent = _.find(between, 'incumbent')
const favored = _.find(between, d => _.includes(['D', 'R'], d.party))
money = {
office, confidence: pending.length ? 'Uncontested' : 'Closed',
incumbent: incumbent ? incumbent.party : 'Open',
favored: favored.party,
}
}
return Object.assign(money, {legislature, candidates, pending})
})
.value()
}