-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrade_fairness.go
More file actions
122 lines (106 loc) · 3.3 KB
/
trade_fairness.go
File metadata and controls
122 lines (106 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
// ABOUTME: Trade fairness detection for dynasty leagues
// ABOUTME: Flags extreme value gaps ("fleeced" trades) while recognizing valid rebuild/compete strategies
package main
import (
"fmt"
"math"
)
const (
FLEECED_THRESHOLD = 15.0 // Q8: ~15% value delta (aggressive detection, iterate as needed)
FAIR_THRESHOLD = 5.0 // Below this is considered fair
)
func calculateTradeFairness(transaction Transaction, allRosterValues map[string]int) TradeFairness {
// Skip if no dynasty values
if transaction.Team1GaveValue == 0 && transaction.Team2GaveValue == 0 {
return TradeFairness{
Winner: "Fair",
DisplayBadge: "",
}
}
// Calculate delta
team1Gave := transaction.Team1GaveValue
team2Gave := transaction.Team2GaveValue
delta := int(math.Abs(float64(team1Gave - team2Gave)))
// Determine winner
winner := "Fair"
winnerTeam := ""
var deltaPct float64
if team1Gave == 0 && team2Gave == 0 {
// No values, can't determine fairness
return TradeFairness{
Winner: "Fair",
DisplayBadge: "",
}
}
if team1Gave > team2Gave {
winner = "Team2"
winnerTeam = transaction.Team2
} else if team2Gave > team1Gave {
winner = "Team1"
winnerTeam = transaction.Team1
}
// Calculate delta as % of smaller trade side (more generous)
// This prevents small trades from being flagged as unfair
smallerSide := team1Gave
if team2Gave > 0 && team2Gave < team1Gave {
smallerSide = team2Gave
}
if smallerSide > 0 {
deltaPct = float64(delta) / float64(smallerSide) * 100
}
// Determine if fleeced
fleeced := deltaPct >= FLEECED_THRESHOLD
// Context detection (Q7: hybrid approach)
context := ""
if deltaPct < FAIR_THRESHOLD {
context = "Fair trade"
} else if deltaPct < FLEECED_THRESHOLD {
// Moderate gap - could be strategic
context = fmt.Sprintf("%s won on value", winnerTeam)
// TODO: Add rebuild/compete detection
// if isRebuildingStrategy(transaction) {
// context = fmt.Sprintf("%s rebuilding - acquiring future value", winnerTeam)
// } else if isCompetingStrategy(transaction) {
// context = fmt.Sprintf("%s competing - acquired win-now pieces", winnerTeam)
// }
} else {
// Fleeced
context = "Extreme value gap - verify trade validity"
}
// Display badge (Q9: subtle)
badge := ""
if fleeced {
badge = fmt.Sprintf("%s +%.0f%% 🔴", winnerTeam, deltaPct)
} else if deltaPct >= FAIR_THRESHOLD {
badge = fmt.Sprintf("%s +%.0f%%", winnerTeam, deltaPct)
} else {
badge = "Fair trade"
}
return TradeFairness{
Winner: winner,
ValueDelta: delta,
ValueDeltaPct: deltaPct,
Fleeced: fleeced,
Context: context,
WinnerTeam: winnerTeam,
DisplayBadge: badge,
}
}
// Helper: detect rebuilding strategy
// TODO: Implement heuristics:
// - Winner received mostly picks + young players (age < 24)
// - Winner gave away older players (age > 26)
// - Winner's roster avg age decreased significantly
func isRebuildingStrategy(transaction Transaction) bool {
// Placeholder for future implementation
return false
}
// Helper: detect competing strategy
// TODO: Implement heuristics:
// - Winner received proven starters (top-24 positional players)
// - Winner gave away picks + young players
// - Winner's roster avg age increased
func isCompetingStrategy(transaction Transaction) bool {
// Placeholder for future implementation
return false
}