services

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 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) AdjustStintsToFitRaceLength added in v0.21.0

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

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.

func (*RaceStrategy) CalculateLastLapTiming added in v0.21.0

func (s *RaceStrategy) CalculateLastLapTiming(
	info entities.RaceInfo,
	pitStrat *entities.PitStrat,
)

CalculateLastLapTiming calculates when the last lap will begin for this strategy and whether a safe lap should be recommended based on the timing margin. Safe lap is recommended if the last lap starts with >= 2/3 of lap time remaining.

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

func (*RaceStrategy) RecalculatePitLengthsForCarAndTrack added in v0.22.0

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

RecalculatePitLengthsForCarAndTrack updates all pit stop durations in all strategies based on the specific car and track combination. User-adjusted pit lengths (via StintAdjustmentType_PitLength) are preserved. After updating pit durations, it recalculates time losses/gains for save strategies.

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) ApplyStintAdjustment

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

func (*Stint) CalculatePitLength added in v0.22.0

func (s *Stint) CalculatePitLength(
	ctx context.Context,
	fuelRequired, energyRequired float64,
	changeTyres bool,
	info entities.RaceInfo,
) (int64, error)

CalculatePitLength calculates the pit stop duration for a stint. If car and track information is available in RaceInfo, it uses specific timings for that car/track combination. Otherwise, it falls back to average timings.

func (*Stint) CreateStint

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

func (*Stint) ExtendShortStints added in v0.21.0

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

ExtendShortStints extends stints to distribute missing laps across them.

func (*Stint) ShortenStints added in v0.21.0

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

func (*Stint) ShouldChangeTyres added in v0.22.0

func (s *Stint) ShouldChangeTyres(info entities.RaceInfo, stint *entities.Stint) bool

ShouldChangeTyres determines if tires should be changed for this stint based on tyre change frequency and stint characteristics.

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 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