Example #1
0
        internal void AddToXmlNode(XmlDocument doc, XmlElement node)
        {
            var horse = doc.CreateElement("horse");

            horse.SetAttribute("program-number", ProgramNumber);
            horse.SetAttribute("name", Name);
            horse.SetAttribute("moring-line-odds", string.Format("{0:0.00}",MorningLineOdds));
            horse.SetAttribute("jockey", Jockey);
            horse.SetAttribute("jockey-stats", JockeyStatistics);
            horse.SetAttribute("trainer", Trainer);
            horse.SetAttribute("trainer-stats", TrainerStatistics);
            horse.SetAttribute("jockey-trainer-stats", JockeyTrainerStatistics);
            horse.SetAttribute("prime-power", PrimePower.ToString());
            horse.SetAttribute("days-off", DaysOff.ToString());
            horse.SetAttribute("long-lay-off", ComingFromLongLayOff ? "1" : "0");
            horse.SetAttribute("lay-off", ComingFromLayOff ? "1" : "0");
            horse.SetAttribute("second-off-lay-off", SecondOfLayoff ? "1" : "0");
            horse.SetAttribute("third-off-lay-off", ThirdOfLayoff ? "1" : "0");
            horse.SetAttribute("first-time-out", FirstTimeOut ? "1" : "0");
            horse.SetAttribute("life-record", LifeTimeRecord);
            horse.SetAttribute("cur-year-record", CurrentYearRecord);
            horse.SetAttribute("pre-year-record", PreviousYearRecord);
            horse.SetAttribute("track-record", TodaysTrackRecord);
            horse.SetAttribute("wet-record", WetTrackRecord);
            horse.SetAttribute("turf-record", TurfTrackRecord);
            horse.SetAttribute("distance-record", TodaysDistanceRecord);
            horse.SetAttribute("color-age-sex", ColorAgeAndSex);
            horse.SetAttribute("sire-name", SireName);
            horse.SetAttribute("dam-sire-name",Dam);
            horse.SetAttribute("claiming-price", string.Format("{0:0}",ClaimingPrice));
            horse.SetAttribute("owner",Owner);
            horse.SetAttribute("owner-silks",OwnerSilks);
            horse.SetAttribute("quirin-speed-points", string.Format("{0:0}",QuirinSpeedPoints));
            horse.SetAttribute("running-style",RunningStyle);
            horse.SetAttribute("weight",MedicationAndWeight);
            horse.SetAttribute("post-position", PostPosition.ToString());

            var handicappinFactorsNode = doc.CreateElement("handicapping-factors");
            _handicappingFactors.ForEach(hf => hf.AddToXmlNode(doc, handicappinFactorsNode));

            var ppNode = doc.CreateElement("past-performances");
            _pastPerformances.ForEach(pp => pp.AddToXmlNode(doc, ppNode));

            var sireNode = doc.CreateElement("sire");

            if(null == this.Sire)
            {
                Sire = new SippSire();
            }

            Sire.AddToXmlNode(doc, sireNode);

            var damSireNode = doc.CreateElement("dam-sire");
            if (null == this.DamSire)
            {
                DamSire = new SippSire();
            }

            DamSire.AddToXmlNode(doc, damSireNode);

            horse.AppendChild(handicappinFactorsNode);
            horse.AppendChild(ppNode);
            horse.AppendChild(sireNode);
            horse.AppendChild(damSireNode);
            node.AppendChild(horse);
        }
Example #2
0
        public string CreateSippDailyCard(ShowMessageDelegate showMessage)
        {
            var sdc = SippDailyCard.Make(Utilities.MakeDateTime(_date), TrackCode);

            var jockeys = new List<string>();

            foreach (var race in _race)
            {
                showMessage(string.Format("Processing race number: {0}",race.RaceNumber));

                var r = SippRace.Make(race.RaceNumber,
                                      race.CorrespondingBrisRace.DistanceInYards,
                                      race.CorrespondingBrisRace.Surface,
                                      race.CorrespondingBrisRace.RaceClassification);

                foreach (var horse in race.Horses)
                {
                    if(!horse.Scratched)
                    {
                        showMessage(string.Format("Processing race number: {0} horse number {1}", race.RaceNumber,horse.ProgramNumber));

                        string jockey = horse.CorrespondingBrisHorse.Jockey;
                        string trainer = horse.CorrespondingBrisHorse.TrainersFullName;

                        if(!jockeys.Contains(jockey))
                        {
                            jockeys.Add(jockey);
                        }

                        var h = SippHorse.Make(horse.ProgramNumber,
                                               horse.Name,
                                               horse.MorningLineOdds.GetOddsToOne(),
                                               jockey,
                                               Utilities.CapitalizeOnlyFirstLetter(trainer),
                                               horse.CorrespondingBrisHorse.PrimePowerRating);

                        h.DaysOff = horse.CorrespondingBrisHorse.DaysSinceLastRace;
                        h.ComingFromLongLayOff = horse.FirstAfterLongLayoff;
                        h.ComingFromLayOff = horse.FirstAfterLayoff;
                        h.SecondOfLayoff = horse.SecondAfterLayoff;
                        h.ThirdOfLayoff = horse.ThirdAfterLayoff;
                        h.FirstTimeOut = horse.CorrespondingBrisHorse.IsFirstTimeOut;
                        h.HandicappingFactors.Clear();

                        h.JockeyStatistics = FactorStatisticManager.GlobalStatisticsPerJockey(jockey).ToString();
                        h.TrainerStatistics = FactorStatisticManager.GlobalStatisticsPerTrainer(trainer).ToString();
                        h.JockeyTrainerStatistics = FactorStatisticManager.GlobalStatisticsPerTrainerAndJockey(trainer, jockey).ToString();

                        /////  Records
                        h.LifeTimeRecord= horse.CorrespondingBrisHorse.LifeTimeEarnings;
                        h.CurrentYearRecord= horse.CorrespondingBrisHorse.CurrentYearEarnings;
                        h.PreviousYearRecord= horse.CorrespondingBrisHorse.PreviousYearEarnings;
                        h.TodaysTrackRecord= horse.CorrespondingBrisHorse.TodaysTrackEarnings;
                        h.WetTrackRecord= horse.CorrespondingBrisHorse.WetTrackEarnings;
                        h.TurfTrackRecord = horse.CorrespondingBrisHorse.TurfTrackEarnings;
                        h.TodaysDistanceRecord = horse.CorrespondingBrisHorse.TodaysDistanceEarnings;
                        h.ColorAgeAndSex = horse.CorrespondingBrisHorse.ColorAgeAndSex;
                        h.SireName = horse.CorrespondingBrisHorse.SireInfo;
                        h.Dam = horse.CorrespondingBrisHorse.DamInfo;
                        h.ClaimingPrice = horse.CorrespondingBrisHorse.ClaimingPriceOfTheHorse;
                        h.Owner = horse.CorrespondingBrisHorse.Owner;
                        h.OwnerSilks = horse.CorrespondingBrisHorse.OwnersSilks;
                        h.QuirinSpeedPoints = horse.CorrespondingBrisHorse.QuirinSpeedPoints;
                        h.RunningStyle = horse.CorrespondingBrisHorse.BrisRunStyle;
                        h.MedicationAndWeight = horse.CorrespondingBrisHorse.MedicationAndWeight;
                        h.PostPosition = horse.FinalPosition;

                        ////// Add sire info //////////////////////////
                        string sire1 = horse.CorrespondingBrisHorse.Sire;
                        string sire2 = horse.CorrespondingBrisHorse.DamSire;

                        int i = 0;
                        foreach (DataRow dr in Sire.GetSiresInfo(sire1, sire2).Rows)
                        {
                            var sippSire = new SippSire
                                               {
                                                   Name = dr["Name"].ToString(),
                                                   FirstTimeOutRating = dr["FTS"].ToString(),
                                                   MudRating = dr["MUD"].ToString(),
                                                   TurfRating = dr["TURF"].ToString(),
                                                   AllWeatherRating = dr["AWS"].ToString(),
                                                   AverageDistance = dr["DIST"].ToString()
                                               };

                            switch (i)
                            {
                                case 0:
                                    h.Sire = sippSire;
                                    break;
                                default:
                                    h.DamSire = sippSire;
                                    break;
                            }

                            ++i;
                        }

                        //////////////////////////////////////////////
                        foreach (var factorStatistic in horse.FactorStatisticsForHorse)
                        {
                            var sippHandicappingFactor = SippHandicappingFactor.Make(factorStatistic.Name);
                            sippHandicappingFactor.GeneralStats = SippHandicappingFactorStats.Make(factorStatistic.Starters,factorStatistic.WinPercent,factorStatistic.Roi, factorStatistic.IV);
                            var trainerStats = FactorStatisticManager.Get(factorStatistic.BitMask, horse.CorrespondingBrisHorse.TrainersFullName);
                            sippHandicappingFactor.TrainerStats = SippHandicappingFactorStats.Make(trainerStats.Starters, trainerStats.WinPercent, trainerStats.Roi, trainerStats.IV);
                            h.HandicappingFactors.Add(sippHandicappingFactor);
                        }

                        foreach (var pp in horse.CorrespondingBrisHorse.PastPerformances)
                        {
                            var sipp = new SippPastPerformance();

                            sipp.DaysSincePreviousRace = pp.DaysSinceLastRace;
                            sipp.DaysSinceTodaysRace = pp.DaysSinceThatRace ;
                            sipp.RacingDate = pp.Date;
                            sipp.RaceNumber = Convert.ToInt32(pp.RaceNumber);
                            sipp.TrackCode = pp.TrackCode;
                            sipp.TrackCondition = pp.TrackCondition;
                            sipp.Distance = pp.DistanceAbreviation;
                            sipp.DistanceInYards = pp.DistanceInYards;
                            sipp.AboutDistanceFlag = pp.AboutDistanceFlag;
                            sipp.Surface = pp.Surface;
                            sipp.RaceCondition = Utilities.FormatCondition(pp.RaceClassification, pp.IsStateBredRestrictedRace, pp.AgeSexRestrictions);
                            sipp.FirstCall = pp.LeadersFirstCall;
                            sipp.SecondCall = pp.LeadersSecondCall;
                            sipp.ThirdCall = pp.LeadersThirdCall;
                            sipp.FinalTime = pp.LeadersFinalCall;
                            sipp.WinnersFinalTime = pp.WinnersFinalTime;
                            sipp.ThisHorseFinalTime = pp.ThisHorseFinalTime;
                            sipp.PostPosition = Convert.ToInt32(pp.PostPosition);
                            sipp.FirstCallPosition = pp.FirstCallPosition;
                            sipp.SecondCallPosition = pp.SecondCallPosition;
                            sipp.ThirdCallPosition= pp.StretchCallPosition;
                            sipp.FinalPosition = pp.FinalPosition;
                            sipp.FirstCallLengthsBehind = pp.FirstCallDistanceFromLeader;
                            sipp.SecondCallLengthsBehind = pp.SecondCallDistanceFromLeader;
                            sipp.ThirdCallLengthsBehind = pp.StretchCallDistanceFromLeader  ;
                            sipp.FinalLengthsBehind = pp.FinalCallDistanceFromLeader;
                            sipp.TrackVariant = pp.TrackVariant;
                            sipp.SpeedFigure = pp.BrisSpeedRating;
                            sipp.Jockey = pp.Jockey.Length < 16 ? pp.Jockey : pp.Jockey.Substring(0, 15);
                            sipp.MedicationWeightEquipment = pp.Medication + pp.Weight + pp.Equipment;
                            sipp.Odds= pp.Odds;
                            sipp.FieldSize = Convert.ToInt32(pp.NumberOfEntrants);

                            sipp.WinnersName = Utilities.CapitalizeOnlyFirstLetter(pp.WinnersName);
                            sipp.SecondPlaceFinisherName = Utilities.CapitalizeOnlyFirstLetter(pp.SecondPlaceFinisherName);
                            sipp.ThirdPlaceFinisherName = Utilities.CapitalizeOnlyFirstLetter(pp.ThirdPlaceFinisherName);
                            h.PastPerformances.Add(sipp);
                        }

                        r.AddHorse(h);
                    }
                }

                sdc.AddRace(r);
            }

            //IEnumerable<ImpactValueStat> ImpactValues = JockeyStatistics.Get(jockey).AllStats,
            showMessage("Now Adding the Jockeys Stats");
            foreach (var jockey in jockeys)
            {
                showMessage(string.Format("adding jockey: {0} ", jockey));
                var s = sdc.GetJockeySummarizedStatistics(jockey);

                foreach (var ivs in JockeyStatistics.Get(jockey).AllStats)
                {
                    s.Add(new SippImpactValueStat
                              {
                                  Name = ivs.Name,
                                  IV = ivs.IV,
                                  Roi = ivs.ROI,
                                  Starters = ivs.Starters,
                                  WinPercentage = ivs.WinPercent
                              });
                }
            }

            if(!Directory.Exists(Utilities.SippFilesDirectory))
            {
                Directory.CreateDirectory(Utilities.SippFilesDirectory);
            }

            string filename = string.Format(@"{0}\sipp_{1}_{2}.xml", Utilities.SippFilesDirectory,TrackCode,_date);
            sdc.SaveToXml(filename);
            showMessage(string.Format("File {0} was created successfully", filename));
            return filename;
        }