Skip to content

Commit

Permalink
Merge pull request #8 from tfreder1ck/sort-by
Browse files Browse the repository at this point in the history
Added sort by option for H2H tables
  • Loading branch information
dos-2 authored Dec 28, 2024
2 parents ee34f33 + 774b612 commit ddc5b7a
Show file tree
Hide file tree
Showing 33 changed files with 457 additions and 106 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ go.work
.env

*.DS_Store

#logs
output.txt
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ package main

import (
"log"
"os"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/ui"
)

func main() {

if len(os.Args) > 1 {
for _, arg := range os.Args[1:] {
switch arg {
case "debug":
models.SetDebug(true)
}
}
}

if err := ui.RunApp(); err != nil {
log.Fatalf("Failed to run application: %v", err)
}
Expand Down
64 changes: 64 additions & 0 deletions models/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2024 dos-2
* All rights reserved.
*/
package models

import (
"fmt"
"time"
)

var loadedEvents = make(map[string][]Event)

func AddLoadedEvent(key string, value []Event) {
tempMap := loadedEvents
tempMap[key] = value
loadedEvents = tempMap
}

func GetLoadedEvents(key string) []Event {
return loadedEvents[key]
}

var currentPage = ""

func SetCurrentPage(page string) {
currentPage = page
}

func GetCurrentPage() string {
return currentPage
}

var currentPageIndex = ""

func SetCurrentPageIndex(index string) {
currentPageIndex = index
}

func GetCurrentPageIndex() string {
return currentPageIndex
}

var debug = false

func SetDebug(option bool) {
debug = option
}

func GetDebug() bool {
return debug
}

func LoadEvent(sport string, games []Event) {
debug := GetDebug()

if len(GetLoadedEvents(sport)) == 0 {
if debug {
fmt.Printf("[%s] Add loaded events for %s", time.Now(), sport)
fmt.Println()
}
AddLoadedEvent(sport, games)
}
}
9 changes: 6 additions & 3 deletions slides/boxing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

// Boxing creates a slide for boxing odds.
func Boxing(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
func Boxing(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
var builder strings.Builder
builder.WriteString("Commencement Date|Ranking|Players|Bookmaker|Spread|Money|Total\n")
headerString := "Commencement Date|Ranking|Players|Bookmaker|Spread –|Money –|Total –\n"

models.LoadEvent(string(sports.Boxing), games)

for _, game := range games {
builder.WriteString(FormatTeamEvent(game))
}

return "Boxing", GetHeader(models.Boxing), CreateH2HTable("Boxing", builder.String())
return "Boxing", GetHeader(models.Boxing), CreateH2HTable(pages, "Boxing", headerString, games)
}
9 changes: 6 additions & 3 deletions slides/brazil_campeonato_soccer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

func BrazilCampeonato(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
func BrazilCampeonato(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
var builder strings.Builder
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"

models.LoadEvent(string(sports.Soccer_brazil_campeonato), games)

for _, game := range games {
builder.WriteString(FormatTeamEvent(game))
}

return "Brazil Campeonato", GetHeader(models.Soccer_brazil_campeonato), CreateH2HTable(string(models.Soccer_brazil_campeonato), builder.String())
return "Brazil Campeonato", GetHeader(models.Soccer_brazil_campeonato), CreateH2HTable(pages, string(models.Soccer_brazil_campeonato), headerString, games)
}
9 changes: 6 additions & 3 deletions slides/copa_america_soccer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

func CopaAmericaSoccer(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
func CopaAmericaSoccer(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
var builder strings.Builder
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"

models.LoadEvent(string(sports.Soccer_conmebol_copa_america), games)

for _, game := range games {
builder.WriteString(FormatTeamEvent(game))
}

return "Copa America", GetHeader(models.Soccer_conmebol_copa_america), CreateH2HTable(string(models.Soccer_conmebol_copa_america), builder.String())
return "Copa America", GetHeader(models.Soccer_conmebol_copa_america), CreateH2HTable(pages, string(models.Soccer_conmebol_copa_america), headerString, games)
}
7 changes: 2 additions & 5 deletions slides/cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
)

// Cover returns the cover page.
func Cover(games []models.Event, nextSlide func()) (title string, header string, content tview.Primitive) {
func Cover(pages *tview.Pages, games []models.Event) (title string, header string, content tview.Primitive) {
// What's the size of the logo?
lines := strings.Split(logo, "\n")
logoWidth := 0
Expand All @@ -44,10 +44,7 @@ func Cover(games []models.Event, nextSlide func()) (title string, header string,
}
}
logoBox := tview.NewTextView().
SetTextColor(tcell.NewRGBColor(57, 255, 20)).
SetDoneFunc(func(key tcell.Key) {
nextSlide()
})
SetTextColor(tcell.NewRGBColor(57, 255, 20))
fmt.Fprint(logoBox, logo)

// Create a frame for the subtitle and navigation infos.
Expand Down
9 changes: 6 additions & 3 deletions slides/epl_soccer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

func EPLSoccer(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
func EPLSoccer(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
var builder strings.Builder
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"

models.LoadEvent(string(sports.Soccer_epl), games)

for _, game := range games {
builder.WriteString(FormatTeamEvent(game))
}

return "EPL Soccer", GetHeader(models.Soccer_epl), CreateH2HTable(string(models.Soccer_epl), builder.String())
return "EPL Soccer", GetHeader(models.Soccer_epl), CreateH2HTable(pages, string(models.Soccer_epl), headerString, games)
}
9 changes: 6 additions & 3 deletions slides/ipl_cricket.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

// IPLCricket creates a slide for IPL cricket odds.
func IPLCricket(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
func IPLCricket(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
var builder strings.Builder
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"

models.LoadEvent(string(sports.Cricket_ipl), games)

for _, game := range games {
builder.WriteString(FormatTeamEvent(game))
}

return "IPL", GetHeader(models.Cricket_ipl), CreateH2HTable(string(models.Cricket_ipl), builder.String())
return "IPL", GetHeader(models.Cricket_ipl), CreateH2HTable(pages, string(models.Cricket_ipl), headerString, games)
}
14 changes: 5 additions & 9 deletions slides/la_liga_soccer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
package slides

import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

// LaLigaSoccer creates a slide for La Liga soccer odds.
func LaLigaSoccer(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
var builder strings.Builder
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
func LaLigaSoccer(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"

for _, game := range games {
builder.WriteString(FormatTeamEvent(game))
}
models.LoadEvent(string(sports.Soccer_spain_la_liga), games)

return "La Liga", GetHeader(models.Soccer_spain_la_liga), CreateH2HTable(string(models.Soccer_spain_la_liga), builder.String())
return "La Liga", GetHeader(models.Soccer_spain_la_liga), CreateH2HTable(pages, string(models.Soccer_spain_la_liga), headerString, games)
}
14 changes: 5 additions & 9 deletions slides/masters_golf.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
package slides

import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

// MastersGolf creates a slide for golf odds.
func MastersGolf(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
var builder strings.Builder
builder.WriteString("Commencement Date|Teams|Players|Bookmaker|Outrights||\n")
func MastersGolf(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
headerString := "Commencement Date|Teams|Players|Bookmaker|Outrights||\n"

if len(games) > 0 {
builder.WriteString(FormatTournamentEvent(games[0]))
}
models.LoadEvent(string(sports.Golf_masters_tournament_winner), games)

return "Masters", GetHeader(models.Golf_masters_tournament_winner), CreateRoundRobinTable(string(models.Golf_masters_tournament_winner), builder.String())
return "Masters", GetHeader(models.Golf_masters_tournament_winner), CreateRoundRobinTable(string(models.Golf_masters_tournament_winner), headerString, games)
}
9 changes: 6 additions & 3 deletions slides/mens_french_open_tennis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

// FrenchOpenTennis creates a slide for tennis odds.
func MensFrenchOpenTennis(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
func MensFrenchOpenTennis(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
var builder strings.Builder
builder.WriteString("Commencement Date|Location|Players|Bookmaker|Spread|Money|Total\n")
headerString := "Commencement Date|Location|Players|Bookmaker|Spread –|Money –|Total –\n"

models.LoadEvent(string(sports.Tennis_atp_french_open), games)

for _, game := range games {
builder.WriteString(FormatTeamEvent(game))
}

return "Mens French Open", GetHeader(models.Tennis_atp_french_open), CreateH2HTable("Mens French Open Tennis", builder.String())
return "Mens French Open", GetHeader(models.Tennis_atp_french_open), CreateH2HTable(pages, "Mens French Open Tennis", headerString, games)
}
9 changes: 6 additions & 3 deletions slides/mens_wimbledon_tennis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

func MensWimbledonTennis(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
func MensWimbledonTennis(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
var builder strings.Builder
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"

models.LoadEvent(string(sports.Tennis_atp_wimbledon), games)

for _, game := range games {
builder.WriteString(FormatTeamEvent(game))
}

return "Wimbledon", GetHeader(models.Tennis_atp_wimbledon), CreateH2HTable(string(models.Tennis_atp_wimbledon), builder.String())
return "Wimbledon", GetHeader(models.Tennis_atp_wimbledon), CreateH2HTable(pages, string(models.Tennis_atp_wimbledon), headerString, games)
}
9 changes: 6 additions & 3 deletions slides/mlb_baseball.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

// MLBBaseball creates a slide for baseball odds.
func MLBBaseball(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
func MLBBaseball(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
var tableData strings.Builder
tableData.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"

models.LoadEvent(string(sports.Baseball_mlb), games)

for _, game := range games {
tableData.WriteString(FormatTeamEvent(game))
}

return "MLB", GetHeader(models.Baseball_mlb), CreateH2HTable("MLB Baseball", tableData.String())
return "MLB", GetHeader(models.Baseball_mlb), CreateH2HTable(pages, "MLB Baseball", headerString, games)
}
9 changes: 6 additions & 3 deletions slides/mls_soccer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import (
"strings"

"github.com/dos-2/oddshub/models"
"github.com/dos-2/oddshub/sports"

"github.com/rivo/tview"
)

// MLSSoccer creates a slide for soccer odds.
func MLSSoccer(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
func MLSSoccer(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
var tableData strings.Builder
tableData.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"

models.LoadEvent(string(sports.Soccer_usa_mls), games)

for _, game := range games {
tableData.WriteString(FormatTeamEvent(game))
}

return "MLS", GetHeader(models.Soccer_usa_mls), CreateH2HTable("MLS Soccer", tableData.String())
return "MLS", GetHeader(models.Soccer_usa_mls), CreateH2HTable(pages, "MLS Soccer", headerString, games)
}
Loading

0 comments on commit ddc5b7a

Please sign in to comment.