コード例 #1
0
        /// <summary>
        /// Initialises a new instance of the <see cref="LabelGenerationViewModel"/> class.
        /// </summary>
        /// <param name="model">junior handicap model</param>
        /// <param name="normalisationConfigManager">normalisation configuration manager</param>
        /// <param name="seriesConfigManager">series configuration manager</param>
        /// <param name="logger">application logger</param>
        /// <param name="saveFolder">folder to save the output to</param>
        public LabelGenerationViewModel(
            IModel model,
            INormalisationConfigMngr normalisationConfigManager,
            ISeriesConfigMngr seriesConfigManager,
            IJHcLogger logger,
            string saveFolder)
        {
            this.model = model;
            this.seriesConfigManager = seriesConfigManager;
            this.logger = logger;
            SaveFolder  = saveFolder;
            NormalisationConfigType hcConfiguration =
                normalisationConfigManager.ReadNormalisationConfiguration();

            // TODO, this is repeated code, see HandicapWriter.cs
            foreach (AthleteDetails athlete in model.Athletes.AthleteDetails)
            {
                TimeType newHandicap = model.CurrentSeason.GetAthleteHandicap(athlete.Key, hcConfiguration);

                // Only look at active athletes.
                if (athlete.Active)
                {
                    List <string> runningNumbers = model.Athletes.GetAthleteRunningNumbers(athlete.Key);

                    // Use default handicap, if the athlete is not registered for the current season.
                    // TODO, I suspect this should never happen???
                    if (newHandicap == null)
                    {
                        newHandicap = athlete.RoundedHandicap;
                    }

                    // Ensure that the athlete is registered for the season.
                    if (runningNumbers.Count > 0)
                    {
                        AthleteLabel modelAthlete =
                            new AthleteLabel(
                                athlete.Name,
                                athlete.Club,
                                runningNumbers[0],
                                newHandicap,
                                athlete.Appearances == 0);
                        modelAthlete.AthleteLabelWidth  = A4Details.GetLabelWidth96DPI(NoColumns);
                        modelAthlete.AthleteLabelHeight = A4Details.GetLabelHeight96DPI(NoRows);
                        this.AthleteDetails.Add(modelAthlete);
                    }
                }
            }

            // Order the athletes alphabetically.
            this.AthleteDetails =
                this.AthleteDetails.OrderBy(athlete => athlete.Forename).ToList();
            this.AthleteDetails =
                this.AthleteDetails.OrderBy(athlete => athlete.Surname).ToList();

            this.saveDirectory = saveFolder;

            this.CreateRaceLabelsCommand  = new CreateAndSaveRaceLabelsCmd(this);
            this.CreateSpareLabelsCommand = new CreateAndSaveSpareLabelsCmd(this);
            this.CreateAllLabelsCommand   = new CreateAndSaveAllLabelsCmd(this);
        }
コード例 #2
0
ファイル: HandicapHelper.cs プロジェクト: abs508/jHc
        /// <summary>
        /// Round to the nearest 30 seconds
        /// </summary>
        /// <param name="config">normalisation configuration</param>
        /// <param name="inputTime">time to round</param>
        /// <returns></returns>
        public static RaceTimeType RoundHandicap(
            NormalisationConfigType config,
            RaceTimeType inputTime)
        {
            RaceTimeType calculatedHandicap = inputTime;

            // Make sure the handicap is not less than the minimum.
            if (calculatedHandicap < new TimeType(config.MinimumHandicap, 0))
            {
                return(new RaceTimeType(config.MinimumHandicap, 0));
            }

            // Round to nearest 30 seconds
            if (calculatedHandicap.Seconds < 15)
            {
                calculatedHandicap = new RaceTimeType(calculatedHandicap.Minutes, 0);
            }
            else if (calculatedHandicap.Seconds < 45)
            {
                calculatedHandicap = new RaceTimeType(calculatedHandicap.Minutes, 30);
            }
            else
            {
                calculatedHandicap = new RaceTimeType(calculatedHandicap.Minutes + 1, 0);
            }

            return(calculatedHandicap);
        }
コード例 #3
0
ファイル: Season.cs プロジェクト: abs508/jHc
        /// <summary>
        /// Get the current handicap for the athlete. The handicap is the rounded one.
        /// </summary>
        /// <param name="key">unique key</param>
        /// <returns>rounded handicap</returns>
        public RaceTimeType GetAthleteHandicap(int key, NormalisationConfigType hcConfiguration)
        {
            if (Athletes != null && Athletes.Count > 0)
            {
                if (Athletes.Exists(athlete => athlete.Key == key))
                {
                    return(Athletes.Find(athlete => athlete.Key == key).GetRoundedHandicap(hcConfiguration));
                }
            }

            return(null);
        }
コード例 #4
0
ファイル: CalculateResultsMngr.cs プロジェクト: abs508/jHc
 /// <summary>
 /// Initialises a new instance of the <see cref="CalculateResultsMngr"/> class.
 /// </summary>
 /// <param name="model">junior handicap model</param>
 /// <param name="normalisationConfigurationManager">
 /// normalisation configuration manager
 /// </param>
 /// <param name="resultsConfigurationManager">
 /// results configuration manager
 /// </param>
 /// <param name="seriesConfigurationManager">
 /// series configuration manager
 /// </param>
 /// <param name="logger">application logger</param>
 public CalculateResultsMngr(
     IModel model,
     INormalisationConfigMngr normalisationConfigurationManager,
     IResultsConfigMngr resultsConfigurationManager,
     ISeriesConfigMngr seriesConfigurationManager,
     IJHcLogger logger)
     : base(model)
 {
     this.logger = logger;
     this.resultsConfiguration = resultsConfigurationManager;
     this.hcConfiguration      = normalisationConfigurationManager.ReadNormalisationConfiguration();
     this.seriesConfiguration  = seriesConfigurationManager.ReadSeriesConfiguration();
 }
コード例 #5
0
        //athleteCurrentSeason.Points.BestPoints));

        /// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
        /// <name>LoadAthleteInformation</name>
        /// <date>14/03/15</date>
        /// <summary>
        /// Loads the athlete information via the business library and adds it to the athlete collection.
        /// </summary>
        /// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
        private void LoadAthleteInformation(List <AthleteDetails> athletes)
        {
            NormalisationConfigType hcConfiguration =
                this.normalisationConfigManager.ReadNormalisationConfiguration();

            List <AthleteDetails> orderedList = athletes.OrderBy(athlete => athlete.Forename).ToList();

            orderedList = orderedList.OrderBy(athlete => athlete.Surname).ToList();

            this.AthleteCollection = new ObservableCollection <AthleteCompleteViewModel>();
            foreach (AthleteDetails athlete in orderedList)
            {
                AthleteSeasonDetails athleteCurrentSeason =
                    this.model.CurrentSeason.Athletes.Find(a => a.Key == athlete.Key);

                if (athleteCurrentSeason == null)
                {
                    athleteCurrentSeason =
                        new AthleteSeasonDetails(
                            athlete.Key,
                            athlete.Name,
                            this.resultsConfigurationManager);
                }

                string handicap = athleteCurrentSeason.GetRoundedHandicap(hcConfiguration)?.ToString() ?? athlete.RoundedHandicap.ToString();

                this.AthleteCollection.Add(
                    new AthleteCompleteViewModel(
                        athlete.Key,
                        athlete.Name,
                        athlete.Club,
                        athlete.Sex.ToString(),
                        handicap,
                        athlete.PB.ToString(),
                        athlete.LastAppearance.ToString(),
                        athlete.Appearances,
                        athlete.SignedConsent,
                        athlete.Active,
                        athleteCurrentSeason.SB.ToString(),
                        ListOCConverter.ToObservableCollection(athlete.RunningNumbers),
                        this.ConvertAppearances(athleteCurrentSeason.Times),
                        this.ConvertAppearances(athlete.Times),
                        athleteCurrentSeason.Points.TotalPoints,
                        athleteCurrentSeason.Points.FinishingPoints,
                        athleteCurrentSeason.Points.PositionPoints,
                        athleteCurrentSeason.Points.BestPoints));
            }
        }
コード例 #6
0
 /// <summary>
 /// Creates and saves a default normalisation configuration file.
 /// </summary>
 /// <param name="normalisationConfig">normalisation configuration details</param>
 public void SaveResultsConfiguration(
     NormalisationConfigType normalisationConfig)
 {
     try
     {
         this.reader.SaveNormalisationConfigData(
             this.generalIo.ResultsConfigurationFile,
             normalisationConfig);
     }
     catch (Exception ex)
     {
         this.logger.WriteLog("Failed to save normalisation config file: " + ex.ToString());
         Messenger.Default.Send(
             new HandicapErrorMessage(
                 "Error creating normalisation config file"));
     }
 }
コード例 #7
0
        /// <summary>
        /// Save the configuration data.
        /// </summary>
        /// <param name="fileName">file name</param>
        /// <param name="configData">configuration data</param>
        /// <returns>success flag</returns>
        public bool SaveNormalisationConfigData(
            string fileName,
            NormalisationConfigType configData)
        {
            bool success = true;

            try
            {
                XDocument writer = new XDocument(
                    new XDeclaration("1.0", "uft-8", "yes"),
                    new XComment("HC Normalisation Config XML"));
                XElement root = new XElement(rootElement);

                XElement racePoints =
                    new XElement(
                        useElement,
                        new XAttribute(
                            useHandicapAttribute,
                            configData.UseCalculatedHandicap));

                XElement clubPoints =
                    new XElement(
                        handicapsElement,
                        new XAttribute(
                            handicapTimeAttribute,
                            configData.HandicapTime),
                        new XAttribute(
                            minimumTimeAttribute,
                            configData.MinimumHandicap),
                        new XAttribute(
                            handicapIntervalAttribute,
                            configData.HandicapInterval));

                root.Add(racePoints);
                root.Add(clubPoints);

                writer.Add(root);
                writer.Save(fileName);
            }
            catch (Exception ex)
            {
                this.logger.WriteLog("Error writing Normalisation Configuration data " + ex.ToString());
            }

            return(success);
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        public void DeleteResults()
        {
            this.logger.WriteLog("Delete results");
            DateType currentDate = this.Model.CurrentEvent.Date;
            NormalisationConfigType hcConfiguration =
                this.normalisationConfigMngr.ReadNormalisationConfiguration();

            // Remove points from all clubs for the known date.
            this.RemoveClubPoints(currentDate);

            // In the athlete's season remove all points and times for the known date.
            // Remove the time from the athlete's data
            this.RemoveAthletePoints(currentDate);

            foreach (ResultsTableEntry athleteEntry in this.Model.CurrentEvent.ResultsTable.Entries)
            {
                this.ReduceNumberStatistics(athleteEntry.Sex, athleteEntry.FirstTimer);
                this.RemoveFastestTime(athleteEntry.Sex, athleteEntry.Key, athleteEntry.Name, athleteEntry.RunningTime);

                // If season best, then delete one from the global summary and season summary.
                if (athleteEntry.SB)
                {
                    this.RemoveSBRecord();
                }

                // If personal best, then delete one from the global summary and season summary.
                if (athleteEntry.PB)
                {
                    this.RemovePBRecord();
                }
            }

            // Re initialise the event summary.
            this.Model.CurrentEvent.SetResultsTable(new EventResults());
            this.Model.CurrentEvent.Summary.Reset();

            this.SaveAll();

            this.logger.WriteLog("Delete results completed");
        }
コード例 #9
0
        /// <summary>
        /// Initialises a new instance of the <see cref="NormalisationConfigViewModel"/> class.
        /// </summary>
        /// <param name="normalisationConfigManager">normalisation config manager</param>
        /// <param name="logger">application logger</param>
        public NormalisationConfigViewModel(
            INormalisationConfigMngr normalisationConfigManager,
            IJHcLogger logger)
        {
            this.normalisationConfigManager = normalisationConfigManager;
            this.logger = logger;

            NormalisationConfigType config =
                this.normalisationConfigManager.ReadNormalisationConfiguration();

            useHandicap           = config.UseCalculatedHandicap;
            handicapTime          = config.HandicapTime.ToString();
            minimumHandicap       = config.MinimumHandicap.ToString();
            this.handicapInterval = config.HandicapInterval.ToString();

            useHandicapOrig           = UseHandicap;
            handicapTimeOrig          = HandicapTime;
            minimumHandicapOrig       = MinimumHandicap;
            this.handicapIntervalOrig = this.HandicapInterval;

            SaveCommand = new NormalisationConfigSaveCmd(this);
        }
コード例 #10
0
ファイル: AthleteSeasonDetails.cs プロジェクト: abs508/jHc
        /// <summary>
        /// Calculates a new handicap from the list of times.
        /// </summary>
        public RaceTimeType GetRoundedHandicap(NormalisationConfigType hcConfiguration)
        {
            RaceTimeType handicap;
            RaceTimeType handicapWorking = new RaceTimeType(0, 0);

            if (!hcConfiguration.UseCalculatedHandicap)
            {
                return(null);
            }

            if (this.NumberOfAppearances == 0)
            {
                return(null);
            }

            int eventsIncluded = 0;

            for (int index = NumberOfAppearances - 1; index >= 0; --index)
            {
                if (eventsIncluded < 3)
                {
                    if (!this.Times[index].Time.DNF && !this.Times[index].Time.Unknown)
                    {
                        handicapWorking = handicapWorking + this.Times[index].Time;
                        ++eventsIncluded;
                    }
                }
                else
                {
                    break;
                }
            }

            handicap = new RaceTimeType(hcConfiguration.HandicapTime, 0) - (handicapWorking / eventsIncluded);

            return(HandicapHelper.RoundHandicap(
                       hcConfiguration,
                       handicap));
        }
コード例 #11
0
        /// <summary>
        /// Write the handicaps to a file.
        /// </summary>
        /// <param name="model">junior handicap model</param>
        /// <param name="folder">output folder</param>
        /// <param name="normalisationConfigMngr">normalisation configuration manager</param>
        /// <param name="logger">application logger</param>
        /// <returns>success flag</returns>
        public static bool WriteHandicapTable(
            IModel model,
            string folder,
            INormalisationConfigMngr normalisationConfigMngr,
            IJHcLogger logger)
        {
            bool success = true;

            Messenger.Default.Send(
                new HandicapProgressMessage(
                    "Printing handicap."));

            try
            {
                NormalisationConfigType hcConfiguration =
                    normalisationConfigMngr.ReadNormalisationConfiguration();

                using (StreamWriter writer = new StreamWriter(Path.GetFullPath(folder) +
                                                              Path.DirectorySeparatorChar +
                                                              model.CurrentSeason.Name +
                                                              model.CurrentEvent.Name +
                                                              ResultsPaths.handicapTable +
                                                              ResultsPaths.csvExtension))
                {
                    List <AthleteDetails> athletes = new List <AthleteDetails>(model.Athletes.AthleteDetails);
                    athletes = athletes.OrderBy(athlete => athlete.Forename).ToList();
                    athletes = athletes.OrderBy(athlete => athlete.Surname).ToList();

                    foreach (AthleteDetails athlete in athletes)
                    {
                        if (!athlete.Active)
                        {
                            continue;
                        }

                        string number =
                            model.Athletes.GetAthleteRunningNumber(
                                athlete.Key);
                        TimeType newHandicap =
                            model.CurrentSeason.GetAthleteHandicap(
                                athlete.Key,
                                hcConfiguration);
                        string consented =
                            athlete.SignedConsent
                            ? "Y"
                            : string.Empty;

                        // Use default handicap, if the athlete is not registered for the current season.
                        if (newHandicap == null)
                        {
                            newHandicap = athlete.RoundedHandicap;
                        }

                        string entryString = athlete.Name +
                                             ResultsPaths.separator +
                                             number +
                                             ResultsPaths.separator +
                                             newHandicap +
                                             ResultsPaths.separator +
                                             athlete.Club +
                                             ResultsPaths.separator +
                                             consented;

                        writer.WriteLine(entryString);
                    }
                    success = true;
                }
            }
            catch (Exception ex)
            {
                logger.WriteLog("Error, failed to print handicap: " + ex.ToString());

                Messenger.Default.Send(
                    new HandicapErrorMessage(
                        "Failed to print handicap"));

                success = false;
            }

            return(success);
        }