services

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventPublisher

type EventPublisher interface {
	PublishSetupCreated(context.Context, postgresdb.Tx, entities.Setup) error
	PublishSetupUpdated(context.Context, postgresdb.Tx, entities.Setup) error
}

type Pitstop

type Pitstop struct {
	// contains filtered or unexported fields
}

func NewPitstop

func NewPitstop(
	pitParamsRepo repositories.PitParameters,
) *Pitstop

func (*Pitstop) AveragePitLength

func (p *Pitstop) AveragePitLength(ctx context.Context, pitDetails entities.PitstopDetails) (int64, error)

AveragePitLength calculates the averate pit length for the given pitDetails pit services, across all race classes, including pit lane drive loss on all tracks and layouts.

func (*Pitstop) CalculatePitLength

func (p *Pitstop) CalculatePitLength(
	ctx context.Context,
	raceClass entities.RaceClass,
	pitDetails entities.PitstopDetails,
	trackID uuid.UUID,
	layoutID *uuid.UUID,
) (int64, error)

type PitstopService

type PitstopService interface {
	CalculatePitLength(
		context.Context,
		entities.RaceClass,
		entities.PitstopDetails,
		uuid.UUID,
		*uuid.UUID,
	) (int64, error)
	AveragePitLength(context.Context, entities.PitstopDetails) (int64, error)
}

type RaceProgress

type RaceProgress struct {
	// contains filtered or unexported fields
}

func NewRaceProgress

func NewRaceProgress(
	stintSvc StintService,
) *RaceProgress

func (*RaceProgress) UpdateStrategyWithRaceProgress

func (p *RaceProgress) UpdateStrategyWithRaceProgress(
	ctx context.Context,
	strat *entities.SavedStrategy,
	progress *entities.RaceProgress,
)

type RaceStrategy

type RaceStrategy struct {
	// contains filtered or unexported fields
}

func NewRaceStrategy

func NewRaceStrategy(
	stratRepo repositories.Strategy,
	carRepo repositories.Car,
	trackRepo repositories.Track,
	trackLayoutRepo repositories.TrackLayout,
	stintSvc StintService,
) *RaceStrategy

func (*RaceStrategy) CalculateMaxTimeLoss

func (s *RaceStrategy) CalculateMaxTimeLoss(saveStrat, flatoutStrat *entities.PitStrat)

CalculateMaxTimeLoss that the driver is allowed to lose per lap when driving in fuel saving mode, to save enough fuel in the race to avoiding having to take a pit stop for the savedStint.

func (*RaceStrategy) DefaultTrackLayoutFallback

func (s *RaceStrategy) DefaultTrackLayoutFallback(ctx context.Context, info *entities.RaceInfo) error

func (*RaceStrategy) EnsurePitLength

func (s *RaceStrategy) EnsurePitLength(info *entities.RaceInfo)

func (*RaceStrategy) FetchStrategy

func (s *RaceStrategy) FetchStrategy(
	ctx context.Context,
	id, userID uuid.UUID,
	passphrase string,
) (*entities.SavedStrategy, error)

func (*RaceStrategy) FetchStrategyCarAndLocation

func (s *RaceStrategy) FetchStrategyCarAndLocation(
	ctx context.Context,
	strategyID uuid.UUID,
) (*entities.Car, *entities.Track, *entities.TrackLayout, error)

func (*RaceStrategy) GeneratePitStrategies

func (s *RaceStrategy) GeneratePitStrategies(
	ctx context.Context,
	strat *entities.RaceStrategy,
) error

type Setup

type Setup struct {
	// contains filtered or unexported fields
}

func NewSetup

func NewSetup(
	setupStore repositories.SetupStorage,
) *Setup

func (*Setup) CanUserUpdate

func (s *Setup) CanUserUpdate(setup *entities.Setup, user *entities.User) bool

func (*Setup) NormalizeForUpdate

func (s *Setup) NormalizeForUpdate(reqSetup, savedSetup *entities.Setup)

NormalizeForUpdate sets required fields to the previous values if the update request is not setting them.

func (*Setup) SetUser

func (s *Setup) SetUser(setup *entities.Setup, user *entities.User)

func (*Setup) ShouldUpdateFileContent

func (s *Setup) ShouldUpdateFileContent(setup *entities.Setup) bool

func (*Setup) StoreSetupFile

func (s *Setup) StoreSetupFile(ctx context.Context, setup *entities.Setup, opts ...postgresdb.ExecOption) error

type Stint

type Stint struct {
	// contains filtered or unexported fields
}

func NewStint

func NewStint(
	carRepo repositories.Car,
	pitstopSvc PitstopService,
) *Stint

func (*Stint) AdjustStintsToFitRaceLength

func (s *Stint) AdjustStintsToFitRaceLength(ctx context.Context, info entities.RaceInfo, strat *entities.PitStrat)

AdjustStintsToFitRaceLength after applying changes to stints from race progress or manual edits, we may need to adjust the rest so that they still fit the race length.

TODO: Adjusting stints to fit race length can lead to invalid adjustments, no matter how the race length is determined, if it is by race length or by laps of the race. If a subset of race laps are driven at a much slower pace, i.e. under FCY or SC, or a badly damaged car, then the driven laps at the end of the race will not be the same as when driving at normal pace, nor will the laps driven counted at race pace reach the same time. https://gitlab.com/bitval/go-lmu-setup-api/-/issues/73

func (*Stint) ApplyStintAdjustment

func (s *Stint) ApplyStintAdjustment(
	ctx context.Context,
	strat *entities.SavedStrategy,
	stintAdj *entities.StintAdjustment,
) error

func (*Stint) CreateStint

func (s *Stint) CreateStint(
	ctx context.Context,
	stintLaps, saveLaps float64,
	info entities.RaceInfo,
	stintNo uint,
) entities.Stint

func (*Stint) UpdateCompleteLaps

func (s *Stint) UpdateCompleteLaps(
	ctx context.Context,
	strat *entities.SavedStrategy,
	stint *entities.Stint,
	lapsComplete, maxStintLaps float64,
) float64

UpdateCompleteLaps updates the stints with the number of complete laps and adjusts its length based on the remaining fuel/energy in the tank, as well as adjusting the fuel/energy target consumption.

type StintService

type StintService interface {
	UpdateCompleteLaps(context.Context, *entities.SavedStrategy, *entities.Stint, float64, float64) float64
	AdjustStintsToFitRaceLength(context.Context, entities.RaceInfo, *entities.PitStrat)
	CreateStint(context.Context, float64, float64, entities.RaceInfo, uint) entities.Stint
	ApplyStintAdjustment(context.Context, *entities.SavedStrategy, *entities.StintAdjustment) error
}

type Track

type Track struct {
	// contains filtered or unexported fields
}

func NewTrack

func NewTrack(trackLayoutRepo repositories.TrackLayout) *Track

func (*Track) GetDefaultTrackLayout

func (t *Track) GetDefaultTrackLayout(ctx context.Context, trackID, layoutID *uuid.UUID) (*uuid.UUID, error)

func (*Track) LayoutMatchesTrack

func (t *Track) LayoutMatchesTrack(ctx context.Context, trackID, layoutID *uuid.UUID) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL