Skip to content

Commit

Permalink
[B] Fix sorting of result rows and sessions when fetching from db
Browse files Browse the repository at this point in the history
  • Loading branch information
SSchulze1989 committed Jan 9, 2025
1 parent 17f4fd9 commit 0a9b9c9
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 234 deletions.
260 changes: 133 additions & 127 deletions src/iRLeagueApiCore.Server/Handlers/Results/ResultHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,141 +136,147 @@ protected static RawResultRowModel MapToModResultRowModel(RawResultRowModel mode
TrackName = result.Event.Track.TrackGroup.TrackName,
ConfigName = result.Event.Track.ConfigName,
StrengthOfField = result.Event.SimSessionDetails.Any() ? result.Event.SimSessionDetails.First().EventStrengthOfField : 0,
SessionResults = result.ScoredSessionResults.Select(sessionResult => new ResultModel()
{
LeagueId = sessionResult.LeagueId,
ScoringId = sessionResult.ScoringId,
SessionResultId = sessionResult.SessionResultId,
SessionName = sessionResult.Name,
SessionNr = sessionResult.SessionNr,
ResultRows = sessionResult.ScoredResultRows
.OrderBy(x => x.FinalPosition)
.Select(row => new ResultRowModel()
SessionResults = result.ScoredSessionResults
.OrderBy(sessionResult => sessionResult.SessionNr)
.Select(sessionResult => new ResultModel()
{
ScoredResultRowId = row.ScoredResultRowId,
MemberId = row.MemberId,
Interval = new Interval(row.Interval),
FastestLapTime = row.FastestLapTime,
AvgLapTime = row.AvgLapTime,
Firstname = (row.Member != null) ? row.Member.Firstname : string.Empty,
Lastname = (row.Member != null) ? row.Member.Lastname : string.Empty,
TeamName = (row.Team != null) ? row.Team.Name : string.Empty,
StartPosition = row.StartPosition,
FinishPosition = row.FinishPosition,
FinalPosition = row.FinalPosition,
RacePoints = row.RacePoints,
PenaltyPoints = row.PenaltyPoints,
BonusPoints = row.BonusPoints,
TotalPoints = row.TotalPoints,
Car = row.Car,
CarClass = row.CarClass,
CarId = row.CarId,
CarNumber = row.CarNumber,
ClassId = row.ClassId,
ClubId = row.ClubId,
ClubName = row.ClubName,
CompletedLaps = row.CompletedLaps,
CompletedPct = row.CompletedPct,
Division = row.Division,
FastLapNr = row.FastLapNr,
FinalPositionChange = row.FinalPositionChange,
Incidents = row.Incidents,
LeadLaps = row.LeadLaps,
License = row.License,
NewIrating = row.NewIRating,
NewLicenseLevel = row.NewLicenseLevel,
NewSafetyRating = row.NewSafetyRating,
OldIrating = row.OldIRating,
OldLicenseLevel = row.OldLicenseLevel,
OldSafetyRating = row.OldSafetyRating,
PositionChange = row.PositionChange,
QualifyingTime = row.QualifyingTime,
SeasonStartIrating = row.SeasonStartIRating,
Status = (RaceStatus)row.Status,
TeamId = row.TeamId,
TeamColor = (row.Team != null) ? row.Team.TeamColor : string.Empty,
PenaltyTime = row.PenaltyTime,
PenaltyPositions = row.PenaltyPositions,
LeagueId = sessionResult.LeagueId,
ScoringId = sessionResult.ScoringId,
SessionResultId = sessionResult.SessionResultId,
SessionName = sessionResult.Name,
SessionNr = sessionResult.SessionNr,
ResultRows = sessionResult.ScoredResultRows
.OrderBy(x => x.FinalPosition)
.Select(row => new ResultRowModel()
{
ScoredResultRowId = row.ScoredResultRowId,
MemberId = row.MemberId,
Interval = new Interval(row.Interval),
FastestLapTime = row.FastestLapTime,
AvgLapTime = row.AvgLapTime,
Firstname = (row.Member != null) ? row.Member.Firstname : string.Empty,
Lastname = (row.Member != null) ? row.Member.Lastname : string.Empty,
TeamName = (row.Team != null) ? row.Team.Name : string.Empty,
StartPosition = row.StartPosition,
FinishPosition = row.FinishPosition,
FinalPosition = row.FinalPosition,
RacePoints = row.RacePoints,
PenaltyPoints = row.PenaltyPoints,
BonusPoints = row.BonusPoints,
TotalPoints = row.TotalPoints,
Car = row.Car,
CarClass = row.CarClass,
CarId = row.CarId,
CarNumber = row.CarNumber,
ClassId = row.ClassId,
ClubId = row.ClubId,
ClubName = row.ClubName,
CompletedLaps = row.CompletedLaps,
CompletedPct = row.CompletedPct,
Division = row.Division,
FastLapNr = row.FastLapNr,
FinalPositionChange = row.FinalPositionChange,
Incidents = row.Incidents,
LeadLaps = row.LeadLaps,
License = row.License,
NewIrating = row.NewIRating,
NewLicenseLevel = row.NewLicenseLevel,
NewSafetyRating = row.NewSafetyRating,
OldIrating = row.OldIRating,
OldLicenseLevel = row.OldLicenseLevel,
OldSafetyRating = row.OldSafetyRating,
PositionChange = row.PositionChange,
QualifyingTime = row.QualifyingTime,
SeasonStartIrating = row.SeasonStartIRating,
Status = (RaceStatus)row.Status,
TeamId = row.TeamId,
TeamColor = (row.Team != null) ? row.Team.TeamColor : string.Empty,
PenaltyTime = row.PenaltyTime,
PenaltyPositions = row.PenaltyPositions,
}),
FastestLapTime = sessionResult.FastestLap,
FastestLapDriver = sessionResult.FastestLapDriver == null ? null : new()
{
FirstName = sessionResult.FastestLapDriver.Firstname,
LastName = sessionResult.FastestLapDriver.Lastname,
MemberId = sessionResult.FastestLapDriver.Id,
},
PoleLapTime = sessionResult.FastestQualyLap,
PoleLapDriver = sessionResult.FastestQualyLapDriver == null ? null : new()
{
FirstName = sessionResult.FastestQualyLapDriver.Firstname,
LastName = sessionResult.FastestQualyLapDriver.Lastname,
MemberId = sessionResult.FastestQualyLapDriver.Id,
},
CleanestDrivers = sessionResult.CleanestDrivers.Select(member => new MemberInfoModel()
{
FirstName = member.Firstname,
LastName = member.Lastname,
MemberId = member.Id,
}).ToList(),
CreatedOn = TreatAsUTCDateTime(sessionResult.CreatedOn),
LastModifiedOn = TreatAsUTCDateTime(sessionResult.LastModifiedOn),
}),
FastestLapTime = sessionResult.FastestLap,
FastestLapDriver = sessionResult.FastestLapDriver == null ? null : new()
{
FirstName = sessionResult.FastestLapDriver.Firstname,
LastName = sessionResult.FastestLapDriver.Lastname,
MemberId = sessionResult.FastestLapDriver.Id,
},
PoleLapTime = sessionResult.FastestQualyLap,
PoleLapDriver = sessionResult.FastestQualyLapDriver == null ? null : new()
{
FirstName = sessionResult.FastestQualyLapDriver.Firstname,
LastName = sessionResult.FastestQualyLapDriver.Lastname,
MemberId = sessionResult.FastestQualyLapDriver.Id,
},
CleanestDrivers = sessionResult.CleanestDrivers.Select(member => new MemberInfoModel()
{
FirstName = member.Firstname,
LastName = member.Lastname,
MemberId = member.Id,
}).ToList(),
CreatedOn = TreatAsUTCDateTime(sessionResult.CreatedOn),
LastModifiedOn = TreatAsUTCDateTime(sessionResult.LastModifiedOn),
}),
};

protected static Expression<Func<EventResultEntity, RawEventResultModel>> MapToRawEventResultModelExpression => result => new()
{
EventId = result.EventId,
SessionResults = result.SessionResults.Select(sessionResult => new RawSessionResultModel()
{
SessionId = sessionResult.SessionId,
ResultRows = sessionResult.ResultRows.Select(row => new RawResultRowModel()
SessionResults = result.SessionResults
.OrderBy(sessionResult => sessionResult.Session.SessionNr)
.Select(sessionResult => new RawSessionResultModel()
{
ResultRowId = row.ResultRowId,
MemberId = row.MemberId,
StartPosition = row.StartPosition,
FinishPosition = row.FinishPosition,
CarNumber = row.CarNumber,
ClassId = row.ClassId,
Car = row.Car,
CarClass = row.CarClass,
CompletedLaps = row.CompletedLaps,
LeadLaps = row.LeadLaps,
FastLapNr = row.FastLapNr,
Incidents = row.Incidents,
Status = row.Status,
QualifyingTime = row.QualifyingTime,
Interval = row.Interval,
AvgLapTime = row.AvgLapTime,
FastestLapTime = row.FastestLapTime,
PositionChange = row.PositionChange,
IRacingId = row.IRacingId,
SimSessionType = row.SimSessionType,
OldIRating = row.OldIRating,
NewIRating = row.NewIRating,
SeasonStartIRating = row.SeasonStartIRating,
License = row.License,
OldSafetyRating = row.OldSafetyRating,
NewSafetyRating = row.NewSafetyRating,
OldCpi = row.OldCpi,
NewCpi = row.NewCpi,
ClubId = row.ClubId,
ClubName = row.ClubName,
CarId = row.CarId,
CompletedPct = row.CompletedPct,
QualifyingTimeAt = row.QualifyingTimeAt,
Division = row.Division,
OldLicenseLevel = row.OldLicenseLevel,
NewLicenseLevel = row.NewLicenseLevel,
NumPitStops = row.NumPitStops,
PittedLaps = row.PittedLaps,
NumOfftrackLaps = row.NumOfftrackLaps,
OfftrackLaps = row.OfftrackLaps,
NumContactLaps = row.NumContactLaps,
ContactLaps = row.ContactLaps,
RacePoints = row.RacePoints,
TeamId = row.TeamId,
PointsEligible = row.PointsEligible,
SessionId = sessionResult.SessionId,
ResultRows = sessionResult.ResultRows
.OrderBy(row => row.FinishPosition)
.Select(row => new RawResultRowModel()
{
ResultRowId = row.ResultRowId,
MemberId = row.MemberId,
StartPosition = row.StartPosition,
FinishPosition = row.FinishPosition,
CarNumber = row.CarNumber,
ClassId = row.ClassId,
Car = row.Car,
CarClass = row.CarClass,
CompletedLaps = row.CompletedLaps,
LeadLaps = row.LeadLaps,
FastLapNr = row.FastLapNr,
Incidents = row.Incidents,
Status = row.Status,
QualifyingTime = row.QualifyingTime,
Interval = row.Interval,
AvgLapTime = row.AvgLapTime,
FastestLapTime = row.FastestLapTime,
PositionChange = row.PositionChange,
IRacingId = row.IRacingId,
SimSessionType = row.SimSessionType,
OldIRating = row.OldIRating,
NewIRating = row.NewIRating,
SeasonStartIRating = row.SeasonStartIRating,
License = row.License,
OldSafetyRating = row.OldSafetyRating,
NewSafetyRating = row.NewSafetyRating,
OldCpi = row.OldCpi,
NewCpi = row.NewCpi,
ClubId = row.ClubId,
ClubName = row.ClubName,
CarId = row.CarId,
CompletedPct = row.CompletedPct,
QualifyingTimeAt = row.QualifyingTimeAt,
Division = row.Division,
OldLicenseLevel = row.OldLicenseLevel,
NewLicenseLevel = row.NewLicenseLevel,
NumPitStops = row.NumPitStops,
PittedLaps = row.PittedLaps,
NumOfftrackLaps = row.NumOfftrackLaps,
OfftrackLaps = row.OfftrackLaps,
NumContactLaps = row.NumContactLaps,
ContactLaps = row.ContactLaps,
RacePoints = row.RacePoints,
TeamId = row.TeamId,
PointsEligible = row.PointsEligible,
}).ToList(),
}).ToList(),
}).ToList(),
};
}
Loading

0 comments on commit 0a9b9c9

Please sign in to comment.