Example #1
0
        public RaceInfo AddRaceInfo(string html, List <HorseInfo> horses)
        {
            DbContext();

            try
            {
                var regex             = new RaceInfoCname();
                var matchHolding      = regex.holding.Match(html);
                var matchRaceName     = regex.raceName.Match(html);
                var matchShippingTime = regex.shippingTime.Match(html);

                // Dateに時刻を加え、PKが重複しないようにする
                var shippingTime   = DateTime.Parse(matchShippingTime.Value).TimeOfDay;
                var matchDate      = regex.date.Match(html);
                var date           = DateTime.ParseExact(matchDate.Value, "yyyy年M月d日", CultureInfo.InvariantCulture) + shippingTime;
                var matchWeather   = regex.weather.Match(html);
                var matchBaba      = regex.baba.Match(html);
                var matchBabaState = regex.babaState.Match(html);
                var matchDistance  = regex.distance.Match(html);
                var matchAround    = regex.around.Match(html);

                // レースの出走条件
                var matchOldClass = regex.oldClass.Matches(html);
                var oldClass      = "";
                foreach (Match match in matchOldClass)
                {
                    var category = match.Groups["OldClass"].Value;
                    oldClass = string.Join(" ",
                                           Regex.Matches(category, "cell (category|class|rule|weight)\\\">(?<name>.*?)\\</div\\>", RegexOptions.Singleline)
                                           .Cast <Match>()
                                           .Select(match => match.Groups["name"].Value));
                }

                var raceDuplicateCheck = context.RaceInfo.SingleOrDefault(c => c.Date == date && c.ShippingTime == matchShippingTime.Value);

                if (raceDuplicateCheck != null)
                {
                    return(null);
                }
                {
                    var raceInfo = new RaceInfo()
                    {
                        Holding      = matchHolding.Value,
                        RaceName     = matchRaceName.Value,
                        Date         = date,
                        ShippingTime = matchShippingTime.Value,
                        Weather      = matchWeather.Value,
                        Baba         = matchBaba.Value,
                        BabaState    = matchBabaState.Value,
                        OldClass     = oldClass,
                        Distance     = matchDistance.Value,
                        Around       = matchAround.Value,
                    };
                    Debug.WriteLine($"Insert実行:{raceInfo.RaceName}");
                    context.Add(raceInfo);
                    context.SaveChanges();

                    // raceInfoが無ければ、PayBackはaddしない
                    var payBacks = new PayBackQuery().AddPayBack(html);

                    return(raceInfo);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                throw;
            }
        }
Example #2
0
        public RaceResult CreateRaceResults(string html, string dateHtml)
        {
            try
            {
                var regex             = new RaceResultsCName();
                var matchDate         = regex.date.Match(dateHtml);
                var matchShippingTime = regex.shippingTime.Match(dateHtml);
                var matchHolding      = regex.holding.Match(dateHtml);

                // Dateに時刻を加え、PKが重複しないようにする
                var shippingTime           = DateTime.Parse(matchShippingTime.Value).TimeOfDay;
                var matchPlace             = regex.place.Match(html);
                var matchWaku              = regex.waku.Match(html);
                var matchNum               = regex.num.Match(html);
                var matchHorse             = regex.horse.Match(html);
                var matchWeight            = regex.weight.Match(html);
                var matchJockey            = Regex.Replace(regex.jockey.Match(html).Value, @"<.*?>", "");
                var matchTime              = regex.time.Match(html);
                var matchArrivalDifference = regex.arrivalDifference.Match(html);
                var matchCorner            = regex.corner.Matches(html);
                var matchHalongTime        = regex.halongTime.Match(html);
                var matchHorseWeight       = regex.horseWeight.Match(html).Value.Replace("<span>", "");
                var matchTrainer           = regex.trainer.Match(html);
                var matchPop               = regex.pop.Match(html);
                var raceNameRegex          = new RaceInfoCname();
                var matchRaceName          = raceNameRegex.raceName.Match(dateHtml);

                var corner = "";
                foreach (Match match in matchCorner)
                {
                    var ulul = match.Groups["corner"].Value;
                    corner = string.Join(",",
                                         Regex.Matches(ulul, "順位\\\">(?<number>.*?)\\</li\\>", RegexOptions.Singleline)
                                         .Cast <Match>()
                                         .Select(match => match.Groups["number"].Value))
                             .Replace("&nbsp;", "");
                }

                // 人気順位のNullチェック。競争除外はNullになるため、変数に100をセット。int.Parseの例外を回避する
                int pop = string.IsNullOrEmpty(matchPop.Value) ? 100 : int.Parse(matchPop.Value);

                var raceResults = new RaceResult()
                {
                    Date         = DateTime.ParseExact(matchDate.Value, "yyyy年M月d日", CultureInfo.InvariantCulture) + shippingTime,
                    ShippingTime = matchShippingTime.Value,
                    Holding      = matchHolding.Value,
                    RaceName     = matchRaceName.Value,
                    Place        = matchPlace.Value,
                    Waku         = int.Parse(matchWaku.Value),
                    // Horseはシャドウプロパティ?らしい
                    Num               = int.Parse(matchNum.Value),
                    Weight            = matchWeight.Value,
                    Jockey            = matchJockey,
                    Time              = matchTime.Value,
                    ArrivalDifference = matchArrivalDifference.Value,
                    Corner            = corner,
                    HalongTime        = matchHalongTime.Value,
                    HorseWeight       = matchHorseWeight,
                    Trainer           = matchTrainer.Value,
                    Pop               = pop
                };
                return(raceResults);
            }

            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                throw;
            }
        }