Ejemplo n.º 1
0
        private static bool MatchToPQDamSpecial(string horse_name, string sire_name, int offspring_year_min,
                                                int offspring_year_max, ref string pqid, ref string match_basis)
        {
            foreach (string horse_match_id in pq_horse_lookup[horse_name])
            {
                PQHorse horse_match = pq_horses[horse_match_id];

                if (horse_match.FoalYear == null)
                {
                    continue;
                }

                bool   sires_available = sire_name != null && horse_match.SireName != null;
                double ld_sire         = LD.FuzzyMatch(sire_name, horse_match.SireName);
                bool   sire_match      = ld_sire >= 0.8;

                match_basis = null;
                if (sires_available && sire_match && horse_match.FoalYear <= offspring_year_min - 3 &&
                    horse_match.FoalYear >= offspring_year_max - 28)
                {
                    match_basis = "Dam Special";
                }

                if (match_basis != null)
                {
                    pqid = horse_match.Id;
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        private static bool MatchToPQByName(string horse_name, string sire_name, string dam_name, int?year,
                                            string country, ref string pqid, ref string match_basis)
        {
            foreach (string horse_match_id in pq_horse_lookup[horse_name])
            {
                PQHorse horse_match = pq_horses[horse_match_id];

                bool sires_available = sire_name != null && horse_match.SireName != null;
                bool dams_available  = dam_name != null && horse_match.DamName != null;
                bool years_available = year != null && horse_match.FoalYear != null;

                double ld_sire = LD.FuzzyMatch(sire_name, horse_match.SireName);
                double ld_dam  = LD.FuzzyMatch(dam_name, horse_match.DamName);

                bool sire_match  = ld_sire >= 0.8;
                bool dam_match   = ld_dam >= 0.8;
                bool year_match  = year != null && horse_match.FoalYear != null && year == horse_match.FoalYear;
                bool year_approx = year != null && horse_match.FoalYear != null &&
                                   Math.Abs((int)year - (int)horse_match.FoalYear) <= 3;
                bool country_match = country != null && horse_match.Country != null && country == horse_match.Country;

                match_basis = null;
                if (sires_available && dams_available && years_available && sire_match && dam_match && year_approx)
                {
                    match_basis = "Name, Sire Name, Dam Name, Year";
                }
                else if (!sires_available && dams_available && years_available && dam_match && year_match)
                {
                    match_basis = "Name, Dam Name, Year";
                }
                else if (sires_available && !dams_available && years_available && sire_match && year_match)
                {
                    match_basis = "Name, Sire Name, Year";
                }
                else if (sires_available && dams_available && !years_available && sire_match && dam_match)
                {
                    match_basis = "Name, Sire Name, Dam Name";
                }

                if (match_basis != null)
                {
                    pqid = horse_match.Id;
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        private static bool MatchToPQBySire(string sire_pqid, string horse_name, string sire_name, string dam_name,
                                            int?horse_year, string horse_country, ref string pqid, ref string match_basis)
        {
            if (dam_name == null || horse_year == null)
            {
                return(false);
            }

            List <PQHorse> p_sires = null;

            if (sire_pqid != null)
            {
                p_sires = new List <PQHorse> {
                    pq_horses[sire_pqid]
                };
            }
            else
            {
                p_sires = new List <PQHorse>();
                foreach (string p_sire_id in pq_horse_lookup[sire_name])
                {
                    p_sires.Add(pq_horses[p_sire_id]);
                }
            }

            foreach (PQHorse p_sire in p_sires)
            {
                IEnumerable <string> prog_ids = pq_sire_lookup[p_sire.Id];
                foreach (string prog_id in prog_ids)
                {
                    PQHorse prog = pq_horses[prog_id];
                    double  ld   = LD.FuzzyMatch(horse_name, prog.HorseName);

                    if (prog.DamName != null && prog.FoalYear != null)
                    {
                        double ld_dam = LD.FuzzyMatch(dam_name, prog.DamName);
                        if (ld_dam >= 0.8 && horse_year == prog.FoalYear)
                        {
                            pqid        = prog.Id;
                            match_basis = match_basis + ", Name, Dam Name, Year";
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        private static bool MatchToPPBySire(int?sire_ppid, string horse_name, string sire_name, string dam_name,
                                            int?horse_year, string horse_country, ref int?ppid, ref string match_basis)
        {
            if (dam_name == null || horse_year == null)
            {
                return(false);
            }

            List <PPHorse> p_sires = null;

            if (sire_ppid != null && pp_horses.ContainsKey((int)sire_ppid))
            {
                p_sires = new List <PPHorse> {
                    pp_horses[(int)sire_ppid]
                };
            }
            else
            {
                p_sires = new List <PPHorse>();
                foreach (int p_sire_id in pp_horse_lookup[sire_name])
                {
                    p_sires.Add(pp_horses[p_sire_id]);
                }
            }

            foreach (PPHorse p_sire in p_sires)
            {
                IEnumerable <int> prog_ids = pp_sire_lookup[p_sire.Id];
                foreach (int prog_id in prog_ids)
                {
                    PPHorse prog = pp_horses[prog_id];
                    double  ld   = LD.FuzzyMatch(horse_name, prog.HorseName);

                    bool temp_pp_name = false;
                    if (prog.OrigName.Contains("/"))
                    {
                        temp_pp_name = true;
                    }

                    var   regex = new Regex("'[0-9]{4}$");
                    Match match = regex.Match(prog.OrigName);
                    if (match.Success)
                    {
                        temp_pp_name = true;
                    }

                    if (ld < 0.8 && !temp_pp_name)
                    {
                        continue;
                    }

                    if (prog.DamName != null && prog.FoalYear != null)
                    {
                        double ld_dam = LD.FuzzyMatch(dam_name, prog.DamName);
                        if (ld_dam >= 0.8 && horse_year == prog.FoalYear)
                        {
                            ppid        = prog.Id;
                            match_basis = match_basis + ", Name, Dam Name, Year";
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }