Esempio n. 1
0
        /// <summary>
        /// Initialises a new instance of the <see cref="PositionEditorRawItem"/> class
        /// </summary>
        /// <param name="input"></param>
        public PositionEditorRawItem(string input)
        {
            this.Complete         = input;
            this.Barcode          = ResultsDecoder.OpnScannerResultsBarcode(input);
            this.ExtraInformation = ResultsDecoder.OpnScannerResultsOtherData(input);
            this.fault            = PositionEditorFaults.NoFault;

            int defaultPosition = -1;

            // Calculate the position as an interger. Use default if there is a fault in the calculation,
            // or a position is not represented.
            if (this.Type == PositionEditorType.Position)
            {
                int position;
                int.TryParse(ResultsDecoder.GetPositionNumber(this.Barcode), out position);

                if (position != 0)
                {
                    this.Position = position;
                }
                else
                {
                    this.Position = defaultPosition;
                }
            }
            else
            {
                this.Position = defaultPosition;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Takes a result and populate the position or race number depending on what it is.
 /// </summary>
 /// <param name="result">position / athlete result</param>
 /// <param name="position">position of result</param>
 /// <param name="raceNumber">race number of result</param>
 private void UpdatePositionAthleteData(string result,
                                        ref int?position,
                                        ref string raceNumber)
 {
     if (ResultsDecoder.IsPositionValue(result))
     {
         position = ResultsDecoder.ConvertPositionValue(result);
     }
     else
     {
         raceNumber = result;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Import the times from <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">file containing times</param>
        /// <param name="commonIo">common Io manager</param>
        /// <param name="logger">program logger</param>
        /// <returns>collection of race times.</returns>
        public static List <RawPositionResults> Import(
            string fileName,
            ICommonIo commonIo,
            IJHcLogger logger)
        {
            List <RawPositionResults> rawImportedPositions = new List <RawPositionResults>();
            List <string>             rawPositions         = commonIo.ReadFile(fileName);

            foreach (string positionAthleteData in rawPositions)
            {
                char splitChar = ',';

                string[] resultLine = positionAthleteData.Split(splitChar);

                // Ensure this line is not the first one and its valid.
                if (string.Equals(resultLine[0], StartString) ||
                    resultLine.Length != ImportParkrunPositionFactory.NumberOfSectionsInAValdEntry)
                {
                    continue;
                }

                // Ensure that the interesting data is not empty.
                if (string.IsNullOrEmpty(resultLine[0]) ||
                    string.IsNullOrEmpty(resultLine[1]) ||
                    !ResultsDecoder.IsPositionValue(resultLine[1]))
                {
                    continue;
                }

                int?position =
                    ResultsDecoder.ConvertPositionValue(
                        resultLine[1]);

                RawPositionResults result =
                    new RawPositionResults(
                        resultLine[0],
                        (int)position);

                rawImportedPositions.Add(result);
            }

            rawImportedPositions =
                rawImportedPositions
                .OrderBy(position => position.Position)
                .ToList();

            return(rawImportedPositions);
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        public void ImportPositionsData(string fileName)
        {
            RawImportedPostions = new List <ImportedRawPositionResults>();
            List <List <string> > rawPositions = this.commonIo.ReadPairedStringListFomFile(fileName);

            foreach (List <string> positionAthleteData in rawPositions)
            {
                // Ensure 2 results present
                if (positionAthleteData.Count == 2)
                {
                    int?   position   = null;
                    string raceNumber = null;

                    string result1 = ResultsDecoder.OpnScannerResultsBarcode(positionAthleteData[0]);
                    string result2 = ResultsDecoder.OpnScannerResultsBarcode(positionAthleteData[1]);

                    this.UpdatePositionAthleteData(result1, ref position, ref raceNumber);
                    this.UpdatePositionAthleteData(result2, ref position, ref raceNumber);

                    if (position != null && raceNumber != null)
                    {
                        RawImportedPostions.Add(new ImportedRawPositionResults(raceNumber, (int)position));
                    }
                    else
                    {
                        string errorString = string.Format("Can't decode {0}/{1}", positionAthleteData[0], positionAthleteData[1]);
                        Messenger.Default.Send(
                            new HandicapProgressMessage(
                                errorString));
                        this.logger.WriteLog(errorString);
                    }
                }
                else
                {
                    string errorString = "Please check results, result/barcode pair invalid";
                    Messenger.Default.Send(
                        new HandicapProgressMessage(
                            errorString));
                    this.logger.WriteLog(errorString);
                }
            }

            RawImportedPostions = RawImportedPostions.OrderBy(position => position.Position).ToList();
            RaisePropertyChangedEvent("RawImportedPostions");
            this.DetermineImportedState();
        }
Esempio n. 5
0
        /// <summary>
        /// Import the times from <paramref name="fileName"/>
        /// </summary>
        /// <param name="fileName">file containing times</param>
        /// <param name="commonIo">common Io manager</param>
        /// <param name="logger">program logger</param>
        /// <returns>collection of race times.</returns>
        public static List <RawPositionResults> Import(
            string fileName,
            ICommonIo commonIo,
            IJHcLogger logger)
        {
            List <RawPositionResults> rawImportedPositions = new List <RawPositionResults>();
            List <List <string> >     rawPositions         = commonIo.ReadPairedStringListFomFile(fileName);

            foreach (List <string> positionAthleteData in rawPositions)
            {
                // Ensure 2 results present
                if (positionAthleteData.Count == 2)
                {
                    int?   position   = null;
                    string raceNumber = null;

                    string result1 = ResultsDecoder.OpnScannerResultsBarcode(positionAthleteData[0]);
                    string result2 = ResultsDecoder.OpnScannerResultsBarcode(positionAthleteData[1]);

                    UpdatePositionAthleteData(
                        result1,
                        ref position,
                        ref raceNumber);
                    UpdatePositionAthleteData(
                        result2,
                        ref position,
                        ref raceNumber);

                    if (position != null && raceNumber != null)
                    {
                        RawPositionResults results =
                            new RawPositionResults(
                                raceNumber,
                                (int)position);
                        rawImportedPositions.Add(results);
                    }
                    else
                    {
                        string errorString = $"Can't decode {positionAthleteData[0]}/{positionAthleteData[1]}";
                        HandicapProgressMessage message =
                            new HandicapProgressMessage(
                                errorString);

                        Messenger.Default.Send(
                            new HandicapProgressMessage(
                                errorString));

                        logger.WriteLog(errorString);
                    }
                }
                else
                {
                    string errorString = "Please check results, result/barcode pair invalid";
                    Messenger.Default.Send(
                        new HandicapProgressMessage(
                            errorString));
                    logger.WriteLog(errorString);
                }
            }

            rawImportedPositions =
                rawImportedPositions
                .OrderBy(position => position.Position)
                .ToList();

            return(rawImportedPositions);
        }