APIs

package
v0.0.0-...-58fb9df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Pre-computed in historical_optimize.go
	COOK_WEIGHT     = 302.0708670497893
	COOK_PVI_WEIGHT = 0.3588032283134363

	CookConfidence = [][2]float64{{0.67, 0.33}, {0.56, 0.44}, {0.535, 0.465}, {0.5, 0.5}, {0.5, 0.5}, {0.465, 0.535}, {0.44, 0.56}, {0.33, 0.67}} // Based on 538's analysis of expert forecast margins
)
View Source
var (
	FEC_API_KEY = "DEMO_KEY" // Allows 40 API calls per time period, we only need 27, but you can set this if you like
)
View Source
var (
	USStateAbbrev = map[string]string{
		"Alabama":        "AL",
		"Alaska":         "AK",
		"Arizona":        "AZ",
		"Arkansas":       "AR",
		"California":     "CA",
		"Colorado":       "CO",
		"Connecticut":    "CT",
		"Delaware":       "DE",
		"Florida":        "FL",
		"Georgia":        "GA",
		"Hawaii":         "HI",
		"Idaho":          "ID",
		"Illinois":       "IL",
		"Indiana":        "IN",
		"Iowa":           "IA",
		"Kansas":         "KS",
		"Kentucky":       "KY",
		"Louisiana":      "LA",
		"Maine":          "ME",
		"Maryland":       "MD",
		"Massachusetts":  "MA",
		"Michigan":       "MI",
		"Minnesota":      "MN",
		"Mississippi":    "MS",
		"Missouri":       "MO",
		"Montana":        "MT",
		"Nebraska":       "NE",
		"Nevada":         "NV",
		"New Hampshire":  "NH",
		"New Jersey":     "NJ",
		"New Mexico":     "NM",
		"New York":       "NY",
		"North Carolina": "NC",
		"North Dakota":   "ND",
		"Ohio":           "OH",
		"Oklahoma":       "OK",
		"Oregon":         "OR",
		"Pennsylvania":   "PA",
		"Rhode Island":   "RI",
		"South Carolina": "SC",
		"South Dakota":   "SD",
		"Tennessee":      "TN",
		"Texas":          "TX",
		"Utah":           "UT",
		"Vermont":        "VT",
		"Virginia":       "VA",
		"Washington":     "WA",
		"West Virginia":  "WV",
		"Wisconsin":      "WI",
		"Wyoming":        "WY",
	}
)

Functions

func Load538GenericBallot

func Load538GenericBallot() float64

func Load538GovForecast

func Load538GovForecast() (forecast_538 map[string]float64, parties_538 map[string]map[string]string)

func Load538HouseElasticities

func Load538HouseElasticities() map[string]float64

func Load538HouseForecast

func Load538HouseForecast() (forecast_538 map[string]float64, parties_538 map[string]map[string]string, congressional_ballot float64)

func Load538Polls

func Load538Polls() (polls_538_senate, polls_538_house, polls_538_gov map[string][]Poll)

func Load538SenateElasticities

func Load538SenateElasticities() map[string]float64

func Load538SenateForecast

func Load538SenateForecast() (forecast_538 map[string]float64, parties_538 map[string]map[string]string)

func Load2016SenatePolls

func Load2016SenatePolls() map[string][]Poll

func LoadCNNGovResults

func LoadCNNGovResults(year string) map[string][2]float64

func LoadCNNHouseForecast

func LoadCNNHouseForecast() map[string]float64

func LoadCNNHouseResults

func LoadCNNHouseResults(year string) map[string][2]float64

func LoadCNNSenateForecast

func LoadCNNSenateForecast() map[string]float64

func LoadCNNSenateResults

func LoadCNNSenateResults(year string) map[string][2]float64

func LoadCache

func LoadCache(url, file string, maxAge time.Duration, parser func(r io.Reader) interface{}) interface{}

func LoadCookGovRatingsHtml

func LoadCookGovRatingsHtml(id uint64) (ratings map[string][2]float64, incumbents map[string]string, pvis map[string]float64)

func LoadCookHouseRatingsHtml

func LoadCookHouseRatingsHtml(id uint64) (ratings map[string][2]float64, incumbents map[string]string, pvis map[string]float64)

func LoadCookRatings

func LoadCookRatings(file string) (ratings []map[string]string)

func LoadCookSenateRatingsHtml

func LoadCookSenateRatingsHtml(id uint64) (ratings map[string][2]float64, incumbents map[string]string, pvis map[string]float64)

func LoadFECRaces

func LoadFECRaces(office string, year int) map[string]float64

func LoadFECRacesOld

func LoadFECRacesOld(office string, year int) map[string]float64

Apparently this is missing about 30% of candidates for some fucking reason. Good job, FEC. Instead, use the bulk zip file above.

func LoadNYTHouseResults

func LoadNYTHouseResults(year string) map[string][2]float64

func LoadNYTLivePolls

func LoadNYTLivePolls() (housePolls, senatePolls map[string][]Poll)

Load ongoing polls from https://www.nytimes.com/interactive/2018/upshot/elections-polls.html Partial data is better than no data

func LoadNYTSenateResults

func LoadNYTSenateResults(year string) map[string][2]float64

2008, 2010

func LoadOpenSecretsRace

func LoadOpenSecretsRace(mode, st string) map[string]float64

Not used. Using FEC instead

Types

type CNNForecast

type CNNForecast struct {
	Topline        CNNForecastTopline       `json:"topline"`
	Competitive    []CNNForecastRaceDetails `json:"competitive"`
	Swing          []CNNForecastRaceDetails `json:"swing"`
	Districts      []CNNForecastDistrict    `json:"districts"`
	Seats          []CNNForecastSeat        `json:"seats"`
	LastUpdatedEDT string                   `json:"lastUpdatedEDT"`
}

type CNNForecastDistrict

type CNNForecastDistrict struct {
	ID         string  `json:"id"`
	State      string  `json:"state"`
	District   string  `json:"district"`
	Prediction float64 `json:"prediction"`
	LowMargin  float64 `json:"lowMargin"`
	HiMargin   float64 `json:"hiMargin"`
	Rcand      string  `json:"rcand,omitempty"`
	Rlast      string  `json:"rlast,omitempty"`
	Dcand      string  `json:"dcand,omitempty"`
	Dlast      string  `json:"dlast,omitempty"`
}

type CNNForecastHistory

type CNNForecastHistory struct {
	Timestamp  string  `json:"timestamp"`
	Party      string  `json:"party"`
	MarginHigh float64 `json:"marginHigh"`
	MarginWin  float64 `json:"marginWin"`
	MarginLow  float64 `json:"marginLow"`
}

type CNNForecastPrediction

type CNNForecastPrediction struct {
	Bin int     `json:"bin"`
	Pct float64 `json:"pct"`
}

type CNNForecastRaceDetails

type CNNForecastRaceDetails struct {
	ID                              string                  `json:"id"`
	State                           string                  `json:"state"`
	District                        string                  `json:"district"`
	Prediction                      float64                 `json:"prediction"`
	LowMargin                       float64                 `json:"lowMargin"`
	HiMargin                        float64                 `json:"hiMargin"`
	Predictions                     []CNNForecastPrediction `json:"predictions"`
	LastHouseResultDemocraticMargin float64                 `json:"last_house_result_democratic_margin"`
	UnopposedPrior                  bool                    `json:"unopposedPrior"`
	ExcludedCurrent                 bool                    `json:"excludedCurrent"`
}

type CNNForecastSeat

type CNNForecastSeat struct {
	Seat        string                  `json:"seat"`
	LowMargin   float64                 `json:"lowMargin"`
	Prediction  float64                 `json:"prediction"`
	HiMargin    float64                 `json:"hiMargin"`
	History     []CNNForecastHistory    `json:"history"`
	Predictions []CNNForecastPrediction `json:"predictions"`
	Dcand       string                  `json:"dcand,omitempty"`
	Dlast       string                  `json:"dlast,omitempty"`
	Rcand       string                  `json:"rcand,omitempty"`
	Rlast       string                  `json:"rlast,omitempty"`
	Dcand2      string                  `json:"dcand2"`
	Icand       string                  `json:"icand,omitempty"`
	Ilast       string                  `json:"ilast,omitempty"`
}

type CNNForecastTopline

type CNNForecastTopline struct {
	Timestamp   string                      `json:"timestamp"`
	Party       string                      `json:"party"`
	MarginHigh  float64                     `json:"marginHigh"`
	MarginWin   float64                     `json:"marginWin"`
	MarginLow   float64                     `json:"marginLow"`
	DaysOut     int                         `json:"daysOut"`
	Race        string                      `json:"race"`
	Predictions []CNNForecastPrediction     `json:"predictions"`
	History     []CNNForecastToplineHistory `json:"history"`
}

type CNNForecastToplineHistory

type CNNForecastToplineHistory struct {
	CNNForecastHistory
	DaysOut int `json:"daysOut"`
}

type CandidateForecast538

type CandidateForecast538 struct {
	Candidate string            `json:"candidate"`
	Party     string            `json:"party"`
	Date      string            `json:"date"`
	Models    ModelForecasts538 `json:"models"`
}

type DistrictForecast538

type DistrictForecast538 struct {
	State    string                 `json:"state"`
	District string                 `json:"district"`
	Forecast []CandidateForecast538 `json:"forecast"`
}

type Forecast538

type Forecast538 struct {
	//CongressPartySplits []CongressPartySplit538 `json:"congress_party_splits"`
	//SeatChances         []SeatChance538         `json:"seat_chances"`
	//NationalTrends      []NationalTrend538      `json:"nationalTrends"`
	DistrictForecasts []DistrictForecast538 `json:"districtForecasts"` // House
	SeatForecasts     []SeatForecast538     `json:"seatForecasts"`     // Senate
}

type GenericBallot538

type GenericBallot538 struct {
	Date     string             `json:"date"`
	Subgroup string             `json:"subgroup"`
	Revised  GenericEstimate538 `json:"revised"`
	Original GenericEstimate538 `json"original"`
}

type GenericEstimate538

type GenericEstimate538 struct {
	DemEstimate float64 `json:"dem_estimate"`
	DemHi       float64 `json:"dem_hi"`
	DemLo       float64 `json:"dem_lo"`
	RepEstimate float64 `json:"rep_estimate"`
	RepHi       float64 `json:"rep_hi"`
	RepLo       float64 `json:"rep_lo"`
}

type ModelForecast538

type ModelForecast538 struct {
	WinProb     float64 `json:"winprob"`
	VoteShare   float64 `json:"voteshare"`
	VoteShareHi float64 `json:"voteshare_hi"`
	VoteShareLo float64 `json:"voteshare_lo"`
	Margin      float64 `json:"margin"` // only for US
}

type ModelForecasts538

type ModelForecasts538 struct {
	Lite    ModelForecast538 `json:"lite"`
	Classic ModelForecast538 `json:"classic"`
	Deluxe  ModelForecast538 `json:"deluxe"`
}

type SeatForecast538

type SeatForecast538 struct {
	State    string                 `json:"state"`
	Class    int                    `json:"class"`
	Forecast []CandidateForecast538 `json:"forecast"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL