private HypotheticalsViewModel GetEstimatedTime(RaceFilterViewModel filter) { var modelView = new HypotheticalsViewModel(); modelView.Filter = filter; string raceId = filter.SelectedRaceIds.First(); var athletes = _RaceService.GetAthletes( new BasicRaceCriteria { SelectedRaceIds = new string[] { raceId }, SelectedAgeGroupIds = AgeGroup.Expand(filter.SelectedAgeGroupIds), SelectedGenderIds = Gender.Expand(filter.SelectedGenderIds) }, filter ); modelView.Triathletes = athletes; modelView.Stats.Add(GetStats(athletes, filter.AvailableRaces.Single(r => r.RaceId == raceId))); modelView.SelectedSkillLevel = filter.SkillLevel; //TO-DO: fix this up so it removes the redundancy return(modelView); }
protected override ActionResult DisplayResultsView(RaceFilterViewModel filter) { var viewModel = new TriStatsViewModel(); viewModel.Filter = filter; List <Triathlete> allAthletes = GetAllAthletesForRaces(filter); var selectedAgeGroupIds = AgeGroup.Expand(filter.SelectedAgeGroupIds); var selectedGenderIds = Gender.Expand(filter.SelectedGenderIds); var athletes = new List <Triathlete>(); foreach (string raceId in filter.SelectedRaceIds) { var athletesPerRace = allAthletes.Where( a => a.RequestContext.RaceId.Equals(raceId, System.StringComparison.CurrentCultureIgnoreCase) && selectedAgeGroupIds.Contains(a.RequestContext.AgeGroupId) && selectedGenderIds.Contains(a.RequestContext.GenderId) ).ToList(); // new BasicDurationFilter() { } //bypass the user's duration filter so we can get all athletes, including DNFs athletes.AddRange(athletesPerRace); viewModel.Stats.Add( GetStats(athletesPerRace, filter.AvailableRaces.Single(r => r.RaceId == raceId))); } viewModel.Triathletes = athletes; return(View("Compare", viewModel)); }
//filter the list of athletes by race, agegroup, gender, and range protected List <Triathlete> GetFilteredAthletes(string raceId, List <Triathlete> allAthletes, RaceFilterViewModel filter) { var selectedAgeGroupIds = AgeGroup.Expand(filter.SelectedAgeGroupIds); var selectedGenderIds = Gender.Expand(filter.SelectedGenderIds); var athletes = allAthletes.Where( a => a.RequestContext.RaceId.Equals(raceId, StringComparison.CurrentCultureIgnoreCase) && selectedAgeGroupIds.Contains(a.RequestContext.AgeGroupId) && selectedGenderIds.Contains(a.RequestContext.GenderId)).ToList(); return(new BasicFilterProvider(athletes, filter).GetAthletes()); }
private static void PopulateCache(string raceId) { using (var db = new RaceAnalysisDbContext()) { var raceService = new RaceService(db); var athletes = raceService.GetAthletes( new BasicRaceCriteria { SelectedRaceIds = new string[] { raceId }, SelectedAgeGroupIds = AgeGroup.Expand(new int[] { 0 }), SelectedGenderIds = Gender.Expand(new int[] { 0 }) } ); } }
//filter the list of athletes by agegroup, gender, and range protected List <Triathlete> GetFilteredAthletes(List <Triathlete> allAthletes, RaceFilterViewModel filter, string sort = null, string search = null) { try { Trace.TraceInformation("GetFilteredAthletes-1"); var selectedAgeGroupIds = AgeGroup.Expand(filter.SelectedAgeGroupIds); var selectedGenderIds = Gender.Expand(filter.SelectedGenderIds); var athletes = allAthletes.Where( a => selectedAgeGroupIds.Contains(a.RequestContext.AgeGroupId) && selectedGenderIds.Contains(a.RequestContext.GenderId)); Trace.TraceInformation("GetFilteredAthletes-1a"); if (!string.IsNullOrEmpty(sort)) { athletes = athletes.AsQueryable().OrderBy(sort); } Trace.TraceInformation("GetFilteredAthletes-1b"); if (!String.IsNullOrEmpty(search)) { Trace.TraceInformation("GetFilteredAthletes-Search"); athletes = athletes.Where(a => a.Name.ToLower().Contains(search.ToLower())).ToList(); } Trace.TraceInformation(String.Format("GetFilteredAthletes-2 athlete count {0}", athletes.Count())); var list = athletes.ToList(); Trace.TraceInformation("GetFilteredAthletes-3"); var result = new BasicFilterProvider(list, filter).GetAthletes(); return(result); } catch (Exception ex) { Trace.TraceError(ex.Message); throw ex; } }
/// <summary> /// DisplayResultsView() - In this version we must iterate through each race, get the athletes, and calculate their stats /// </summary> /// <param name="page"></param> /// <param name="raceIds"></param> /// <param name="agegroupIds"></param> /// <param name="genderIds"></param> /// <returns></returns> protected override ActionResult DisplayResultsView(RaceFilterViewModel filter) { var viewModel = new TriStatsViewModel(); viewModel.Filter = filter; List <Triathlete> allAthletes = GetAllAthletesForRaces(filter); var selectedAgeGroupIds = AgeGroup.Expand(filter.SelectedAgeGroupIds); var selectedGenderIds = Gender.Expand(filter.SelectedGenderIds); foreach (string raceId in filter.SelectedRaceIds) //get stats for each race in order to compare them rather than to combine their stats { var athletes = GetFilteredAthletes(raceId, allAthletes, filter); var stats = GetStats(athletes, _DBContext.Races.Include("Conditions").Single(r => r.RaceId.Equals(raceId, StringComparison.CurrentCultureIgnoreCase))); viewModel.Stats.Add(stats); } return(View("~/Views/TriStats/Details.cshtml", viewModel)); }
protected override ActionResult DisplayResultsView(RaceFilterViewModel filter) { var viewModel = new AgeGroupCompareViewModel(); viewModel.Filter = filter; List <Triathlete> allAthletes = GetAllAthletesForRaces(filter); var stopwatch = new Stopwatch(); stopwatch.Start(); var selectedGenderIds = Gender.Expand(filter.SelectedGenderIds); var resultingAthletes = new List <Triathlete>(); //calculating each selected age groups so that we can do the same when we draw the chart foreach (var agId in AgeGroup.Expand(viewModel.Filter.SelectedAgeGroupIds)) //collect the stats for each age group { var athletesPerAG = allAthletes.Where( a => a.RequestContext.AgeGroupId == agId && selectedGenderIds.Contains(a.RequestContext.GenderId)).ToList(); var filteredAthletes = new BasicFilterProvider(athletesPerAG, filter).GetAthletes(); resultingAthletes.AddRange(filteredAthletes); var stats = GetStats(filteredAthletes); stats.AgeGroupId = agId; viewModel.Stats.Add(stats); } Trace.TraceInformation("AgeGroupCompare Calulating all took: " + stopwatch.Elapsed); stopwatch.Stop(); viewModel.Triathletes = resultingAthletes; return(View("Compare", viewModel)); }
protected List <Triathlete> GetAllAthletesForRaces(RaceFilterViewModel filter) { var stopwatch = new Stopwatch(); stopwatch.Start(); var allAthletes = new List <Triathlete>(); var allAgeGroupIds = AgeGroup.Expand(new int[] { 0 }); var allGenderIds = Gender.Expand(new int[] { 0 }); //assuming a cache contains athletes for each race, get all athletes for each racfil foreach (var raceId in filter.SelectedRaceIds) { if (String.IsNullOrEmpty(raceId))//i've seen this occassionally with a back button { continue; } var athletes = _RaceService.GetAthletes( new BasicRaceCriteria { SelectedRaceIds = { raceId }, SelectedAgeGroupIds = allAgeGroupIds, SelectedGenderIds = allGenderIds } ); if (athletes.Count > 0) { allAthletes.AddRange(athletes); } } Trace.TraceInformation("BaseCcontroller GetAllRaceInfo took: " + stopwatch.Elapsed); stopwatch.Reset(); return(allAthletes); }