- Added evaluation functions for NFL money line, spread, and total points. - Implemented evaluation functions for Rugby money line, spread, and total points. - Created evaluation functions for Baseball money line, spread, total runs, first inning, and first 5 innings. - Developed unit tests for all sports markets to ensure correct evaluation outcomes. - Introduced ResultCheckerService to handle game result checking for NFL, Rugby, and Baseball. - Updated routes to include new functionality for virtual game handling.
291 lines
8.9 KiB
Go
291 lines
8.9 KiB
Go
package domain
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// NFLResultResponse represents the structure for NFL game results
|
|
type NFLResultResponse struct {
|
|
ID string `json:"id"`
|
|
SportID string `json:"sport_id"`
|
|
Time string `json:"time"`
|
|
TimeStatus string `json:"time_status"`
|
|
League struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
CC string `json:"cc"`
|
|
} `json:"league"`
|
|
Home struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
ImageID string `json:"image_id"`
|
|
CC string `json:"cc"`
|
|
} `json:"home"`
|
|
Away struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
ImageID string `json:"image_id"`
|
|
CC string `json:"cc"`
|
|
} `json:"away"`
|
|
SS string `json:"ss"`
|
|
Scores struct {
|
|
FirstQuarter Score `json:"1"`
|
|
SecondQuarter Score `json:"2"`
|
|
ThirdQuarter Score `json:"3"`
|
|
FourthQuarter Score `json:"4"`
|
|
Overtime Score `json:"5"`
|
|
TotalScore Score `json:"7"`
|
|
} `json:"scores"`
|
|
Stats struct {
|
|
FirstDowns []string `json:"first_downs"`
|
|
TotalYards []string `json:"total_yards"`
|
|
PassingYards []string `json:"passing_yards"`
|
|
RushingYards []string `json:"rushing_yards"`
|
|
Turnovers []string `json:"turnovers"`
|
|
TimeOfPossession []string `json:"time_of_possession"`
|
|
ThirdDownEfficiency []string `json:"third_down_efficiency"`
|
|
FourthDownEfficiency []string `json:"fourth_down_efficiency"`
|
|
} `json:"stats"`
|
|
Extra struct {
|
|
HomePos string `json:"home_pos"`
|
|
AwayPos string `json:"away_pos"`
|
|
StadiumData map[string]string `json:"stadium_data"`
|
|
Round string `json:"round"`
|
|
} `json:"extra"`
|
|
Events []map[string]string `json:"events"`
|
|
HasLineup int `json:"has_lineup"`
|
|
ConfirmedAt string `json:"confirmed_at"`
|
|
Bet365ID string `json:"bet365_id"`
|
|
}
|
|
|
|
// RugbyResultResponse represents the structure for Rugby game results
|
|
type RugbyResultResponse struct {
|
|
ID string `json:"id"`
|
|
SportID string `json:"sport_id"`
|
|
Time string `json:"time"`
|
|
TimeStatus string `json:"time_status"`
|
|
League struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
CC string `json:"cc"`
|
|
} `json:"league"`
|
|
Home struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
ImageID string `json:"image_id"`
|
|
CC string `json:"cc"`
|
|
} `json:"home"`
|
|
Away struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
ImageID string `json:"image_id"`
|
|
CC string `json:"cc"`
|
|
} `json:"away"`
|
|
SS string `json:"ss"`
|
|
Scores struct {
|
|
FirstHalf Score `json:"1"`
|
|
SecondHalf Score `json:"2"`
|
|
TotalScore Score `json:"7"`
|
|
} `json:"scores"`
|
|
Stats struct {
|
|
Tries []string `json:"tries"`
|
|
Conversions []string `json:"conversions"`
|
|
Penalties []string `json:"penalties"`
|
|
DropGoals []string `json:"drop_goals"`
|
|
Possession []string `json:"possession"`
|
|
Territory []string `json:"territory"`
|
|
Lineouts []string `json:"lineouts"`
|
|
Scrums []string `json:"scrums"`
|
|
PenaltiesConceded []string `json:"penalties_conceded"`
|
|
} `json:"stats"`
|
|
Extra struct {
|
|
HomePos string `json:"home_pos"`
|
|
AwayPos string `json:"away_pos"`
|
|
StadiumData map[string]string `json:"stadium_data"`
|
|
Round string `json:"round"`
|
|
} `json:"extra"`
|
|
Events []map[string]string `json:"events"`
|
|
HasLineup int `json:"has_lineup"`
|
|
ConfirmedAt string `json:"confirmed_at"`
|
|
Bet365ID string `json:"bet365_id"`
|
|
}
|
|
|
|
// BaseballResultResponse represents the structure for Baseball game results
|
|
type BaseballResultResponse struct {
|
|
ID string `json:"id"`
|
|
SportID string `json:"sport_id"`
|
|
Time string `json:"time"`
|
|
TimeStatus string `json:"time_status"`
|
|
League struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
CC string `json:"cc"`
|
|
} `json:"league"`
|
|
Home struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
ImageID string `json:"image_id"`
|
|
CC string `json:"cc"`
|
|
} `json:"home"`
|
|
Away struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
ImageID string `json:"image_id"`
|
|
CC string `json:"cc"`
|
|
} `json:"away"`
|
|
SS string `json:"ss"`
|
|
Scores struct {
|
|
FirstInning Score `json:"1"`
|
|
SecondInning Score `json:"2"`
|
|
ThirdInning Score `json:"3"`
|
|
FourthInning Score `json:"4"`
|
|
FifthInning Score `json:"5"`
|
|
SixthInning Score `json:"6"`
|
|
SeventhInning Score `json:"7"`
|
|
EighthInning Score `json:"8"`
|
|
NinthInning Score `json:"9"`
|
|
ExtraInnings Score `json:"10"`
|
|
TotalScore Score `json:"7"`
|
|
} `json:"scores"`
|
|
Stats struct {
|
|
Hits []string `json:"hits"`
|
|
Errors []string `json:"errors"`
|
|
LeftOnBase []string `json:"left_on_base"`
|
|
Strikeouts []string `json:"strikeouts"`
|
|
Walks []string `json:"walks"`
|
|
HomeRuns []string `json:"home_runs"`
|
|
TotalBases []string `json:"total_bases"`
|
|
BattingAverage []string `json:"batting_average"`
|
|
} `json:"stats"`
|
|
Extra struct {
|
|
HomePos string `json:"home_pos"`
|
|
AwayPos string `json:"away_pos"`
|
|
StadiumData map[string]string `json:"stadium_data"`
|
|
Round string `json:"round"`
|
|
} `json:"extra"`
|
|
Events []map[string]string `json:"events"`
|
|
HasLineup int `json:"has_lineup"`
|
|
ConfirmedAt string `json:"confirmed_at"`
|
|
Bet365ID string `json:"bet365_id"`
|
|
}
|
|
|
|
// ParseNFLResult parses NFL result from raw JSON data
|
|
func ParseNFLResult(data json.RawMessage) (*NFLResultResponse, error) {
|
|
var result NFLResultResponse
|
|
if err := json.Unmarshal(data, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
// ParseRugbyResult parses Rugby result from raw JSON data
|
|
func ParseRugbyResult(data json.RawMessage) (*RugbyResultResponse, error) {
|
|
var result RugbyResultResponse
|
|
if err := json.Unmarshal(data, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
// ParseRugbyUnionResult parses Rugby Union result from raw JSON data
|
|
func ParseRugbyUnionResult(data json.RawMessage) (*RugbyResultResponse, error) {
|
|
return ParseRugbyResult(data)
|
|
}
|
|
|
|
// ParseRugbyLeagueResult parses Rugby League result from raw JSON data
|
|
func ParseRugbyLeagueResult(data json.RawMessage) (*RugbyResultResponse, error) {
|
|
return ParseRugbyResult(data)
|
|
}
|
|
|
|
// ParseBaseballResult parses Baseball result from raw JSON data
|
|
func ParseBaseballResult(data json.RawMessage) (*BaseballResultResponse, error) {
|
|
var result BaseballResultResponse
|
|
if err := json.Unmarshal(data, &result); err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
// GetNFLWinner determines the winner of an NFL game
|
|
func GetNFLWinner(result *NFLResultResponse) (string, error) {
|
|
homeScore, err := strconv.Atoi(result.Scores.TotalScore.Home)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
awayScore, err := strconv.Atoi(result.Scores.TotalScore.Away)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if homeScore > awayScore {
|
|
return result.Home.Name, nil
|
|
} else if awayScore > homeScore {
|
|
return result.Away.Name, nil
|
|
}
|
|
return "Draw", nil
|
|
}
|
|
|
|
// GetRugbyWinner determines the winner of a Rugby game
|
|
func GetRugbyWinner(result *RugbyResultResponse) (string, error) {
|
|
homeScore, err := strconv.Atoi(result.Scores.TotalScore.Home)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
awayScore, err := strconv.Atoi(result.Scores.TotalScore.Away)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if homeScore > awayScore {
|
|
return result.Home.Name, nil
|
|
} else if awayScore > homeScore {
|
|
return result.Away.Name, nil
|
|
}
|
|
return "Draw", nil
|
|
}
|
|
|
|
// GetBaseballWinner determines the winner of a Baseball game
|
|
func GetBaseballWinner(result *BaseballResultResponse) (string, error) {
|
|
homeScore, err := strconv.Atoi(result.Scores.TotalScore.Home)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
awayScore, err := strconv.Atoi(result.Scores.TotalScore.Away)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if homeScore > awayScore {
|
|
return result.Home.Name, nil
|
|
} else if awayScore > homeScore {
|
|
return result.Away.Name, nil
|
|
}
|
|
return "Draw", nil
|
|
}
|
|
|
|
// FormatNFLScore formats the NFL score in a readable format
|
|
func FormatNFLScore(result *NFLResultResponse) string {
|
|
return strings.Join([]string{
|
|
result.Home.Name + " " + result.Scores.TotalScore.Home,
|
|
result.Away.Name + " " + result.Scores.TotalScore.Away,
|
|
}, " - ")
|
|
}
|
|
|
|
// FormatRugbyScore formats the Rugby score in a readable format
|
|
func FormatRugbyScore(result *RugbyResultResponse) string {
|
|
return strings.Join([]string{
|
|
result.Home.Name + " " + result.Scores.TotalScore.Home,
|
|
result.Away.Name + " " + result.Scores.TotalScore.Away,
|
|
}, " - ")
|
|
}
|
|
|
|
// FormatBaseballScore formats the Baseball score in a readable format
|
|
func FormatBaseballScore(result *BaseballResultResponse) string {
|
|
return strings.Join([]string{
|
|
result.Home.Name + " " + result.Scores.TotalScore.Home,
|
|
result.Away.Name + " " + result.Scores.TotalScore.Away,
|
|
}, " - ")
|
|
}
|