protected override IList <ICategory> InternalCreate()
        {
            ILog logger = LogManager.GetCurrentClassLogger();

            List <ICategory> categories = new List <ICategory>
            {
                new OverallCategory(),
                new TimeOnlyCategory()
            };

            // todo: review how to combine categories together more effectively - setting the
            var masterOverrides = RawOverrides.Where(o => o.AggregationMaster).Select(o => o.EventId);
            var mastersA        =
                RawUnderlying
                .Where(u => masterOverrides.Contains(u.eventId)).ToList();
            IList <EventCategory> masters = mastersA
                                            .Select(u => new EventCategory(u, RawOverrides.FirstOrDefault(ov => ov.EventId == u.eventId), null))
                                            .ToList();

            categories.AddRange(masters);
            var multiBands = RawOverrides.GroupBy(o => o.EventId).Where(kvp => kvp.Count() > 1).Select(kvp => kvp.Key).ToList();

            categories.AddRange(
                RawUnderlying
                .Where(u => !masters.Select(m => m.EventId).Contains(u.eventId))
                .Where(u => !multiBands.Contains(u.eventId))
                .Select(u => new EventCategory(u, RawOverrides.FirstOrDefault(ov => ov.EventId == u.eventId), masters)));

            foreach (var multi in multiBands)
            {
                var bands      = RawOverrides.Where(o => o.EventId == multi);
                var underlying = RawUnderlying.FirstOrDefault(u => u.eventId == multi);
                foreach (var b in bands)
                {
                    categories.Add(new EventCategory(underlying, b, masters));
                    logger.DebugFormat("Added {0} ({1}, {2})", underlying.eventIdentity, b.FromPri, b.ToPri);
                }
            }

            foreach (Gender gender in (Gender[])Enum.GetValues(typeof(Gender)))
            {
                if (ConfigurationManager.AppSettings["hasoverallgendercategory"].ToString() == "1")
                {
                    categories.Add(new GenderCategory(gender));
                }
                if (ConfigurationManager.AppSettings["hasoverallforeigncategory"].ToString() == "1")
                {
                    categories.Add(new ForeignCategory(gender));
                }
                if (ConfigurationManager.AppSettings ["overallmastershandicapped"].ToString() == "1")
                {
                    categories.Add(new MastersGenderAdjustedCategory(gender, false, false));
                    categories.Add(new MastersGenderAdjustedCategory(gender, true, false));
                    //categories.Add (new MastersGenderAdjustedCategory (gender, true, true));
                }
            }

            return(categories);
        }
Esempio n. 2
0
		protected override IList<ICrew> InternalCreate ()
		{
			IList<ICrew> crews = new List<ICrew> ();
			foreach (var raw in RawUnderlying) 
			{
				if (raw.currentCrewStatus != "Accepted" && raw.currentCrewStatus != "Submitted")
				{
                    Logger.DebugFormat("Crew {0} is {1}", raw.crewId, raw.currentCrewStatus); 
					continue;
				}
                CrewOverride crewOverride = RawOverrides.FirstOrDefault(o => o.CrewId == raw.crewId);

                // if there are several categories for the single event id, pick one with the appropriate CRI range. 
                // todo: deal with the situation where lightweights cannot be in the lowest or highest bands 
                var validcats = _eventCategories.Where(cat => cat.EventId == raw.eventId).ToList();
                if(crewOverride != null && !string.IsNullOrEmpty(crewOverride.EventName))
                {
                    var overridecats = _eventCategories.Where(cat => cat.Name == crewOverride.EventName).ToList();
                    if (overridecats.Count == 1)
                        validcats = overridecats;
                    else
                    {
                        // if the event name has been overridden, we need to map across to the agg Master 
                        var aggMasters = overridecats.Where(cat => cat.AggregationMaster != null).Select(cat => cat.AggregationMaster).ToList();
                        if (aggMasters.Count > 0)
                            validcats = new List<EventCategory> { aggMasters[0] };
                    }
                }

                // HACK: euch. The PRI Name hack to ensure that crews that should be novice but aren't, but then end in an aggregated category ... 
                EventCategory eventCategory = 
                    validcats.Count > 1 
                        ? validcats.FirstOrDefault(vc => vc.CriInRange(crewOverride != null && crewOverride.PRI > 0 ? crewOverride.PRI : raw.rowingPointsCri)) // todo - sculling vs rowing 
                        : validcats[0];

				int startPosition = -1;
				try
				{
					startPosition = _startPositions == null ? -1 : _startPositions.First(sp => sp.CrewId == raw.crewId).StartNumber;
				}
				catch (Exception)
				{
					Logger.ErrorFormat("A problem with the start position for crewid: {0}", raw.crewId);
					throw;
				}
				IClub boatingLocation = _clubs.FirstOrDefault (cl => !string.IsNullOrEmpty(raw.boatingPermissionClubIndexCode) && cl.Index == raw.boatingPermissionClubIndexCode);
				if (boatingLocation == null)
					Logger.WarnFormat ("Cannot identify boating location [crewid: {1}]: {0}", raw.boatingPermissionClubIndexCode, raw.crewId);
				var athletes = _athletes.Where (a => a.CrewId == raw.crewId).ToList();
				var componentClubs = athletes.Select(a => a.Club).Distinct().ToList();
				ICrew crew = new Crew (raw, eventCategory, crewOverride, boatingLocation, startPosition, componentClubs);
				foreach (var athlete in athletes) {
					athlete.SetCrew (crew);
					crew.AddAthlete (athlete);
				}
				crews.Add (crew);
			}
			return crews;
		}
Esempio n. 3
0
        protected override IList <IAthlete> InternalCreate()
        {
            var scratched = RawOverrides.Where(o => !RawUnderlying.Select(u => u.CrewId).Contains(o.CrewId)).Select(o => new Athlete(null, o));

            return(RawUnderlying.Select(a => new Athlete(a, RawOverrides.FirstOrDefault(ov => ov.CrewId == a.CrewId && ov.Position == a.Position)) as IAthlete).Union(scratched).ToList());
        }