-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
136 lines (123 loc) · 3.3 KB
/
utils.go
File metadata and controls
136 lines (123 loc) · 3.3 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// ABOUTME: Utility functions for SleeperPy application
// ABOUTME: Includes string manipulation, name normalization, and helper functions
package main
import (
"strings"
)
// toStringSlice converts interface{} to []string safely
func toStringSlice(val interface{}) []string {
arr := []string{}
if val == nil {
return arr
}
switch v := val.(type) {
case []interface{}:
for _, x := range v {
if s, ok := x.(string); ok {
arr = append(arr, s)
}
}
}
return arr
}
// diff returns elements in a that are not in b
func diff(a, b []string) []string {
m := make(map[string]bool)
for _, x := range b {
m[x] = true
}
out := []string{}
for _, x := range a {
if !m[x] {
out = append(out, x)
}
}
return out
}
// findTier locates the tier number for a player by name
func findTier(tiers [][]string, name string) int {
norm := normalizeName(name)
for i, names := range tiers {
for _, n := range names {
if normalizeName(n) == norm {
return i + 1
}
}
}
return 0
}
// normalizeName standardizes player names for comparison
func normalizeName(name string) string {
name = strings.ToLower(name)
name = strings.ReplaceAll(name, ".", "")
name = strings.ReplaceAll(name, ",", "")
for _, suf := range []string{" jr", " sr", " ii", " iii", " iv", " v"} {
name = strings.TrimSuffix(name, suf)
}
// Remove non-alphanumeric except spaces
var result strings.Builder
for _, r := range name {
if (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') || r == ' ' {
result.WriteRune(r)
}
}
name = strings.Join(strings.Fields(result.String()), " ")
return name
}
// stripHTML removes HTML tags from strings
func stripHTML(s string) string {
if idx := strings.Index(s, "<span"); idx >= 0 {
return strings.TrimSpace(s[:idx])
}
return s
}
// isDynastyLeague determines if a league is dynasty format
func isDynastyLeague(league map[string]interface{}) bool {
// Check type field - type 2 indicates dynasty league
if settings, ok := league["settings"].(map[string]interface{}); ok {
if leagueType, ok := settings["type"].(float64); ok && leagueType == 2 {
debugLog("[DEBUG] League detected as dynasty via type: %v", leagueType)
return true
}
}
// Check for taxi squad (dynasty-specific feature)
if settings, ok := league["settings"].(map[string]interface{}); ok {
if taxiSlots, ok := settings["taxi_slots"].(float64); ok && taxiSlots > 0 {
debugLog("[DEBUG] League detected as dynasty via taxi_slots: %v", taxiSlots)
return true
}
}
// Fallback: check league name for "dynasty" keyword
if name, ok := league["name"].(string); ok {
nameLower := strings.ToLower(name)
if strings.Contains(nameLower, "dynasty") {
debugLog("[DEBUG] League detected as dynasty via name: %s", name)
return true
}
}
return false
}
// parseCSVLine parses a CSV line handling quoted fields
func parseCSVLine(line string) []string {
var fields []string
var current strings.Builder
inQuotes := false
for i := 0; i < len(line); i++ {
char := line[i]
if char == '"' {
if inQuotes && i+1 < len(line) && line[i+1] == '"' {
current.WriteByte('"')
i++
} else {
inQuotes = !inQuotes
}
} else if char == ',' && !inQuotes {
fields = append(fields, current.String())
current.Reset()
} else {
current.WriteByte(char)
}
}
fields = append(fields, current.String())
return fields
}