예제 #1
0
        public List <BaseRider> Rank(
            string riderType,
            string raceName,
            string raceDiscipline,
            BikeRegData bikeRegData)
        {
            if (data.ContainsKey(riderType) == false)
            {
                log.Warn("Unknown rider type: " + riderType);
                return(new List <BaseRider>());
            }
            else if (NCCDataSource.DataSourceType.Equals(riderType) == false &&
                     USACDataSource.DataSourceType.Equals(riderType) == false &&
                     USACritsDataSource.DataSourceType.Equals(riderType) == false)
            {
                log.Warn("Unknown rider type: " + riderType);
                return(new List <BaseRider>());
            }

            //
            //  Loop through each row of the bike reg data, finding riders
            //  for this race.
            //

            List <BaseRider> rankedRiders  = new List <BaseRider>();
            List <BaseRider> unknownRiders = new List <BaseRider>();

            foreach (string row in bikeRegData.Rows(raceName))
            {
                bool      found      = false;
                string [] bikeRegRow = row.Split(',');

                BikeRegRider bikeRegRider = new BikeRegRider(row.Split(','));

                //
                //  Try to find the bike reg rider in the ranking engine data
                //

                log.Debug("Finding " + riderType + " rider: '" +
                          bikeRegRider.FirstName + "' '" +
                          bikeRegRider.LastName + "' [" +
                          bikeRegRider.License + "," +
                          bikeRegRider.ManualLicense + "] " +
                          bikeRegRider.EntryDate);

                foreach (BaseRider rankedRider in data[riderType])
                {
                    //log.Debug( "               '" + rider.FirstName + "' '" + rider.LastName + "'" );

                    if (USACDataSource.DataSourceType.Equals(riderType))
                    {
                        if (rankedRider.Discipline.Equals(raceDiscipline) == false)
                        {
                            continue;
                        }

                        //
                        //  Rank order is bikereg license, then manual
                        //

                        if (bikeRegRider.License.Equals(rankedRider.License))
                        {
                            found = true;

                            if (bikeRegRider.FirstName.Equals(rankedRider.FirstName) == false ||
                                bikeRegRider.LastName.Equals(rankedRider.LastName) == false)
                            {
                                log.Warn(" BIKEREG LICENSE [" + bikeRegRider.License + "] WITH NAME CONFLICT: [["
                                         + bikeRegRider.FirstName + "][" + rankedRider.FirstName + "]["
                                         + bikeRegRider.LastName + "][" + rankedRider.LastName + "]]");

                                bikeRegRider.Message = "BIKEREG LICENSE WITH NAME CONFLICT";
                            }
                            else
                            {
                                bikeRegRider.Message = "BIKEREG LICENSE";
                            }

                            bikeRegRider.Points = rankedRider.Points;
                            rankedRiders.Add(bikeRegRider);
                            break;
                        }
                        else if (bikeRegRider.ManualLicense.Equals(rankedRider.License))
                        {
                            found = true;

                            if (bikeRegRider.FirstName.Equals(rankedRider.FirstName) == false ||
                                bikeRegRider.LastName.Equals(rankedRider.LastName) == false)
                            {
                                log.Warn(" MANUAL LICENSE [" + bikeRegRider.ManualLicense + "] WITH NAME CONFLICT: [["
                                         + bikeRegRider.FirstName + "][" + rankedRider.FirstName + "]["
                                         + bikeRegRider.LastName + "][" + rankedRider.LastName + "]]");

                                bikeRegRider.Message = "MANUAL LICENSE WITH NAME CONFLICT";
                            }
                            else
                            {
                                bikeRegRider.Message = "MANUAL LICENSE";
                            }

                            bikeRegRider.Points  = rankedRider.Points;
                            bikeRegRider.License = bikeRegRider.ManualLicense;
                            rankedRiders.Add(bikeRegRider);
                            break;
                        }
                    }
                    else if (USACritsDataSource.DataSourceType.Equals(riderType) ||
                             NCCDataSource.DataSourceType.Equals(riderType))
                    {
                        //
                        //  Only find by name
                        //

                        if (bikeRegRider.FirstName.Equals(rankedRider.FirstName) == true &&
                            bikeRegRider.LastName.Equals(rankedRider.LastName) == true)
                        {
                            found = true;
                            bikeRegRider.Points  = rankedRider.Points;
                            bikeRegRider.Message = riderType + " FOUND BY NAME [" + rankedRider.Points + "]";
                            rankedRiders.Add(bikeRegRider);
                            break;
                        }
                        //else
                        //{
                        //    log.Debug( "    [[ " + firstName + " ][ " + rider.FirstName +
                        //               " ]] [[ " + lastName + " ][ " + rider.LastName + " ]]" );
                        //}
                    }
                }

                if (found == false)
                {
                    log.Warn("UNKNOWN " + riderType + " rider: '" +
                             bikeRegRider.FirstName + "' '" +
                             bikeRegRider.LastName + "' [" +
                             bikeRegRider.License + "," +
                             bikeRegRider.ManualLicense + "] " +
                             bikeRegRider.EntryDate);

                    if (USACDataSource.DataSourceType.Equals(riderType))
                    {
                        bikeRegRider.Points = "1000";

                        if (bikeRegRider.License.Equals(bikeRegRider.ManualLicense))
                        {
                            bikeRegRider.Message = "UNKNOWN LICENSE " + bikeRegRider.License;
                            unknownRiders.Add(bikeRegRider);
                        }
                        else if ("".Equals(bikeRegRider.License) == true &&
                                 "".Equals(bikeRegRider.ManualLicense) == false)
                        {
                            bikeRegRider.Message = "UNKNOWN MANUAL LICENSE " + bikeRegRider.ManualLicense;
                            bikeRegRider.License = bikeRegRider.ManualLicense;
                            unknownRiders.Add(bikeRegRider);
                        }
                        else if ("".Equals(bikeRegRider.License) == false &&
                                 "".Equals(bikeRegRider.ManualLicense) == true)
                        {
                            bikeRegRider.Message = "UNKNOWN BIKEREG LICENSE " + bikeRegRider.License;
                            unknownRiders.Add(bikeRegRider);
                        }
                        else if ("".Equals(bikeRegRider.License) == true &&
                                 "".Equals(bikeRegRider.ManualLicense) == true)
                        {
                            bikeRegRider.Message = "NO LICENSE";
                            unknownRiders.Add(bikeRegRider);
                        }
                        else
                        {
                            bikeRegRider.Message = "UNKNOWN LICENSE";
                            unknownRiders.Add(bikeRegRider);
                        }
                    }
                    else if (USACritsDataSource.DataSourceType.Equals(riderType) ||
                             NCCDataSource.DataSourceType.Equals(riderType))
                    {
                        bikeRegRider.Points  = "0";
                        bikeRegRider.Message = "UNKNOWN " + riderType;
                        unknownRiders.Add(bikeRegRider);
                    }
                }
            }

            //
            //  Sort the riders
            //

            if (USACDataSource.DataSourceType.Equals(riderType))
            {
                //
                //  USAC: lower is better
                //

                rankedRiders.Sort(new USACRankSort());
                unknownRiders.Sort(new EntryDateRankSort());
            }
            else if (USACritsDataSource.DataSourceType.Equals(riderType) ||
                     NCCDataSource.DataSourceType.Equals(riderType))
            {
                //
                //  NCC / USACrits: higher is better
                //

                rankedRiders.Sort(new NCCRankSort());
                unknownRiders.Sort(new EntryDateRankSort());
            }

            //
            //  Add the unknown riders to the end of the ranked riders
            //

            rankedRiders.AddRange(unknownRiders);

            //
            //  Assign race rank to each rider
            //

            for (int i = 0; i < rankedRiders.Count; i++)
            {
                rankedRiders[i].Rank = Convert.ToString(i + 1);
            }

            //
            //  Return the complete ranked rider list
            //

            return(rankedRiders);
        }
예제 #2
0
        public static int Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            try
            {
                if (args.Length != 1)
                {
                    log.Fatal("invalid command line parameters");
                    log.Fatal(" usage: rider_rank.exe [BikeReg Input File]");
                }

                //
                //  load configuration
                //

                RiderRankConfiguration configSection =
                    ConfigurationManager.GetSection("rider_rank_config")
                    as RiderRankConfiguration;

                DatePattern = configSection.DatetimeFormat;

                //
                //  Load the bikereg file
                //

                log.Info(" loading BikeReg data file: " + args[0]);
                BikeRegData bikeRegData = new BikeRegData(args[0]);
                bikeRegData.LoadData(true);

                for (int i = 0; i < configSection.BikeRegConfig.Count; i++)
                {
                    bikeRegData.AddColumn(
                        configSection.BikeRegConfig[i].Name,
                        configSection.BikeRegConfig[i].ColumnID);
                }

                //
                //  Load the ranking system
                //

                RankingEngine rankingEngine = new RankingEngine();

                for (int i = 0; i < configSection.RankSystemConfig.Count; i++)
                {
                    log.Info(" loading " + configSection.RankSystemConfig[i].Name +
                             " rider data from: " + configSection.RankSystemConfig[i].DataSource);

                    rankingEngine.LoadRiderData(
                        configSection.RankSystemConfig[i].RiderType,
                        configSection.RankSystemConfig[i].DataSource,
                        true);
                }

                //
                //  Iterate over each event and rank the riders
                //

                bool             top10Append     = false;
                List <BaseRider> rankedRiders    = new List <BaseRider>();
                List <BaseRider> allRankedRiders = new List <BaseRider>();

                for (int i = 0; i < configSection.EventsConfig.Count; i++)
                {
                    rankedRiders.Clear();

                    log.Info(" generating rider list for: " +
                             configSection.EventsConfig[i].Name);

                    if (configSection.EventsConfig[i].RiderType.Contains("COMPOSITE:") == true)
                    {
                        log.Debug(" composite rider types: " + configSection.EventsConfig[i].RiderType);

                        //
                        //  COMPOSITE RIDER: for each riderType rank as if
                        //  they were individual, and join into single list.
                        //

                        string    riderTypes          = configSection.EventsConfig[i].RiderType;
                        string [] compositeRiderTypes = riderTypes.Split(new Char [] { ':' });
                        string [] riderTypeArr        = compositeRiderTypes[1].Split(new Char [] { ',' });

                        log.Info(" rider types: " + compositeRiderTypes[1]);

                        foreach (string riderType in riderTypeArr)
                        {
                            log.Info(" ranking composite rider type: " + riderType);

                            //
                            //  Assign the composite riderType to the event
                            //

                            List <BaseRider> compositeRiders =
                                rankingEngine.Rank(riderType,
                                                   configSection.EventsConfig[i].Name,
                                                   configSection.EventsConfig[i].Discipline,
                                                   bikeRegData);

                            foreach (BaseRider compositeRider in compositeRiders)
                            {
                                bool found = false;
                                foreach (BaseRider rankedRider in rankedRiders)
                                {
                                    if (compositeRider.EqualsByFirstName(rankedRider) &&
                                        compositeRider.EqualsByLastName(rankedRider))
                                    {
                                        found = true;
                                        rankedRider.AddPoints(compositeRider.Points);
                                        rankedRider.Message += " | " + compositeRider.Message;
                                        break;
                                    }
                                }

                                if (found == false)
                                {
                                    rankedRiders.Add(compositeRider);
                                }
                            }

                            rankingEngine.SortRiderData(riderType, rankedRiders);
                        }

                        //
                        //  We now need to re-bib the rankedRider list
                        //

                        for (int j = 0; j < rankedRiders.Count; j++)
                        {
                            rankedRiders[j].Rank = Convert.ToString(j + 1);
                        }
                    }
                    else
                    {
                        rankedRiders.AddRange(rankingEngine.Rank(
                                                  configSection.EventsConfig[i], bikeRegData));
                    }

                    allRankedRiders.AddRange(rankedRiders);

                    //
                    //  Print out the rider rankings
                    //

                    using (StreamWriter outfile = new StreamWriter(
                               configSection.OutputDir + "\\" +
                               configSection.EventsConfig[i].Output))
                    {
                        outfile.WriteLine("POINTS,BIB_NUMBER,FIRST_NAME,LAST_NAME,CITY,STATE,TEAM,EMAIL,LICENSE,UCI_CODE,GENDER,AGE,CATEGORY,CATEGORY_ENTERED,ENTRY_DATE,MESSAGE");

                        foreach (BaseRider rider in rankedRiders)
                        {
                            outfile.WriteLine(rider.ToRankCSV());
                        }
                    }

                    //
                    //  Add ranked riders to top-10 file
                    //

                    using (StreamWriter outfile = new StreamWriter(
                               configSection.OutputDir + "\\TOP-10.csv", top10Append))
                    {
                        top10Append = true; // one shot
                        outfile.WriteLine(configSection.EventsConfig[i].Name);

                        for (int j = 0; j < rankedRiders.Count; j++)
                        {
                            outfile.WriteLine(rankedRiders[j].ToRankCSV());

                            if (j == 9)
                            {
                                break;
                            }
                        }

                        outfile.WriteLine();
                    }
                }

                //
                //  Print out all the rider rankings
                //

                using (StreamWriter outfile = new StreamWriter(
                           configSection.OutputDir + "\\REGISTRATION.csv"))
                {
                    outfile.WriteLine("POINTS,BIB_NUMBER,FIRST_NAME,LAST_NAME,CITY,STATE,TEAM,EMAIL,LICENSE,UCI_CODE,GENDER,AGE,CATEGORY,CATEGORY_ENTERED,ENTRY_DATE,MESSAGE");

                    foreach (BaseRider rider in allRankedRiders)
                    {
                        outfile.WriteLine(rider.ToRankCSV());
                    }
                }

                //
                //  List riders in multiple races
                //

                List <BikeRegRider> bikeRegRiders = bikeRegData.GetRidersByEvent("ALL");

                foreach (string evnt in bikeRegData.GetEvents())
                {
                    foreach (BikeRegRider eventRider in bikeRegData.GetRidersByEvent(evnt))
                    {
                        foreach (BikeRegRider rider in bikeRegRiders)
                        {
                            if (eventRider.EqualsByName(rider))
                            {
                                if (eventRider.EqualsByLicense(rider) == false)
                                {
                                    log.Warn("DUPLICATE RIDER NAME: " + eventRider.Name);
                                }
                                else
                                {
                                    rider.AddEvent(evnt);
                                    break;
                                }
                            }
                        }
                    }
                }

                using (StreamWriter outfile = new StreamWriter(
                           configSection.OutputDir + "\\" +
                           "MultiEventRiders.csv"))
                {
                    foreach (BikeRegRider rider in bikeRegRiders)
                    {
                        if (rider.Events.Count > 1)
                        {
                            log.Warn(rider.ToDataCSV());
                            outfile.WriteLine(rider.ToDataCSV( ));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Fatal("RiderRank error: ", ex);
                return(-1);
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
            return(0);
        }
예제 #3
0
 public List <BaseRider> Rank(EventElement race, BikeRegData bikeRegData)
 {
     return(Rank(race.RiderType, race.Name, race.Discipline, bikeRegData));
 }