-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
94 lines (84 loc) · 2.67 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"github.com/molson82/ncaa-sim/models"
)
func findNCAAMBTeams(apiTeams []models.Team, bracket models.NCAAMB) map[string]models.Team__c {
results := make(map[string]models.Team__c)
duplicates := make(map[string][]models.Team__c)
for _, v := range bracket.Matches {
var count int
for _, q := range apiTeams {
if (strings.Contains(strings.ToLower(q.Name), strings.ToLower(v.TeamA))) ||
(strings.Contains(strings.ToLower(q.Team), strings.ToLower(v.TeamA))) {
if count > 0 {
duplicates[v.TeamA] = append(duplicates[v.TeamA], models.Team__c{q.TeamID, q.Name, q.Team, q.Wins, q.Losses, v.Order, "A"})
continue
}
results[v.TeamA] = models.Team__c{q.TeamID, q.Name, q.Team, q.Wins, q.Losses, v.Order, "A"}
count++
}
}
}
for _, v := range bracket.Matches {
var count int
for _, q := range apiTeams {
if (strings.Contains(strings.ToLower(q.Name), strings.ToLower(v.TeamB))) ||
(strings.Contains(strings.ToLower(q.Team), strings.ToLower(v.TeamB))) {
if count > 0 {
duplicates[v.TeamB] = append(duplicates[v.TeamB], models.Team__c{q.TeamID, q.Name, q.Team, q.Wins, q.Losses, v.Order, "B"})
continue
}
results[v.TeamB] = models.Team__c{q.TeamID, q.Name, q.Team, q.Wins, q.Losses, v.Order, "B"}
count++
}
}
}
return handleDuplicates(results, duplicates)
}
func handleDuplicates(result map[string]models.Team__c, dups map[string][]models.Team__c) map[string]models.Team__c {
finalResults := result
OUTER:
for k, v := range dups {
fmt.Printf("\n-----------------------------------------------------------------------------")
fmt.Printf("\n%v Results for: %v\n[", len(v)+1, k)
fmt.Printf("%v, ", result[k].Name)
for _, j := range v {
fmt.Printf("%v, ", j.Name)
}
fmt.Printf("]\n")
c := askForConfirmation(fmt.Sprintf("\nIs this the correct one?\nName: %v | Team: %v | Wins: %v | Losses: %v ", result[k].Name, result[k].Team, result[k].Wins, result[k].Losses))
if c {
finalResults[k] = result[k]
continue
}
for _, j := range v {
q := askForConfirmation(fmt.Sprintf("\nIs this the correct one?\nName: %v | Team: %v | Wins: %v | Losses: %v ", j.Name, j.Team, j.Wins, j.Losses))
if q {
finalResults[k] = j
continue OUTER
}
}
}
return finalResults
}
func askForConfirmation(s string) bool {
reader := bufio.NewReader(os.Stdin)
for {
fmt.Printf("%s [y/n]: ", s)
response, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}
response = strings.ToLower(strings.TrimSpace(response))
if response == "y" || response == "yes" {
return true
} else if response == "n" || response == "no" {
return false
}
}
}