public LeagueMemberInfoDTO MapToMemberInfoDTO(LeagueMemberEntity source, LeagueMemberInfoDTO target = null) { if (source == null) { return(null); } if (target == null) { target = new LeagueMemberInfoDTO(); } target.MemberId = source.MemberId; return(target); }
public LeagueMemberEntity MapToMemberEntity(LeagueMemberDataDTO source, LeagueMemberEntity target = null) { if (source == null) { return(null); } if (target == null) { target = GetMemberEntity(source); } target.DanLisaId = source.DanLisaId; target.DiscordId = source.DiscordId; target.Firstname = source.Firstname; target.IRacingId = source.IRacingId; target.Lastname = source.Lastname; return(target); }
public LeagueMemberDataDTO MapToMemberDataDTO(LeagueMemberEntity source, LeagueMemberDataDTO target = null) { if (source == null) { return(null); } if (target == null) { target = new LeagueMemberDataDTO(); } MapToMemberInfoDTO(source, target); target.DanLisaId = source.DanLisaId; target.DiscordId = source.DiscordId; target.Firstname = source.Firstname; target.IRacingId = source.IRacingId; target.Lastname = source.Lastname; target.MemberId = source.MemberId; return(target); }
public IncidentReviewEntity(LeagueMemberEntity author) : this() { //Author = author; }
/// <summary> /// Calculate statistic data based on the current data set. /// <para>Make sure either lazy-loading is enabled on the context or run <see cref="LoadRequiredDataAsync(LeagueDbContext, bool)"/> before execution.</para> /// </summary> /// <param name="dbContext">Database context from EntityFramework</param> public override void Calculate(LeagueDbContext dbContext) { // Fix penalty points sign foreach (var statistic in StatisticSets.OfType <ImportedStatisticSetEntity>()) { statistic.DriverStatistic.Where(x => x.PenaltyPoints < 0).ForEach(x => x.PenaltyPoints *= -1); } // Get all statistic rows and group them by member var seasonStatisticRows = StatisticSets.SelectMany(x => x.DriverStatistic).GroupBy(x => x.Member); List <DriverStatisticRowEntity> removeDriverStatisticRows = DriverStatistic.ToList(); foreach (var memberStatisticRows in seasonStatisticRows) { var member = memberStatisticRows.Key; DriverStatisticRowEntity driverStatRow; if (DriverStatistic.Any(x => x.Member == member)) { driverStatRow = DriverStatistic.SingleOrDefault(x => x.Member == member); driverStatRow.ResetStatistic(); removeDriverStatisticRows.Remove(driverStatRow); } else { driverStatRow = new DriverStatisticRowEntity() { Member = member }; DriverStatistic.Add(driverStatRow); } // Calculate accumulative statistics foreach (var statisticRow in memberStatisticRows) { driverStatRow.CompletedLaps += statisticRow.CompletedLaps; driverStatRow.DrivenKm += statisticRow.DrivenKm; driverStatRow.FastestLaps += statisticRow.FastestLaps; driverStatRow.Incidents += statisticRow.Incidents; driverStatRow.LeadingKm += statisticRow.LeadingKm; driverStatRow.LeadingLaps += statisticRow.LeadingLaps; driverStatRow.PenaltyPoints += statisticRow.PenaltyPoints; driverStatRow.Poles += statisticRow.Poles; driverStatRow.Races += statisticRow.Races; driverStatRow.RacesCompleted += statisticRow.RacesCompleted; driverStatRow.RacesInPoints += statisticRow.RacesInPoints; driverStatRow.Top10 += statisticRow.Top10; driverStatRow.Top15 += statisticRow.Top15; driverStatRow.Top20 += statisticRow.Top20; driverStatRow.Top25 += statisticRow.Top25; driverStatRow.Top3 += statisticRow.Top3; driverStatRow.Top5 += statisticRow.Top5; driverStatRow.Wins += statisticRow.Wins; driverStatRow.RacePoints += statisticRow.RacePoints; driverStatRow.TotalPoints += statisticRow.TotalPoints; driverStatRow.BonusPoints += statisticRow.BonusPoints; driverStatRow.HardChargerAwards += statisticRow.HardChargerAwards; driverStatRow.CleanestDriverAwards += statisticRow.CleanestDriverAwards; driverStatRow.Titles += statisticRow.Titles; } // Calculate min/max statistics driverStatRow.BestFinalPosition = memberStatisticRows.Min(x => x.BestFinalPosition); driverStatRow.BestFinishPosition = memberStatisticRows.Min(x => x.BestFinishPosition); driverStatRow.BestStartPosition = memberStatisticRows.Min(x => x.BestStartPosition); driverStatRow.WorstFinalPosition = memberStatisticRows.Max(x => x.WorstFinalPosition); driverStatRow.WorstFinishPosition = memberStatisticRows.Max(x => x.WorstFinishPosition); driverStatRow.WorstStartPosition = memberStatisticRows.Max(x => x.WorstStartPosition); // Calculate start/end statistics var firstResultRow = memberStatisticRows.OrderBy(x => x.FirstRaceDate).FirstOrDefault(); var lastResultRow = memberStatisticRows.OrderBy(x => x.LastRaceDate).LastOrDefault(); driverStatRow.FirstResult = firstResultRow.FirstResult; driverStatRow.LastResult = lastResultRow.LastResult; driverStatRow.FirstRace = firstResultRow.FirstRace; driverStatRow.FirstRaceDate = memberStatisticRows.Min(x => x.FirstRaceDate); driverStatRow.FirstRaceFinalPosition = firstResultRow.FirstRaceFinalPosition; driverStatRow.FirstRaceFinishPosition = firstResultRow.FirstRaceFinishPosition; driverStatRow.FirstRaceStartPosition = firstResultRow.FirstRaceStartPosition; driverStatRow.FirstSession = memberStatisticRows.Select(x => x.FirstSession).Where(x => x != null).OrderBy(x => x.Date).FirstOrDefault(); driverStatRow.FirstSessionDate = memberStatisticRows.Min(x => x.FirstSessionDate); driverStatRow.LastRace = lastResultRow.LastRace; driverStatRow.LastRaceDate = memberStatisticRows.Max(x => x.LastRaceDate); driverStatRow.LastRaceFinalPosition = lastResultRow.LastRaceFinalPosition; driverStatRow.LastRaceFinishPosition = lastResultRow.LastRaceFinishPosition; driverStatRow.LastRaceStartPosition = lastResultRow.LastRaceStartPosition; driverStatRow.LastSession = memberStatisticRows.Select(x => x.LastSession).Where(x => x != null).LastOrDefault(); driverStatRow.LastSessionDate = memberStatisticRows.Max(x => x.LastSessionDate); driverStatRow.StartIRating = firstResultRow.StartIRating; driverStatRow.EndIRating = lastResultRow.EndIRating; driverStatRow.StartSRating = firstResultRow.StartSRating; driverStatRow.EndSRating = lastResultRow.EndSRating; driverStatRow.CurrentSeasonPosition = lastResultRow.CurrentSeasonPosition; // Calculate average statistics driverStatRow.AvgFinalPosition = memberStatisticRows.WeightedAverage(x => x.AvgFinalPosition, x => x.Races); driverStatRow.AvgFinishPosition = memberStatisticRows.WeightedAverage(x => x.AvgFinishPosition, x => x.Races); driverStatRow.AvgIncidentsPerKm = (driverStatRow.Incidents / driverStatRow.DrivenKm).GetZeroWhenInvalid(); driverStatRow.AvgIncidentsPerLap = ((double)driverStatRow.Incidents / driverStatRow.CompletedLaps).GetZeroWhenInvalid(); driverStatRow.AvgIncidentsPerRace = ((double)driverStatRow.Incidents / driverStatRow.Races).GetZeroWhenInvalid(); driverStatRow.AvgIRating = memberStatisticRows.WeightedAverage(x => x.AvgIRating, x => x.Races); driverStatRow.AvgPenaltyPointsPerKm = (driverStatRow.PenaltyPoints / driverStatRow.DrivenKm).GetZeroWhenInvalid(); driverStatRow.AvgPenaltyPointsPerLap = ((double)driverStatRow.PenaltyPoints / driverStatRow.CompletedLaps).GetZeroWhenInvalid(); driverStatRow.AvgPenaltyPointsPerRace = ((double)driverStatRow.PenaltyPoints / driverStatRow.Races).GetZeroWhenInvalid(); driverStatRow.AvgPointsPerRace = ((double)driverStatRow.TotalPoints / driverStatRow.Races).GetZeroWhenInvalid(); driverStatRow.AvgSRating = memberStatisticRows.WeightedAverage(x => x.AvgSRating, x => x.Races); driverStatRow.AvgStartPosition = memberStatisticRows.WeightedAverage(x => x.AvgStartPosition, x => x.Races); } // Calculate current champ var seasonStatisticSets = StatisticSets.OfType <SeasonStatisticSetEntity>().Where(x => x.IsSeasonFinished); var importedStatisticSets = StatisticSets.OfType <ImportedStatisticSetEntity>(); var lastSeasonStatistic = seasonStatisticSets.OrderBy(x => x.Season.SeasonEnd).LastOrDefault(); var lastImportedStatistic = importedStatisticSets.OrderBy(x => x.LastDate).LastOrDefault(); if (lastSeasonStatistic?.Season.SeasonEnd >= lastImportedStatistic?.LastDate) { CurrentChamp = lastSeasonStatistic?.DriverStatistic?.SingleOrDefault(x => x.CurrentSeasonPosition == 1)?.Member; } else { CurrentChamp = lastImportedStatistic?.DriverStatistic?.SingleOrDefault(x => x.CurrentSeasonPosition == 1)?.Member; } DriverStatistic.Remove(removeDriverStatisticRows); }