コード例 #1
0
ファイル: Manager.cs プロジェクト: Puppetplay/BeThe2016
 public List<LineUp> MakeLineUp(Int64 matchId, BoxScore_W boxScore)
 {
     MatchInfo matchInfo = new MatchInfo();
     var homeLineUp = GetLineUp(matchId, boxScore.HomeHitter, AttackType.Home);
     var awayLineUp = GetLineUp(matchId, boxScore.AwayHitter, AttackType.Away);
     return homeLineUp.Concat(awayLineUp).ToList();
 }
コード例 #2
0
ファイル: Manager.cs プロジェクト: Puppetplay/BeThe2016
        private Th MakeTh(Match match, String content, Int32 number, MatchInfo matchInfo)
        {
            Th th = new Th();
            th.Number = number;

            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(content);
            var nodes = doc.DocumentNode.SelectNodes("//*[@class='tEx Ex2']");

            if (nodes == null)
            {
                return null;
            }
            if (nodes.Count > 0)
            {
                // 초공격
                th.AwayBats = MakeBatts(match, nodes[0].OuterHtml, number, matchInfo, ThType.초);
            }

            if (nodes.Count > 1)
            {
                // 말공격
                th.HomeBats = MakeBatts(match, nodes[1].OuterHtml, number, matchInfo, ThType.말);
            }

            if(th.AwayBats == null && th.HomeBats == null)
            {
                return null;
            }

            return th;
        }
コード例 #3
0
ファイル: Manager.cs プロジェクト: Puppetplay/BeThe2016
        private List<Th> MakeThs(Match match, Situation_W situation, MatchInfo matchInfo)
        {
            String[] separator = new String[] { "회" };
            List<Th> ths = new List<Th>();

            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(situation.Content);

            for (Int32 i = 1; i <= 12; ++i)
            {
                String id = String.Format("sms{0:D2}", i);
                var allNode = doc.DocumentNode.SelectSingleNode(String.Format("//*[@id='{0}']", id));

                if (allNode != null)
                {
                    var th = MakeTh(match, allNode.OuterHtml, i, matchInfo);
                    if (th != null)
                    {
                        ths.Add(th);
                    }
                }
            }
            return ths;
        }
コード例 #4
0
ファイル: Manager.cs プロジェクト: Puppetplay/BeThe2016
 private MatchInfo MakeMatchInfo(BoxScore_W boxScore)
 {
     MatchInfo matchInfo = new MatchInfo();
     matchInfo.HomeTeamPitcherInfos = GetPitcherInfos(boxScore.HomePitcher);
     matchInfo.AwayTeamPitcherInfos = GetPitcherInfos(boxScore.AwayPitcher);
     matchInfo.HomeTeamHitterInfos = GetBatterInfos(boxScore.HomeHitter);
     matchInfo.AwayTeamHitterInfos = GetBatterInfos(boxScore.AwayHitter);
     return matchInfo;
 }
コード例 #5
0
ファイル: Manager.cs プロジェクト: Puppetplay/BeThe2016
        private Bat MakeBat(String content, Int32 number, MatchInfo matchInfo, ThType type)
        {
            try
            {
                Bat bat = new Bat();
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(content);

                // Hitter Id 
                var node = doc.DocumentNode.SelectSingleNode("//*[@class='btn_detail detail_minus']");
                String item = node.GetAttributeValue("onclick", "");
                String[] items = item.Split(separatorComma, StringSplitOptions.RemoveEmptyEntries);
                bat.HitterId = Convert.ToInt32(items[1]);

                Int32 count = 0;
                List<PitcherInfo> pitcherInfos = null;
                List<HitterInfo> hitterInfos = null;
                if (type == ThType.초)
                {
                    pitcherInfos = matchInfo.HomeTeamPitcherInfos;
                    hitterInfos = matchInfo.AwayTeamHitterInfos;
                    count = matchInfo.AwayHitterCount++;
                }
                else
                {
                    pitcherInfos = matchInfo.AwayTeamPitcherInfos;
                    hitterInfos = matchInfo.HomeTeamHitterInfos;
                    count = matchInfo.HomeHitterCount++;
                }

                // Pitcher Id
                Int32 sum = 0;
                foreach (var pitcherInfo in pitcherInfos)
                {
                    sum += pitcherInfo.BatterCount;
                    if (count < sum)
                    {
                        bat.PitcherId = pitcherInfo.PlayerId;
                        break;
                    }
                }

                // 세부 결과
                node = doc.DocumentNode.SelectSingleNode("//td");
                var delNode = node.SelectSingleNode("//table");
                node.RemoveChild(delNode);
                delNode = node.SelectSingleNode("//span");
                node.RemoveChild(delNode);

                bat.DetailResult = node.InnerText.Trim();

                // 결과가 나지 않은 타석 제거
                String[] datas = bat.DetailResult.Split(separatorBlank, StringSplitOptions.RemoveEmptyEntries);
                if (datas.Count() == 4)
                {
                    if (datas[0] == datas[2] && datas[1] == datas[3])
                    {
                        if (type == ThType.초)
                        {
                            matchInfo.AwayHitterCount--;
                        }
                        else
                        {

                            matchInfo.HomeHitterCount--;
                        }
                        return null;
                    }
                }

                // 결과
                var hitterResults = (from p in hitterInfos
                                     where p.PlayerId == bat.HitterId
                                     select p.HitterResults).First();

                var hitterResult = (from r in hitterResults
                                    where r.Number == number
                                   select r).First();

                bat.Result = hitterResult.Result;

                //1 or 2 or 3 or 안 or 홈 으로끈나는것들
                //Pass -> '희' 포함 or 4구, 타방, 고4, 4구
                if (bat.Result.EndsWith("1") || bat.Result.EndsWith("2") || bat.Result.EndsWith("3")
                    || bat.Result.EndsWith("안") || bat.Result.EndsWith("홈"))
                {
                    bat.PResult = PResultType.Hit;
                }
                else if (bat.Result.EndsWith("희") || bat.Result.EndsWith("4구") || bat.Result.EndsWith("타방")
                    || bat.Result.EndsWith("고4"))
                {
                    bat.PResult = PResultType.Pass;
                }
                else
                {
                    bat.PResult = PResultType.Out;
                }

                hitterResults.Remove(hitterResult);

                // Balls 
                bat.Balls = MakeBalls(content);
                return bat;
            }
            catch(Exception e)
            {
                return null;
            }
        }
コード例 #6
0
ファイル: Manager.cs プロジェクト: Puppetplay/BeThe2016
        private List<Bat> MakeBatts(Match match, String content, Int32 number, MatchInfo matchInfo, ThType type)
        {
            List<Bat> bats = new List<Bat>();

            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(content);
            var nodes = doc.DocumentNode.SelectNodes("/table[@class='tEx Ex2']/tbody[1]/tr/td");

            if(nodes == null)
            {
                return null;
            }

            foreach (var node in nodes)
            {
                var bat = MakeBat(node.OuterHtml, number, matchInfo, type);
                if (bat != null)
                {
                    bats.Add(bat);
                }
            }

            return bats;
        }
コード例 #7
0
        private Bat MakeBat(String content, Int32 number, MatchInfo matchInfo, ThType type)
        {
            try
            {
                Bat          bat = new Bat();
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(content);

                // Hitter Id
                var      node  = doc.DocumentNode.SelectSingleNode("//*[@class='btn_detail detail_minus']");
                String   item  = node.GetAttributeValue("onclick", "");
                String[] items = item.Split(separatorComma, StringSplitOptions.RemoveEmptyEntries);
                bat.HitterId = Convert.ToInt32(items[1]);

                Int32 count = 0;
                List <PitcherInfo> pitcherInfos = null;
                List <HitterInfo>  hitterInfos  = null;
                if (type == ThType.초)
                {
                    pitcherInfos = matchInfo.HomeTeamPitcherInfos;
                    hitterInfos  = matchInfo.AwayTeamHitterInfos;
                    count        = matchInfo.AwayHitterCount++;
                }
                else
                {
                    pitcherInfos = matchInfo.AwayTeamPitcherInfos;
                    hitterInfos  = matchInfo.HomeTeamHitterInfos;
                    count        = matchInfo.HomeHitterCount++;
                }

                // Pitcher Id
                Int32 sum = 0;
                foreach (var pitcherInfo in pitcherInfos)
                {
                    sum += pitcherInfo.BatterCount;
                    if (count < sum)
                    {
                        bat.PitcherId = pitcherInfo.PlayerId;
                        break;
                    }
                }

                // 세부 결과
                node = doc.DocumentNode.SelectSingleNode("//td");
                var delNode = node.SelectSingleNode("//table");
                node.RemoveChild(delNode);
                delNode = node.SelectSingleNode("//span");
                node.RemoveChild(delNode);

                bat.DetailResult = node.InnerText.Trim();

                // 결과가 나지 않은 타석 제거
                String[] datas = bat.DetailResult.Split(separatorBlank, StringSplitOptions.RemoveEmptyEntries);
                if (datas.Count() == 4)
                {
                    if (datas[0] == datas[2] && datas[1] == datas[3])
                    {
                        if (type == ThType.초)
                        {
                            matchInfo.AwayHitterCount--;
                        }
                        else
                        {
                            matchInfo.HomeHitterCount--;
                        }
                        return(null);
                    }
                }

                // 결과
                var hitterResults = (from p in hitterInfos
                                     where p.PlayerId == bat.HitterId
                                     select p.HitterResults).First();

                var hitterResult = (from r in hitterResults
                                    where r.Number == number
                                    select r).First();

                bat.Result = hitterResult.Result;

                //1 or 2 or 3 or 안 or 홈 으로끈나는것들
                //Pass -> '희' 포함 or 4구, 타방, 고4, 4구
                if (bat.Result.EndsWith("1") || bat.Result.EndsWith("2") || bat.Result.EndsWith("3") ||
                    bat.Result.EndsWith("안") || bat.Result.EndsWith("홈"))
                {
                    bat.PResult = PResultType.Hit;
                }
                else if (bat.Result.EndsWith("희") || bat.Result.EndsWith("4구") || bat.Result.EndsWith("타방") ||
                         bat.Result.EndsWith("고4"))
                {
                    bat.PResult = PResultType.Pass;
                }
                else
                {
                    bat.PResult = PResultType.Out;
                }

                hitterResults.Remove(hitterResult);

                // Balls
                bat.Balls = MakeBalls(content);
                return(bat);
            }
            catch (Exception e)
            {
                return(null);
            }
        }