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

Commit

Permalink
Biden --> Harris
Browse files Browse the repository at this point in the history
  • Loading branch information
texadactyl committed Jul 22, 2024
1 parent cc27575 commit f26925d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 92 deletions.
14 changes: 7 additions & 7 deletions helpers/dbfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const tableHistory = "history"
const colDateStamp = "date_stamp"
const colTimeStamp = "time_stamp"
const colState = "state"
const colPctBiden = "pct_biden"
const colPctTrump = "pct_trump"
const colPctDem = "pct_dem"
const colPctGop = "pct_gop"
const colPctZero = "pct_zero"
const colStartDate = "start_date"
const colEndDate = "end_date"
Expand All @@ -32,8 +32,8 @@ type dbparams struct {
state string
startDate string
endDate string
pctBiden float64
pctTrump float64
pctDem float64
pctGop float64
pollster string
}

Expand Down Expand Up @@ -105,8 +105,8 @@ func initDB() {
sqlText += colState + " VARCHAR NOT NULL, "
sqlText += colStartDate + " VARCHAR NOT NULL, "
sqlText += colEndDate + " VARCHAR NOT NULL, "
sqlText += colPctBiden + " FLOAT NOT NULL, "
sqlText += colPctTrump + " FLOAT NOT NULL, "
sqlText += colPctDem + " FLOAT NOT NULL, "
sqlText += colPctGop + " FLOAT NOT NULL, "
sqlText += colPollster + " VARCHAR NOT NULL, "
sqlText += "PRIMARY KEY (" + colState + ", " + colEndDate + ") )"
sqlFunc(sqlText)
Expand Down Expand Up @@ -206,7 +206,7 @@ func DBStore(fields dbparams) {
timeUTC := "'" + GetUtcTime() + "'"
sqlText := "INSERT OR REPLACE INTO " + tableHistory + " VALUES("
sqlText += dateUTC + ", " + timeUTC + ",\"" + fields.state + "\", \"" + fields.startDate + "\", \"" + fields.endDate
caboose := fmt.Sprintf("\", %f, %f, \"%s\" )", fields.pctBiden, fields.pctTrump, fields.pollster)
caboose := fmt.Sprintf("\", %f, %f, \"%s\" )", fields.pctDem, fields.pctGop, fields.pollster)
sqlText += caboose

sqlFunc(sqlText)
Expand Down
8 changes: 4 additions & 4 deletions helpers/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func Load(dirCsv, fileName string) {

// Collect all the column values.
pollFields.state = strings.ToUpper(colArray[0])
pollFields.pctBiden, err = strconv.ParseFloat(colArray[1], 64)
pollFields.pctDem, err = strconv.ParseFloat(colArray[1], 64)
if err != nil {
log.Fatalf("Load: Biden pct from %s is not a valid float at line %d\n", fullPath, lineCounter)
log.Fatalf("Load: Dem pct from %s is not a valid float at line %d\n", fullPath, lineCounter)
}
pollFields.pctTrump, err = strconv.ParseFloat(colArray[2], 64)
pollFields.pctGop, err = strconv.ParseFloat(colArray[2], 64)
if err != nil {
log.Fatalf("Load: Trump pct from %s is not a valid float at line %d\n", fullPath, lineCounter)
log.Fatalf("Load: Gop pct from %s is not a valid float at line %d\n", fullPath, lineCounter)
}
month, err := MonthToInt(colArray[4])
if err != nil {
Expand Down
26 changes: 13 additions & 13 deletions helpers/plodder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"gonum.org/v1/plot/vg/draw"
)

func plotOneState(state string, endDateArray []string, bidenPctArray, trumpPctArray, otherPctArray []float64) {
func plotOneState(state string, endDateArray []string, demPctArray, gopPctArray, otherPctArray []float64) {
glob := global.GetGlobalRef()
RED := color.NRGBA{R: 255, A: 255}
//GREEN := color.NRGBA{G: 255, A: 255}
Expand Down Expand Up @@ -56,7 +56,7 @@ func plotOneState(state string, endDateArray []string, bidenPctArray, trumpPctAr
return pts
}

data := linePoints(endDateArray, bidenPctArray)
data := linePoints(endDateArray, demPctArray)
if countPoints < 1 {
return
}
Expand All @@ -65,18 +65,18 @@ func plotOneState(state string, endDateArray []string, bidenPctArray, trumpPctAr

line, points, err := plotter.NewLinePoints(data)
if err != nil {
log.Fatalf("plotOneState: internal error diagnosed in plotter.NewLinePoints(biden), reason: %s\n" + err.Error())
log.Fatalf("plotOneState: internal error diagnosed in plotter.NewLinePoints(dem), reason: %s\n" + err.Error())
}
line.Color = BLUE
line.Width = 2
points.Shape = draw.CircleGlyph{}
points.Color = BLACK
plt.Add(line, points)

data = linePoints(endDateArray, trumpPctArray)
data = linePoints(endDateArray, gopPctArray)
line, points, err = plotter.NewLinePoints(data)
if err != nil {
log.Fatalf("plotOneState: internal error diagnosed in plotter.NewLinePoints(trump), reason: %s\n" + err.Error())
log.Fatalf("plotOneState: internal error diagnosed in plotter.NewLinePoints(gop), reason: %s\n" + err.Error())
}
line.Color = RED
line.Width = 2
Expand Down Expand Up @@ -108,32 +108,32 @@ func Plodder() {
var stateECV ECVote
for _, stateECV = range stateECVTable {
// For the given state, query from the most recent to the least recent polling.
sqlText := fmt.Sprintf("SELECT end_date, pct_biden, pct_trump FROM history WHERE state = '%s' ORDER BY end_date DESC",
sqlText := fmt.Sprintf("SELECT end_date, pct_dem, pct_gop FROM history WHERE state = '%s' ORDER BY end_date DESC",
stateECV.state)
rows := sqlQuery(sqlText)

var query dbparams
var endDateArray []string
var bidenPctArray []float64
var trumpPctArray []float64
var demPctArray []float64
var gopPctArray []float64
var otherPctArray []float64
counter := 0
for rows.Next() {
counter += 1
err := rows.Scan(&query.endDate, &query.pctBiden, &query.pctTrump)
err := rows.Scan(&query.endDate, &query.pctDem, &query.pctGop)
if err != nil {
log.Fatalf("Plodder: rows.Scan failed, row count: %d, reason: %s\n", counter, err.Error())
}
endDateArray = append(endDateArray, query.endDate)
bidenPctArray = append(bidenPctArray, query.pctBiden)
trumpPctArray = append(trumpPctArray, query.pctTrump)
curOtherPct := CalcOther(query.pctBiden, query.pctTrump)
demPctArray = append(demPctArray, query.pctDem)
gopPctArray = append(gopPctArray, query.pctGop)
curOtherPct := CalcOther(query.pctDem, query.pctGop)
otherPctArray = append(otherPctArray, curOtherPct)
if counter >= glob.PollHistoryLimit {
break
}
}
plotOneState(stateECV.state, endDateArray, bidenPctArray, trumpPctArray, otherPctArray)
plotOneState(stateECV.state, endDateArray, demPctArray, gopPctArray, otherPctArray)
}
log.Println("State plots completed")
}
90 changes: 45 additions & 45 deletions helpers/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func ReportSC(state string) {
var query dbparams

// For the given state, query from the most recent to the least recent polling.
sqlText := fmt.Sprintf("SELECT state, end_date, pct_biden, pct_trump, pollster FROM history WHERE state = '%s' ORDER BY end_date DESC", state)
sqlText := fmt.Sprintf("SELECT state, end_date, pct_dem, pct_gop, pollster FROM history WHERE state = '%s' ORDER BY end_date DESC", state)

// Get all the selected history table rows.
counterScan := 0
Expand All @@ -22,10 +22,10 @@ func ReportSC(state string) {
rows := sqlQuery(sqlText)

// For each row, process it...
fmt.Printf("%-8s %-4s %-4s %-4s %-s\n", "EndPoll", "Biden", "Trump", "Other", "Pollster")
fmt.Printf("%-8s %-4s %-4s %-4s %-s\n", "EndPoll", "Dem", "Gop", "Other", "Pollster")
for rows.Next() {
counterScan += 1
err := rows.Scan(&query.state, &query.endDate, &query.pctBiden, &query.pctTrump, &query.pollster)
err := rows.Scan(&query.state, &query.endDate, &query.pctDem, &query.pctGop, &query.pollster)
if err != nil {
log.Fatalf("ReportSC: rows.Scan failed, row count: %d, reason: %s\n", counterScan, err.Error())
}
Expand All @@ -37,8 +37,8 @@ func ReportSC(state string) {
continue
}
counterPrint++
other := CalcOther(query.pctBiden, query.pctTrump)
fmt.Printf("%-8s %4.1f %4.1f %4.1f %-s\n", query.endDate, query.pctBiden, query.pctTrump, other, query.pollster)
other := CalcOther(query.pctDem, query.pctGop)
fmt.Printf("%-8s %4.1f %4.1f %4.1f %-s\n", query.endDate, query.pctDem, query.pctGop, other, query.pollster)
if counterScan >= glob.PollHistoryLimit {
break
}
Expand All @@ -51,20 +51,20 @@ func ReportSC(state string) {
func ReportEC() {
glob := global.GetGlobalRef()
var stateECV ECVote
totalBidenECV := 0
totalTrumpECV := 0
totalDemECV := 0
totalGopECV := 0
totalTossupECV := 0
counterBidenStates := 0
counterTrumpStates := 0
counterDemStates := 0
counterGopStates := 0
counterTossupStates := 0
listBidenStates := ""
listTrumpStates := ""
listDemStates := ""
listGopStates := ""
listTossupStates := ""
var arrayBidenPct []float64
var arrayTrumpPct []float64
var arrayDemPct []float64
var arrayGopPct []float64
var arrayOtherPct []float64
prtDivider := "-----------------------------------------------------------"
fmt.Println("\nSt EV Last Poll Biden Trump Other Leading")
fmt.Println("\nSt EV Last Poll Dem Gop Other Leading")
fmt.Println(prtDivider)
for _, stateECV = range stateECVTable {
if glob.FlagBattleground {
Expand All @@ -73,19 +73,19 @@ func ReportEC() {
}
}
// For the given state, query from the most recent to the least recent polling.
sqlText := fmt.Sprintf("SELECT end_date, pct_biden, pct_trump FROM history WHERE state = '%s' ORDER BY end_date DESC",
sqlText := fmt.Sprintf("SELECT end_date, pct_dem, pct_gop FROM history WHERE state = '%s' ORDER BY end_date DESC",
stateECV.state)
rows := sqlQuery(sqlText)

counterScan := 0
counterPrint := 0
var query dbparams
aveBidenPct := 0.0
aveTrumpPct := 0.0
aveDemPct := 0.0
aveGopPct := 0.0
endDate := ""
for rows.Next() {
counterScan += 1
err := rows.Scan(&query.endDate, &query.pctBiden, &query.pctTrump)
err := rows.Scan(&query.endDate, &query.pctDem, &query.pctGop)
if err != nil {
log.Fatalf("ReportEC: rows.Scan failed, row count: %d, reason: %s\n", counterScan, err.Error())
}
Expand All @@ -100,11 +100,11 @@ func ReportEC() {
if counterScan == 1 {
endDate = query.endDate
}
aveBidenPct += query.pctBiden
arrayBidenPct = append(arrayBidenPct, query.pctBiden)
aveTrumpPct += query.pctTrump
arrayTrumpPct = append(arrayTrumpPct, query.pctTrump)
arrayOtherPct = append(arrayOtherPct, CalcOther(query.pctBiden, query.pctTrump))
aveDemPct += query.pctDem
arrayDemPct = append(arrayDemPct, query.pctDem)
aveGopPct += query.pctGop
arrayGopPct = append(arrayGopPct, query.pctGop)
arrayOtherPct = append(arrayOtherPct, CalcOther(query.pctDem, query.pctGop))
if counterScan >= glob.PollHistoryLimit {
break
}
Expand All @@ -116,53 +116,53 @@ func ReportEC() {
}

// Averages for this state.
aveBidenPct /= float64(counterScan)
aveTrumpPct /= float64(counterScan)
aveOtherPct := CalcOther(aveBidenPct, aveTrumpPct)
aveDemPct /= float64(counterScan)
aveGopPct /= float64(counterScan)
aveOtherPct := CalcOther(aveDemPct, aveGopPct)
leader := ""
var increBiden, increTrump, increTossup int
var increDem, increGop, increTossup int
otherFactor := ""
switch glob.ECVAlgorithm {
case 1:
leader, increBiden, increTrump, increTossup = ECVAward1(stateECV.votes, aveBidenPct, aveTrumpPct)
leader, increDem, increGop, increTossup = ECVAward1(stateECV.votes, aveDemPct, aveGopPct)
case 2:
leader, increBiden, increTrump, increTossup, otherFactor = ECVAward2(stateECV.votes, aveBidenPct, aveTrumpPct)
leader, increDem, increGop, increTossup, otherFactor = ECVAward2(stateECV.votes, aveDemPct, aveGopPct)
case 3:
leader, increBiden, increTrump, increTossup, otherFactor = ECVAward3(stateECV.votes, aveBidenPct, aveTrumpPct)
leader, increDem, increGop, increTossup, otherFactor = ECVAward3(stateECV.votes, aveDemPct, aveGopPct)
default:
log.Fatalf("ReportEC: global.ECVAlgoithm %d is not supported\n", glob.ECVAlgorithm)
}

totalBidenECV += increBiden
totalTrumpECV += increTrump
totalDemECV += increDem
totalGopECV += increGop
totalTossupECV += increTossup
switch leader {
case "Biden":
counterBidenStates++
listBidenStates += " " + stateECV.state
case "Trump":
counterTrumpStates++
listTrumpStates += " " + stateECV.state
case "Dem":
counterDemStates++
listDemStates += " " + stateECV.state
case "Gop":
counterGopStates++
listGopStates += " " + stateECV.state
default:
counterTossupStates++
listTossupStates += " " + stateECV.state
}

// Show results for current state.
bidenTrend := CalcTrend(arrayBidenPct)
trumpTrend := CalcTrend(arrayTrumpPct)
demTrend := CalcTrend(arrayDemPct)
gopTrend := CalcTrend(arrayGopPct)
otherTrend := CalcTrend(arrayOtherPct)
fmt.Printf("%-2s %2d %-8s %4.1f %s %4.1f %s %4.1f %2s%2s %-s\n",
stateECV.state, stateECV.votes, endDate, aveBidenPct, bidenTrend,
aveTrumpPct, trumpTrend, aveOtherPct, otherTrend, otherFactor, leader)
stateECV.state, stateECV.votes, endDate, aveDemPct, demTrend,
aveGopPct, gopTrend, aveOtherPct, otherTrend, otherFactor, leader)

}
// Totals.
fmt.Println(prtDivider)
if glob.ECVAlgorithm != 1 {
fmt.Println("** The Other percentage exceeds the difference between Biden and Trump.")
fmt.Println("** The Other percentage exceeds the difference between Dem and Gop.")
}
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("Dem EV: %3d, states: (%2d)%s\n", totalDemECV, counterDemStates, listDemStates)
fmt.Printf("Gop EV: %3d, states: (%2d)%s\n", totalGopECV, counterGopStates, listGopStates)
fmt.Printf("Tossup EV: %3d, states: (%2d)%s\n", totalTossupECV, counterTossupStates, listTossupStates)
}
Loading

0 comments on commit f26925d

Please sign in to comment.