Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
clarify reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
texadactyl committed Jun 17, 2024
1 parent a58c947 commit 5a00e34
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 76 deletions.
46 changes: 22 additions & 24 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
PollHistoryLimit: 3
TossupThreshold: 3.01
ECVAlgorithm: 2
ECVAlgorithm: 3
PlotHeight: 10.0
PlotWidth: 10.0

# PollHistoryLimit: Poll History Limit (integer)
# Only look back this many polls or less.

# TossupThreshold: Tossup Threshold (float64)
# If the percentage difference is less than this threshold, its a tossup.
PollHistoryLimit: 3
TossupThreshold: 3.01

# ECVAlgorithm: Electoral College Vote Allocation Algorithm (integer)

# 1
# Other percentage = 100% - (sum percentages of the candidates).
# Difference = absolute value of the difference between candidates.

# 1 - Split the Other Proportionately.
#
# Split the "Other" percentage proportionally amongst the candidates. Then,
# Which candidate has a higher poll percentage?
# If the difference between candidates is below the tossup threshold,
# it's a tossup.
# Split the "Other" percentage proportionally amongst the candidates.
# If the difference between candidates is below the tossup threshold, it's a tossup.

# 2
# 2 - Compare the difference to the tossup threshold.
#
# Which candidate has a higher poll percentage?
# If the difference between candidates is below the tossup threshold,
# it's a tossup.
# Might the "Other" percentage make a difference in the future?
# If so, indicate that in the output.
# If the difference between candidates is below the tossup threshold, it's a tossup.
# If the "Other" percentage exceeds the difference, indicate that in the other factor output.


# 3
# 3 - Like #2 except "other" plays a roll in determining tossup status.
#
# Which candidate has a higher poll percentage?
# If the other percentage exceeds the difference between Biden and Trump,
# * Indicate that in the other factor output.
# * It's a tossup.
# If the difference between candidates is below the tossup threshold,
# it's a tossup.
# If the "Other" percentage would make a difference in the future,
# it's a tossup.

# Plot height and width (float64)
# These are the height and width respectively, measured in the quantity of postscript points (dots)

# PollHistoryLimit: Poll History Limit (integer)
# Only look back this many polls or less.

# TossupThreshold: Tossup Threshold (float64)
# If the percentage difference is less than this threshold, its a tossup.

26 changes: 14 additions & 12 deletions helpers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type paramsStruct struct {
}

func GetConfig() {

var params paramsStruct
glob := global.GetGlobalRef()
bytes, err := os.ReadFile(glob.CfgFile)
Expand All @@ -30,18 +31,6 @@ func GetConfig() {
log.Fatalf("yaml.Unmarshal from %s failed, reason: %s\n", glob.CfgFile, err.Error())
}

glob.PollHistoryLimit, err = strconv.Atoi(params.PollHistoryLimit)
if err != nil {
log.Fatalf("strconv.Atoi(PollHistoryLimit) from %s failed, reason: %s\n", glob.CfgFile, err.Error())
}
log.Printf("GetConfig: PollHistoryLimit: %d", glob.PollHistoryLimit)

glob.TossupThreshold, err = strconv.ParseFloat(params.TossupThreshold, 64)
if err != nil {
log.Fatalf("GetConfig: strconv.ParseFloat(TossupThreshold) from %s failed, reason: %s\n", glob.CfgFile, err.Error())
}
log.Printf("GetConfig: TossupThreshold: %f", glob.TossupThreshold)

glob.ECVAlgorithm, err = strconv.Atoi(params.ECVAlgorithm)
if err != nil {

Expand All @@ -60,4 +49,17 @@ func GetConfig() {
log.Fatalf("GetConfig: strconv.ParseFloat(PlotHeight) from %s failed, reason: %s\n", glob.CfgFile, err.Error())
}
log.Printf("GetConfig: PlotHeight: %f", glob.PlotHeight)

glob.PollHistoryLimit, err = strconv.Atoi(params.PollHistoryLimit)
if err != nil {
log.Fatalf("strconv.Atoi(PollHistoryLimit) from %s failed, reason: %s\n", glob.CfgFile, err.Error())
}
log.Printf("GetConfig: PollHistoryLimit: %d", glob.PollHistoryLimit)

glob.TossupThreshold, err = strconv.ParseFloat(params.TossupThreshold, 64)
if err != nil {
log.Fatalf("GetConfig: strconv.ParseFloat(TossupThreshold) from %s failed, reason: %s\n", glob.CfgFile, err.Error())
}
log.Printf("GetConfig: TossupThreshold: %f", glob.TossupThreshold)

}
5 changes: 4 additions & 1 deletion helpers/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func ReportEC() {
case 2:
leader, increBiden, increTrump, increTossup, otherFactor = ECVAward2(stateECV.votes, aveBidenPct, aveTrumpPct)
case 3:
leader, increBiden, increTrump, increTossup = ECVAward3(stateECV.votes, aveBidenPct, aveTrumpPct)
leader, increBiden, increTrump, increTossup, otherFactor = ECVAward3(stateECV.votes, aveBidenPct, aveTrumpPct)
default:
log.Fatalf("ReportEC: global.ECVAlgoithm %d is not supported\n", glob.ECVAlgorithm)
}
Expand Down Expand Up @@ -127,6 +127,9 @@ func ReportEC() {
}
// Totals.
fmt.Println(prtDivider)
if glob.ECVAlgorithm != 1 {
fmt.Println("** The Other percentage exceeds the difference between Biden and Trump.")
}
fmt.Printf("Biden EV: %3d, states: (%2d)%s\n", totalBidenECV, counterBidenStates, listBidenStates)
fmt.Printf("Trump EV: %3d, states: (%2d)%s\n", totalTrumpECV, counterTrumpStates, listTrumpStates)
fmt.Printf("Tossup EV: %3d, states: (%2d)%s\n", totalTossupECV, counterTossupStates, listTossupStates)
Expand Down
60 changes: 21 additions & 39 deletions helpers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,24 +218,20 @@ func getFactorString(arg bool) string {
/*
ECVAward1 - ECV Award Algorithm 1.
Split the "Other" percentage proportionally amongst the candidates. Then,
Which candidate has a higher poll percentage?
Is the difference below the tossup threshold?
Calculate the Other percentage = 100 - the sum of the candidate percentages.
Split the "Other" percentage proportionally amongst the candidates.
Calculate the difference = absolute value of the difference between the candidates.
Calculate the Other percentage = 100 - the sum of the Biden and Trump percentages.
The Other percentage is awarded proportionately to both candidates.
If the new Biden and Trump totals have a difference below the TossupThreshold,
then the outcome is a tossup.
Otherwise, determine the leader and ECV award.
The Other factor is always returned false.
If the difference is below the tossup threshold, then this state is a tossup.
*/
func ECVAward1(stateVotes int, pctBiden, pctTrump float64) (string, int, int, int) {
glob := global.GetGlobalRef()
pctOther := CalcOther(pctBiden, pctTrump)

pctBiden += pctOther * pctBiden / 100.0
pctTrump += pctOther * pctTrump / 100.0

diff := math.Abs(pctBiden - pctTrump)

if diff < glob.TossupThreshold {
return "TOSSUP", 0, 0, stateVotes
} else {
Expand All @@ -250,18 +246,11 @@ func ECVAward1(stateVotes int, pctBiden, pctTrump float64) (string, int, int, in
/*
ECVAward2 - ECV Award Algorithm 2.
Which candidate has a higher poll percentage?
Is the difference below the tossup threshold?
Calculate the Other percentage = 100 - the sum of the candidate percentages.
Calculate the difference = absolute value of the difference between the candidates.
Might the "Other" percentage make a difference in the future?
If so, provide a "**" flag.
Calculate the Other percentage = 100 - the sum of the Biden and Trump percentages.
If the new Biden and Trump totals have a difference below the TossupThreshold,
then the outcome is a tossup.
Otherwise, determine the leader and ECV award.
The Other factor is true if and only if the Other percentage exceeds the TossupThreshold
that is to say that the Other tallies could swing the voting significantly in the future.
If the "Other" percentage exceeds the difference, then flag this state on return.
If the difference is below the tossup threshold, then this state is a tossup.
*/
func ECVAward2(stateVotes int, pctBiden, pctTrump float64) (string, int, int, int, string) {
glob := global.GetGlobalRef()
Expand All @@ -279,31 +268,24 @@ func ECVAward2(stateVotes int, pctBiden, pctTrump float64) (string, int, int, in
/*
ECVAward3 - ECV Award Algorithm 3.
Which candidate has a higher poll percentage?
Is the difference below the tossup threshold?
Might the "Other" percentage make a difference in the future?
If so, then this state is a tossup.
Calculate the Other percentage = 100 - the sum of the candidate percentages.
Calculate the difference = absolute value of the difference between the candidates.
Calculate the Other percentage = 100 - the sum of the Biden and Trump percentages.
If the new Biden and Trump totals have a difference below the TossupThreshold,
then the outcome is a tossup.
Otherwise, determine the leader and ECV award.
The Other factor is true if and only if the Other percentage exceeds the TossupThreshold
that is to say that the Other tallies could swing the voting significantly in the future.
If the "Other" percentage exceeds the difference, then this state is a tossup.
If the difference is below the tossup threshold, then this state is a tossup.
*/
func ECVAward3(stateVotes int, pctBiden, pctTrump float64) (string, int, int, int) {
func ECVAward3(stateVotes int, pctBiden, pctTrump float64) (string, int, int, int, string) {
glob := global.GetGlobalRef()
diff := math.Abs(pctBiden - pctTrump)
pctOther := CalcOther(pctBiden, pctTrump)
if diff < glob.TossupThreshold {
return "TOSSUP", 0, 0, stateVotes
}
if pctOther > diff {
return "TOSSUP", 0, 0, stateVotes
return "TOSSUP", 0, 0, stateVotes, getFactorString(true)
}
if diff < glob.TossupThreshold {
return "TOSSUP", 0, 0, stateVotes, " "
}
if pctBiden > pctTrump {
return "Biden", stateVotes, 0, 0
return "Biden", stateVotes, 0, 0, " "
}
return "Trump", 0, stateVotes, 0
return "Trump", 0, stateVotes, 0, " "
}

0 comments on commit 5a00e34

Please sign in to comment.