public void AddParsedResult(int raceIndex, ResultParsed parsedResult, int scores = 0)
        {
            Result result = new Result(parsedResult)
            {
                Scores = scores
            };

            Results.Add(raceIndex, result);
            this.Rank      = parsedResult.Rank;
            this.Nick      = parsedResult.Nick;
            HasEnoughRaces = true;

            IsCalculated = false;
        }
 public Result(ResultParsed resultParsed)
 {
     Id             = resultParsed.Id;
     Nick           = resultParsed.Nick;
     RealPlace      = resultParsed.RealPlace.Value;
     Time           = resultParsed.Time.Value;
     Speed          = resultParsed.Speed.Value;
     ErRate         = resultParsed.ErRate.Value;
     ErCnt          = resultParsed.ErCnt.Value;
     IsRecord       = resultParsed.IsRecord;
     Rank           = resultParsed.Rank;
     Mode           = resultParsed.Mode;
     Progress       = resultParsed.Progress;
     HasLeftRace    = resultParsed.HasLeftRace;
     Mileage        = resultParsed.Mileage;
     NoErrorFail    = resultParsed.NoErrorFail;
     PointsIncrease = resultParsed.PointsIncrease;
     SymbolsCnt     = Speed * Time.TotalMinutes;
 }
Exemple #3
0
        private RaceParsingResult ParseRace(string html)
        {
            var result = new RaceParsingResult
            {
                PlayerResults = new List <ResultParsed>(),
                RaceInfo      = new RaceInfo()
            };

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);

            HtmlNode gameTypeSpan = doc.DocumentNode.SelectSingleNode("//td[@id='gamedesc']/span");
            string   modeId       = gameTypeSpan.GetAttributeValue("class", "0").Replace("gametype-", "");
            var      SpanA        = gameTypeSpan.SelectSingleNode("a");

            string modeName;

            if (SpanA == null) //станд режим
            {
                modeName = gameTypeSpan.InnerText;
            }
            else // словарь
            {
                modeId  += "-" + Regex.Match(SpanA.GetAttributeValue("href", "0"), "\\d+");
                modeName = SpanA.InnerText;
            }
            result.RaceInfo.Mode = new Mode(modeId, modeName);

            result.RaceInfo.BookAuthor = doc.DocumentNode.SelectSingleNode("//div[@id='bookinfo']//div[@class='author']")?.InnerText;
            result.RaceInfo.BookName   = doc.DocumentNode.SelectSingleNode("//div[@id='bookinfo']//div[@class='name']")?.InnerText;

            HtmlNode totalPlayersNode = doc.DocumentNode.SelectSingleNode("//div[@id='players-count-lbl']/span");

            if (!string.IsNullOrEmpty(totalPlayersNode?.InnerText))
            {
                var match = Regex.Match(totalPlayersNode.InnerText, @"\d+");
                if (match.Success)
                {
                    result.RaceInfo.TotalPlayers = int.Parse(match.Value);
                }
            }

            HtmlNode pointsIncreaseNode = doc.DocumentNode.SelectSingleNode("//div[@id='players-count-lbl']/b");
            int      pointsIncrease     = 0;

            if (!string.IsNullOrEmpty(pointsIncreaseNode?.InnerText))
            {
                var match = Regex.Match(pointsIncreaseNode.InnerText, @"\d+");
                if (match.Success)
                {
                    pointsIncrease = int.Parse(match.Value);
                }
            }

            HtmlNodeCollection players = doc.DocumentNode.SelectNodes("//div[@class='player other ng-scope']");

            if (players != null)
            {
                players.Add(doc.DocumentNode.SelectSingleNode("//div[@class='player you ng-scope']"));// ng-scope
            }
            else
            {
                players = doc.DocumentNode.SelectNodes("//div[@class='player you ng-scope']");
            }

            foreach (HtmlNode player in players)
            {
                ResultParsed resultParsed = new ResultParsed();
                resultParsed.Mode           = new Mode(modeId, modeName);
                resultParsed.PointsIncrease = pointsIncrease;

                HtmlNode rating = player.SelectSingleNode("div[@class='rating']");
                HtmlNode car    = player.SelectSingleNode("table[@class='car']");
                HtmlNode place  = rating.SelectSingleNode("div/ins");
                HtmlNode nick   = player.SelectSingleNode("table//a");
                if (nick != null)
                {
                    resultParsed.Nick = nick != null ? nick.InnerText : "Гость";
                    string id_str = nick.GetAttributeValue("href", "0");
                    resultParsed.Id   = int.Parse(Regex.Match(id_str, "[0-9]+").ToString());
                    resultParsed.Rank = Rank.GetByIndex(int.Parse(nick.GetAttributeValue("class", "000000").Substring(4, 1)));
                }
                else
                {
                    continue;
                    //result.Nick = "Гость";
                    //result.Id = 0;
                    //result.Rank = Rank.GetByIndex(0);
                }

                if (place != null)
                {
                    string place_str = place.InnerText;
                    resultParsed.RealPlace = int.Parse(place_str.Substring(0, place_str.Length - 6));
                    resultParsed.Time      = TimeSpan.Parse("00:" + rating.SelectSingleNode("div[@class='stats']/div").InnerText.Replace(" ", "").Replace("\r", "").Replace("\n", ""));
                    resultParsed.Speed     = (int)Math.Round(double.Parse(rating.SelectSingleNode("div[@class='stats']/div[2]/span").InnerText, new NumberFormatInfo()
                    {
                        NumberDecimalSeparator = ","
                    }));
                    resultParsed.ErCnt  = int.Parse(rating.SelectSingleNode("div[@class='stats']/div[3]/span").InnerText);
                    resultParsed.ErRate = double.Parse(rating.SelectSingleNode("div[@class='stats']/div[3]/span[2]").InnerText, new NumberFormatInfo()
                    {
                        NumberDecimalSeparator = ","
                    }) / 100;
                    result.RaceInfo.ArrivedPlayers++;
                }

                if (player.SelectSingleNode("div[@class='newrecord']//span[@class='']") != null)
                {
                    resultParsed.IsRecord = true; //рекорд с записью или без
                }
                int.TryParse(Regex.Match(car.GetAttributeValue("style", ""), "(?<=left: )\\d+(?=px)").ToString(), out int progress);
                resultParsed.Progress = (int)(progress / 4.8);
                //result.finished = progress >= 100; //style="top: 0px; left: 480px; "

                HtmlNode _imgcont = car.SelectSingleNode(".//div[@class='imgcont']");
                HtmlNode _left    = car.SelectSingleNode(".//div[@class='imgcont leave']");
                resultParsed.HasLeftRace = _left != null;

                HtmlNode _noerror_fail = car.SelectSingleNode(".//img[@class='noerror-fail']");
                resultParsed.NoErrorFail = _noerror_fail != null;

                HtmlNode _i_style = car.SelectSingleNode(".//i");
                if (_i_style != null)
                {
                    int.TryParse(Regex.Match(_i_style.GetAttributeValue("title", ""), "\\d+").ToString(), out int _mileage);
                    resultParsed.Mileage = _mileage;
                }
                result.PlayerResults.Add(resultParsed);
            }
            return(result);
        }