filter recent polls
This commit is contained in:
parent
ca7401a6ed
commit
6dddb42899
53
main.go
53
main.go
|
@ -187,15 +187,21 @@ func readStates() ([]State, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func sampleFromState(state State) VotesForEachParty {
|
func sampleFromState(state State) VotesForEachParty {
|
||||||
|
fmt.Printf("\n\nState: %s", state.Name)
|
||||||
|
fmt.Printf("\n\tVotes: %d", state.Votes)
|
||||||
|
fmt.Printf("\n\tHistory: %s", state.PresidentialElectoralHistory)
|
||||||
|
fmt.Printf("\n\tPolls: %s", state.Polls)
|
||||||
|
|
||||||
switch state.Name {
|
switch state.Name {
|
||||||
case "Nebraska":
|
case "Nebraska":
|
||||||
// 2000: R
|
/*
|
||||||
// 2004: R
|
2000: R
|
||||||
// 2008: Split, 1 D, 4 R
|
2004: R
|
||||||
// 2012: R
|
2008: Split, 1 D, 4 R
|
||||||
// 2016: R
|
2012: R
|
||||||
// 2020: Split, 1 D, 4 R
|
2016: R
|
||||||
|
2020: Split, 1 D, 4 R
|
||||||
|
*/
|
||||||
p_split := 2.0 / 6.0
|
p_split := 2.0 / 6.0
|
||||||
if r.Float64() < p_split {
|
if r.Float64() < p_split {
|
||||||
return VotesForEachParty{Democrats: 1, Republicans: 4}
|
return VotesForEachParty{Democrats: 1, Republicans: 4}
|
||||||
|
@ -203,12 +209,14 @@ func sampleFromState(state State) VotesForEachParty {
|
||||||
return VotesForEachParty{Democrats: 0, Republicans: 5}
|
return VotesForEachParty{Democrats: 0, Republicans: 5}
|
||||||
}
|
}
|
||||||
case "Maine":
|
case "Maine":
|
||||||
// 2000: D
|
/*
|
||||||
// 2004: D
|
2000: D
|
||||||
// 2008: D
|
2004: D
|
||||||
// 2012: D
|
2008: D
|
||||||
// 2016: Split: 3 D, 1 R
|
2012: D
|
||||||
// 2020: Split, 3 D, 1 R
|
2016: Split: 3 D, 1 R
|
||||||
|
2020: Split, 3 D, 1 R
|
||||||
|
*/
|
||||||
p_split := 2.0 / 6.0
|
p_split := 2.0 / 6.0
|
||||||
if r.Float64() < p_split {
|
if r.Float64() < p_split {
|
||||||
return VotesForEachParty{Democrats: 3, Republicans: 1}
|
return VotesForEachParty{Democrats: 3, Republicans: 1}
|
||||||
|
@ -217,6 +225,7 @@ func sampleFromState(state State) VotesForEachParty {
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
/* Just considering the base rate for the state */
|
||||||
p_republican := 0.0
|
p_republican := 0.0
|
||||||
for _, party := range state.PresidentialElectoralHistory {
|
for _, party := range state.PresidentialElectoralHistory {
|
||||||
if party == "R" {
|
if party == "R" {
|
||||||
|
@ -229,6 +238,15 @@ func sampleFromState(state State) VotesForEachParty {
|
||||||
} else {
|
} else {
|
||||||
return VotesForEachParty{Democrats: state.Votes, Republicans: 0}
|
return VotesForEachParty{Democrats: state.Votes, Republicans: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Considering polls */
|
||||||
|
var recent_polls []Poll
|
||||||
|
for _, poll := range state.Polls {
|
||||||
|
if poll.Date.After(time.Now().AddDate(0, 0, -30)) {
|
||||||
|
recent_polls = append(recent_polls, poll)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return VotesForEachParty{Democrats: 1, Republicans: 1}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,21 +255,10 @@ func simulateElection(states []State) int {
|
||||||
|
|
||||||
republican_seats := 0
|
republican_seats := 0
|
||||||
for _, state := range states {
|
for _, state := range states {
|
||||||
fmt.Printf("\n\nState: %s\n\tVotes: %d\n\tHistory: %s\n\tPolls: %s", state.Name, state.Votes, state.PresidentialElectoralHistory, state.Polls)
|
|
||||||
election_sample := sampleFromState(state)
|
election_sample := sampleFromState(state)
|
||||||
republican_seats += election_sample.Republicans
|
republican_seats += election_sample.Republicans
|
||||||
/*
|
|
||||||
fmt.Printf("%s: Votes: %d,\n\tWinners: ", state.Name, state.Votes)
|
|
||||||
for year, party := range state.PresidentialElectoralHistory {
|
|
||||||
fmt.Printf("[%s: %s] ", year, party)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\n\tSample: Democrat seats: %d, Republican seats: %d", election_sample.Democrats, election_sample.Republicans)
|
|
||||||
fmt.Println()
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
// fmt.Printf("\nDemocrat seats: %d\n", republican_seats)
|
|
||||||
fmt.Printf(" (%d) ", republican_seats)
|
fmt.Printf(" (%d) ", republican_seats)
|
||||||
if republican_seats >= 270 {
|
if republican_seats >= 270 {
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user