refactor snake_case
This commit is contained in:
parent
87c48c5f61
commit
08571ee9b6
24
main.go
24
main.go
|
@ -24,26 +24,26 @@ func readStates() ([]State, error) {
|
||||||
var years = []string{"2000", "2004", "2008", "2012", "2016", "2020"}
|
var years = []string{"2000", "2004", "2008", "2012", "2016", "2020"}
|
||||||
|
|
||||||
/* Electoral college votes for the 2024 election*/
|
/* Electoral college votes for the 2024 election*/
|
||||||
votesFilename := "data/electoral-college-votes.csv"
|
votes_file, err := os.Open("data/electoral-college-votes.csv")
|
||||||
votesFile, err := os.Open(votesFilename)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening the votes file: %v", err)
|
return nil, fmt.Errorf("error opening the votes file: %v", err)
|
||||||
}
|
}
|
||||||
defer votesFile.Close()
|
defer votes_file.Close()
|
||||||
votesReader := csv.NewReader(votesFile)
|
|
||||||
if _, err := votesReader.Read(); err != nil { // Skip header
|
votes_reader := csv.NewReader(votes_file)
|
||||||
|
if _, err := votes_reader.Read(); err != nil { // Skip header
|
||||||
return nil, fmt.Errorf("error reading votes header: %v", err)
|
return nil, fmt.Errorf("error reading votes header: %v", err)
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
record, err := votesReader.Read()
|
csv_record, err := votes_reader.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break // EOF or an error
|
break // EOF or an error
|
||||||
}
|
}
|
||||||
votes, err := strconv.Atoi(record[1])
|
votes, err := strconv.Atoi(csv_record[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue // Error in converting votes, skip this record
|
continue // Error in converting votes, skip this record
|
||||||
}
|
}
|
||||||
state := record[0]
|
state := csv_record[0]
|
||||||
if _, exists := states[state]; !exists {
|
if _, exists := states[state]; !exists {
|
||||||
states[state] = State{Name: state, Votes: votes}
|
states[state] = State{Name: state, Votes: votes}
|
||||||
}
|
}
|
||||||
|
@ -51,13 +51,13 @@ func readStates() ([]State, error) {
|
||||||
|
|
||||||
/* Election results */
|
/* Election results */
|
||||||
for _, year := range years {
|
for _, year := range years {
|
||||||
resultsFilename := fmt.Sprintf("data/results/%s.csv", year)
|
results_filename := fmt.Sprintf("data/results/%s.csv", year)
|
||||||
resultsFile, err := os.Open(resultsFilename)
|
results_file, err := os.Open(results_filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening the results file for %s: %v", year, err)
|
return nil, fmt.Errorf("error opening the results file for %s: %v", year, err)
|
||||||
}
|
}
|
||||||
defer resultsFile.Close()
|
defer results_file.Close()
|
||||||
resultsReader := csv.NewReader(resultsFile)
|
resultsReader := csv.NewReader(results_file)
|
||||||
if _, err := resultsReader.Read(); err != nil { // Skip header
|
if _, err := resultsReader.Read(); err != nil { // Skip header
|
||||||
return nil, fmt.Errorf("error reading results header for %s: %v", year, err)
|
return nil, fmt.Errorf("error reading results header for %s: %v", year, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user