public static void Main(string[] args) { Logger.Info("Application Started"); var categories = new CategoryCreator() .SetRawPath ("Resources/eventexport.csv") .SetOverrideFactory("Resources/events.json") .Create(); var athletes = new AthleteCreator().SetRawPath ("Resources/competitorexport.csv").SetOverrideFactory("Resources/athletes.json").Create (); var clubs = new ClubCreator(athletes).SetOverrideFactory("Resources/clubs.json").Create (); AthleteClubMapper.Map(athletes, clubs); var startpositions = new StartPositionFactory("Resources/startpositions.json").Create(); var crews = new CrewCreator (categories, clubs, startpositions, athletes).SetRawPath ("Resources/crewexport.csv").SetOverrideFactory ("Resources/crews.json").Create ().OrderBy (cr => cr.StartNumber).ToList (); CategoryCrewMapper.Map(categories, crews); if(args.Count() == 0 || args[0].ToLowerInvariant() != "results") { StartPositionGenerator.Generate (crews); bool valid = new CrewValidator().Validate (crews) && new ClubValidator().Validate (clubs) && new AthleteValidator().Validate (athletes) && new CategoryValidator().Validate(categories); if (!valid) return; } else { var starttimes = new SequenceItemFactory("Resources/start-times.json").Create(); var finishtimes = new SequenceItemFactory("Resources/finish-times.json").Create(); var penalties = new PenaltyFactory("Resources/penalties.json").Create(); var adjustments = new AdjustmentFactory ("Resources/adjustments.json").Create (); // todo - is there a weighed in file? TimeMapper.Map (crews, starttimes, finishtimes); TimeMapper.Penalise (crews, penalties); TimeMapper.Adjust (crews, adjustments); CategoryResultsGenerator.Generate (categories); ResultsPrinter.Dump (crews); } Logger.Info ("Application stopped."); }
public bool Validate(IEnumerable <IAthlete> athletes) { ILog logger = LogManager.GetCurrentClassLogger(); DateTime raceday = DateTime.MinValue; if (!DateTime.TryParse(ConfigurationManager.AppSettings["racedate"].ToString(), out raceday)) { raceday = DateTime.MinValue; } var sb = new StringBuilder(); sb.AppendLine("Scratches:"); foreach (var athlete in athletes.Where(a => !a.HasRaw)) { sb.AppendFormat("Crew {0} [{1}], {2}: {3}{4}", athlete.CrewId, athlete.Seat, athlete.Club.Index, athlete.Name, Environment.NewLine); } sb.AppendLine("Age report:"); // todo: configure the report ages foreach (var athlete in athletes.Where(a => a.HasRaw).Where(a => a.Age <= 16 || a.Age >= 75).OrderBy(a => a.Age)) { sb.AppendFormat("{0}, {1}, #{2}, {6}, {7} => {4} years {3}{5}", athlete.Name, athlete.Crew.Name, athlete.Crew.StartNumber, string.Empty, athlete.Age, Environment.NewLine, athlete.Crew.BoatingLocation == null ? "none specified" : athlete.Crew.BoatingLocation.Name, athlete.Crew.SubmittingEmail); } logger.Info(sb.ToString()); logger.Info("Change report:"); IList <Tuple <IAthlete, IAthlete> > changes = new List <Tuple <IAthlete, IAthlete> > (); var ac = new AthleteCreator().SetRawPath("CompetitorsClose.csv"); if (ac.RawPresent()) { IList <IAthlete> originalathletes = ac.Create(); foreach (var athlete in athletes.Where(a => a.HasRaw).OrderBy(a => a.Crew.StartNumber)) { // the substring here ensures that we're ignoring the expiry date, so we're not counting renewals. var originally = originalathletes.FirstOrDefault(a => a.Licence.Substring(7) == athlete.Licence.Substring(7)); if (originally == null) { if (!athlete.IsCox) { changes.Add(new Tuple <IAthlete, IAthlete>(athlete, null)); } logger.InfoFormat("{2}: {1}: {0} is new [cox? {3}]. Crew {4}.", athlete.Name, athlete.Crew.Name, athlete.Crew.StartNumber, athlete.IsCox, athlete.CrewId); continue; } if (athlete.CrewId != originally.CrewId) { if (!athlete.IsCox) { changes.Add(new Tuple <IAthlete, IAthlete>(athlete, originally)); } logger.InfoFormat("{2}: {1}: {0} has moved crew (from {3}) [cox? {4}]", athlete.Name, athlete.Crew.Name, athlete.Crew.StartNumber, originally.CrewId, athlete.IsCox); } } } foreach (var grouping in changes.GroupBy(ch => ch.Item1.Crew.StartNumber).OrderBy(gr => gr.Key)) { var crew = grouping.First().Item1.Crew; int ch = grouping.Count(); string msg = ch >= 4 ? string.Format("{0} / {1}", crew.Name, crew.SubmittingEmail) : string.Empty; logger.InfoFormat("Crew {0} has made {1} changes. {2}", grouping.Key, grouping.Count(), msg); } return(true); }
public static void Main(string[] args) { Logger.Info("Application Started"); if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["csvpath"].ToString())) { CsvImporter.CsvPath = ConfigurationManager.AppSettings["csvpath"].ToString(); } if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["jsonpath"].ToString())) { JsonOverrideFactory.JsonPath = ConfigurationManager.AppSettings["jsonpath"].ToString(); } var categories = new CategoryCreator() .SetRawPath("Events.csv") .SetOverrideFactory("events.json") .Create(); var athletes = new AthleteCreator() .SetRawPath("Competitors.csv") .SetOverrideFactory("athletes.json") .Create(); var clubs = new ClubCreator(athletes).SetOverrideFactory("clubs.json").Create(); AthleteClubMapper.Map(athletes, clubs); var startpositions = new StartPositionFactory("startpositions.json").Create(); var crews = new CrewCreator(categories, clubs, startpositions, athletes) .SetRawPath("Crews.csv") .SetOverrideFactory("crews.json") .Create() .OrderBy(cr => cr.StartNumber) .ToList(); // todo - this is almost certainly not the best place to do this var bandProportions = ConfigurationManager.AppSettings["OpenBands"].Split(',').Select(i => Int32.Parse(i)).ToList(); foreach (Gender gender in (Gender[])Enum.GetValues(typeof(Gender))) { var openBands = categories.Where(cat => cat is EventCategory).Select(c => (EventCategory)c).Where(c => c.Gender == gender && c.UseForCRI).Select(c => c.EventId).ToList(); IList <Func <List <int> > > del = new List <Func <List <int> > > { () => crews.Where(cr => cr.Gender == gender).Select(cr => cr.CRI(false)).ToList(), () => crews.Where(crew => categories.Where(cat => cat is EventCategory).Select(c => (EventCategory)c).Where(c => c.Gender == gender && c.UseForCRI).Select(c => c.EventId).Contains(crew.EventCategory.EventId)).Select(cr => cr.CRI(false)).ToList() }; foreach (var fn in del) { var crisToInclude = fn(); // crews.Where(crew => openBands.Contains(crew.EventCategory.EventId)).Select(cr => cr.CRI).ToList(); crisToInclude.Sort(); if (crisToInclude.Count > 0) { Logger.DebugFormat("{0} crews [#{2}] {1}", gender, crisToInclude.Select(c => c.ToString()).Aggregate((h, t) => String.Format("{0}, {1}", h, t)), crisToInclude.Count); int tally = 0; int lower = 0; for (int i = 0; i < bandProportions.Count; i++) { tally += bandProportions[i]; int upper = i + 1 == bandProportions.Count ? crisToInclude.Count - 1 : 1 + (int)Math.Floor((decimal)crisToInclude.Count * tally / 100); Logger.DebugFormat("Band {0} [{1}, {2}{4}. #{3} ", i + 1, crisToInclude[lower], crisToInclude[upper], (i + 1 == bandProportions.Count ? 1 : 0) + upper - lower, i + 1 < bandProportions.Count ? ")" : "]"); // crisToInclude[mag-1], crisToInclude[mag]); lower = upper; } foreach (var b in new List <bool> { true, false }) { Logger.InfoFormat("Correlation between CRI{2} and points ({1}): {0}", PearsonCorrelation(crews.Where(cr => cr.Gender == gender).Select(cr => (double)cr.CRI(b)).ToList(), crews.Where(cr => cr.Gender == gender).Select(cr => (double)cr.Points).ToList()), gender, b ? "Max" : ""); } } } } foreach (var b in new List <bool> { true, false }) { Logger.InfoFormat("Correlation between CRI{1} and points (all): {0}", PearsonCorrelation(crews.Select(cr => (double)cr.CRI(b)).ToList(), crews.Select(cr => (double)cr.Points).ToList()), b ? "Max" : ""); } CategoryCrewMapper.Map(categories, crews); // TODO: move results into the config file? if (args.Count() == 0 || args[0].ToLowerInvariant() != "results") { StartPositionGenerator.Generate(crews); bool valid = new CrewValidator(athletes).Validate(crews) && new ClubValidator().Validate(clubs) && new AthleteValidator().Validate(athletes) && new CategoryValidator().Validate(categories); if (!valid) { return; } } else { var starttimes = new SequenceItemFactory("start-times.json").Create(); var finishtimes = new SequenceItemFactory("finish-times.json").Create(); var penalties = new PenaltyFactory("penalties.json").Create(); var adjustments = new AdjustmentFactory("adjustments.json").Create(); // todo - is there a weighed in file? TimeMapper.Map(crews, starttimes, finishtimes); TimeMapper.Penalise(crews, penalties); TimeMapper.Adjust(crews, adjustments); CategoryResultsGenerator.Generate(categories); ResultsPrinter.Dump(crews); } Logger.Info("Application stopped."); }