internal static async Task <RaceTranspondersReport> LoadAsync(ICompetitionContext context, Guid competitionId, Guid distanceId, OptionalReportColumns optionalColumns) { var report = new RaceTranspondersReport(); var distance = await context.Distances.Include(d => d.Competition.Venue).Include(d => d.Competition.ReportTemplate.Logos).FirstOrDefaultAsync(d => d.Id == distanceId); if (distance == null) { throw new DistanceNotFoundException(); } report.SetParameters(distance); var races = await context.Races.Include(r => r.Competitor).Include(r => r.Transponders).Where(r => r.DistanceId == distanceId).ToListAsync(); await(context.TeamCompetitorMembers .Include(tcm => tcm.Member) .Where(tcm => tcm.Team.DistanceCombinations.Any(dc => dc.DistanceCombination.Distances.Any(d => d.Id == distanceId)))) .LoadAsync(); var maxPair = races.Select(r => r.Heat).DefaultIfEmpty(0).Max(); var pairs = new List <Pair>(); for (var pair = distance.FirstHeat; pair <= maxPair; pair++) { var colors = PairsDistanceCalculator.Colors(distance, pair); var innerRace = races.SingleOrDefault(r => r.Heat == pair && r.Lane == 0); var innerRaceColor = (int)colors.ToLaneColor(Lane.Inner); var outerRace = races.SingleOrDefault(r => r.Heat == pair && r.Lane == 1); var outerRaceColor = (int)colors.ToLaneColor(Lane.Outer); pairs.Add(new Pair(pair, innerRace, innerRaceColor, null, outerRace, outerRaceColor, null)); } report.Pairs = pairs; return(report); }
internal static async Task <DetailedResultReport> LoadAsync(RacesWorkflow workflow, Guid competitionId, Guid distanceId, IDistanceDisciplineExpertManager expertManager, OptionalReportColumns optionalColumns) { var distance = await workflow.Distances.Include(d => d.Competition.Venue).Include(d => d.Competition.ReportTemplate.Logos).FirstOrDefaultAsync(d => d.Id == distanceId); if (distance == null) { throw new DistanceNotFoundException(); } var expert = expertManager.Find(distance.Discipline); if (expert == null) { return(null); } var report = new DetailedResultReport(); report.SetParameters(distance); report.ReportParameters["OptionalColumnHeader"].Value = Resources.ResourceManager.GetString($"OptionalColumn_{(int)optionalColumns}") ?? ""; switch (optionalColumns) { case OptionalReportColumns.HomeVenueCode: report.ReportParameters["InnerOptionalColumnField"].Value = "Inner.Competitor.VenueCode"; report.ReportParameters["OuterOptionalColumnField"].Value = "Outer.Competitor.VenueCode"; break; case OptionalReportColumns.NationalityCode: report.ReportParameters["InnerOptionalColumnField"].Value = "Inner.Competitor.NationalityCode"; report.ReportParameters["OuterOptionalColumnField"].Value = "Outer.Competitor.NationalityCode"; break; case OptionalReportColumns.ClubShortName: report.ReportParameters["InnerOptionalColumnField"].Value = "Inner.Competitor.ClubShortName"; report.ReportParameters["OuterOptionalColumnField"].Value = "Outer.Competitor.ClubShortName"; break; case OptionalReportColumns.LicenseKey: report.ReportParameters["InnerOptionalColumnField"].Value = "Inner.Competitor.LicenseKey"; report.ReportParameters["OuterOptionalColumnField"].Value = "Outer.Competitor.LicenseKey"; break; default: report.InnerOptionalFieldTextBox.Value = null; report.OuterOptionalFieldTextBox.Value = null; break; } var races = await workflow.Races(competitionId).Include(r => r.Competitor) .Include(r => r.Results) .Include(r => r.Times) .Include(r => r.Laps) .Where(r => r.DistanceId == distanceId) .ToListAsync(); races = races.Where(r => r.PresentedResult?.Status == RaceStatus.Done).ToList(); var maxPair = races.Select(r => r.Heat).DefaultIfEmpty(0).Max(); var pairs = new List <Pair>(); for (var pair = distance.FirstHeat; pair <= maxPair; pair++) { var colors = PairsDistanceCalculator.Colors(distance, pair); var innerRace = races.SingleOrDefault(r => r.Heat == pair && r.Lane == 0); var innerRaceColor = (int)colors.ToLaneColor(Lane.Inner); var innerLaps = innerRace != null?expert.Calculator.CalculateLaps(distance, innerRace.PresentedLaps.Select(t => t?.Time)) : null; var outerRace = races.SingleOrDefault(r => r.Heat == pair && r.Lane == 1); var outerRaceColor = (int)colors.ToLaneColor(Lane.Outer); var outerLaps = outerRace != null?expert.Calculator.CalculateLaps(distance, outerRace.PresentedLaps.Select(t => t?.Time)) : null; pairs.Add(new Pair(pair, innerRace, innerRaceColor, innerLaps, outerRace, outerRaceColor, outerLaps)); } report.Pairs = pairs; return(report); }
private static void UpdateRaceColor(IDistance distance, IRace race) { race.Color = (int)PairsDistanceCalculator.Colors(distance, race.Heat).ToLaneColor((Lane)race.Lane); }
public static async Task <T> LoadAsync(ICompetitionContext context, Guid competitionId, Guid distanceId, OptionalReportColumns optionalColumns) { var report = new T(); var distance = await context.Distances .Include(d => d.Competition.Venue) .Include(d => d.Competition.ReportTemplate.Logos) .FirstOrDefaultAsync(d => d.Id == distanceId); if (distance == null) { throw new DistanceNotFoundException(); } report.SetParameters(distance); report.ReportParameters["OptionalColumnHeader"].Value = Resources.ResourceManager.GetString($"OptionalColumn_{(int)optionalColumns}") ?? ""; var reportOptionalColumns = report as IPairsDrawReportWithOptionalColumn; if (reportOptionalColumns != null) { switch (optionalColumns) { case OptionalReportColumns.HomeVenueCode: report.ReportParameters["InnerOptionalColumnField"].Value = "Inner.Competitor.VenueCode"; report.ReportParameters["OuterOptionalColumnField"].Value = "Outer.Competitor.VenueCode"; break; case OptionalReportColumns.NationalityCode: report.ReportParameters["InnerOptionalColumnField"].Value = "Inner.Competitor.NationalityCode"; report.ReportParameters["OuterOptionalColumnField"].Value = "Outer.Competitor.NationalityCode"; break; case OptionalReportColumns.ClubShortName: report.ReportParameters["InnerOptionalColumnField"].Value = "Inner.Competitor.ClubShortName"; report.ReportParameters["OuterOptionalColumnField"].Value = "Outer.Competitor.ClubShortName"; break; case OptionalReportColumns.LicenseKey: report.ReportParameters["InnerOptionalColumnField"].Value = "Inner.Competitor.LicenseKey"; report.ReportParameters["OuterOptionalColumnField"].Value = "Outer.Competitor.LicenseKey"; break; case OptionalReportColumns.SeasonBest: reportOptionalColumns.InnerOptionalFieldValue = "= SpeedSkating.LongTrack.FormatTime(Fields.Inner.SeasonBest, Parameters.TimeDigits.Value)"; reportOptionalColumns.OuterOptionalFieldValue = "= SpeedSkating.LongTrack.FormatTime(Fields.Outer.SeasonBest, Parameters.TimeDigits.Value)"; break; default: report.ReportParameters["OptionalColumnHeader"].Value = string.Empty; reportOptionalColumns.InnerOptionalFieldValue = null; reportOptionalColumns.OuterOptionalFieldValue = null; break; } } var races = await context.Races .Include(r => r.Competitor) .Include(r => r.Results) .Include(r => r.Times) .Where(r => r.DistanceId == distanceId) .ToListAsync(); await context.Competitors.OfType <TeamCompetitor>() .Include(t => t.Members.Select(m => m.Member)) .Where(tc => tc.Races.Any(r => r.DistanceId == distanceId)) .LoadAsync(); var maxPair = races.Select(r => r.Heat).DefaultIfEmpty(0).Max(); var pairs = new List <Pair>(); for (var pair = distance.FirstHeat; pair <= maxPair; pair++) { var colors = PairsDistanceCalculator.Colors(distance, pair); var innerRace = races.SingleOrDefault(r => r.Heat == pair && r.Lane == 0); var innerRaceColor = (int)colors.ToLaneColor(Lane.Inner); var outerRace = races.SingleOrDefault(r => r.Heat == pair && r.Lane == 1); var outerRaceColor = (int)colors.ToLaneColor(Lane.Outer); pairs.Add(new Pair(pair, innerRace, innerRaceColor, null, outerRace, outerRaceColor, null)); } report.Pairs = pairs; return(report); }