コード例 #1
0
 public static bool teamMatch(TeamAppearance team, string teamHint)
 {
     return
         (
         teamHint == null ||
         team.Team.Name == teamHint ||
         team.Team.Code == teamHint ||
         team.Team.FullName.Contains(teamHint)
         );
 }
コード例 #2
0
        static TeamAppearance ParseTeamAppearance(JObject game, string homeOrAway, DateTime day)
        {
            var appearance = new TeamAppearance()
            {
                Date     = day,
                Team     = ParseTeam(game, homeOrAway),
                Pitchers = ParseTeamPitchers(game, homeOrAway, day),
                Batters  = ParseTeamBatters(game, homeOrAway, day),
            };

            return(appearance);
        }
コード例 #3
0
        static TeamAppearance ParseTeamAppearance(JObject game, string homeOrAway, DateTime day)
        {
            var appearance = new TeamAppearance()
            {
                Date = day,
                Team = ParseTeam(game, homeOrAway)
            };
            var starter = ParseStarter(game, homeOrAway, day);

            if (starter != null)
            {
                appearance.Pitchers.Add(starter);
            }
            return(appearance);
        }
コード例 #4
0
        public static Dictionary <int, TeamAppearance> Parse(JObject standings)
        {
            if (standings == null)
            {
                return(null);
            }
            var results   = new Dictionary <int, TeamAppearance>();
            var rootToken = standings.SelectToken("historical_standings_schedule_date.standings_all_date_rptr.standings_all_date");

            if (rootToken == null || rootToken.Type != JTokenType.Array)
            {
                Logger.Warn("No standings data or non-array, returning empty standings");
                return(results);
            }
            var allEntries = (rootToken as JArray).SelectMany(league => league.SelectTokens("queryResults.row")).SelectMany(e => e.Children());

            foreach (var entry in allEntries)
            {
                TeamAppearance appearance = ParseTeamStandings(entry);
                results.Add(appearance.Team.TeamId, appearance);
            }
            return(results);
        }
コード例 #5
0
ファイル: ScoreboardData.cs プロジェクト: Nolan-Ramsden/MlbDb
        private static async Task ReplaceDuplicates(this MlbDatabase db, TeamAppearance appearance, Dictionary <int, Batter> batterSet, Dictionary <int, Pitcher> pitcherSet)
        {
            // Replace player entries
            appearance.Batters = appearance.Batters.GroupBy(b => b.Batter.BatterId).Select(g => g.First()).ToList();
            var batterIDs       = appearance.Batters.Select(b => b.Batter.BatterId);
            var existingBatters = (await db.Batters.Where(b => batterIDs.Contains(b.BatterId))
                                   .ToListAsync())
                                  .ToDictionary(b => b.BatterId, b => b);

            foreach (var batter in appearance.Batters)
            {
                batter.Batter = batterSet[batter.Batter.BatterId];
                if (existingBatters.ContainsKey(batter.Batter.BatterId))
                {
                    var existingBatter = existingBatters[batter.Batter.BatterId];
                    if ((existingBatter.HeightInches <= 0 || existingBatter.WeightPounds <= 0) &&
                        (batter.Batter.HeightInches > 0 && batter.Batter.WeightPounds > 0))
                    {
                        existingBatter.Bats            = batter.Batter.Bats;
                        existingBatter.FirstName       = batter.Batter.FirstName;
                        existingBatter.LastName        = batter.Batter.LastName;
                        existingBatter.HeightInches    = batter.Batter.HeightInches;
                        existingBatter.JerseyNumber    = batter.Batter.JerseyNumber;
                        existingBatter.NaturalPosition = batter.Batter.NaturalPosition;
                        existingBatter.Throws          = batter.Batter.Throws;
                        existingBatter.WeightPounds    = batter.Batter.WeightPounds;
                    }
                    batter.Batter = existingBatter;
                }
            }

            appearance.Pitchers = appearance.Pitchers.GroupBy(p => p.Pitcher.PitcherId).Select(g => g.First()).ToList();
            var pitcherIDs       = appearance.Pitchers.Select(p => p.Pitcher.PitcherId);
            var existingPitchers = (await db.Pitchers.Where(p => pitcherIDs.Contains(p.PitcherId))
                                    .ToListAsync())
                                   .ToDictionary(p => p.PitcherId, p => p);

            foreach (var pitcher in appearance.Pitchers)
            {
                pitcher.Pitcher = pitcherSet[pitcher.Pitcher.PitcherId];
                if (existingPitchers.ContainsKey(pitcher.Pitcher.PitcherId))
                {
                    var existingPitcher = existingPitchers[pitcher.Pitcher.PitcherId];
                    if ((existingPitcher.HeightInches <= 0 || existingPitcher.WeightPounds <= 0) &&
                        (pitcher.Pitcher.HeightInches > 0 && pitcher.Pitcher.WeightPounds > 0))
                    {
                        existingPitcher.FirstName    = pitcher.Pitcher.FirstName;
                        existingPitcher.LastName     = pitcher.Pitcher.LastName;
                        existingPitcher.HeightInches = pitcher.Pitcher.HeightInches;
                        existingPitcher.JerseyNumber = pitcher.Pitcher.JerseyNumber;
                        existingPitcher.Throws       = pitcher.Pitcher.Throws;
                        existingPitcher.WeightPounds = pitcher.Pitcher.WeightPounds;
                    }
                    pitcher.Pitcher = existingPitcher;
                }
            }

            // Replace team entry
            var existingTeam = await db.Teams.SingleOrDefaultAsync(t => t.TeamId == appearance.Team.TeamId);

            if (existingTeam != null)
            {
                appearance.Team = existingTeam;
            }
        }
コード例 #6
0
        private async Task DetailTeam(Game game, JToken teamJson)
        {
            var lastGame = await Snapshot.Database.GetTeamsLastGameBeforeDate(teamJson["Team"]["TeamId"].Value <int>(), game.Date);

            if (lastGame == null)
            {
                Logger.Warn("No last game for {0}", teamJson["Team"]["Name"]);
                return;
            }
            Logger.Debug("Last game for {0} was {1} hours ago", teamJson["Team"]["Name"], (game.Date.Subtract(lastGame.Date).TotalHours));
            var lastGameJson = JObject.FromObject(lastGame);

            // find if I was home or away last game and update as needed
            Team           me           = null;
            TeamAppearance myAppearance = null;
            bool           IWasHome     = lastGame.Home.Team.TeamId == teamJson["Team"]["TeamId"].Value <int>();

            if (IWasHome)
            {
                me                   = lastGame.Home.Team;
                myAppearance         = lastGame.Home;
                lastGameJson["Me"]   = lastGameJson["Home"];
                lastGameJson["Them"] = lastGameJson["Away"];
            }
            else
            {
                me                   = lastGame.Away.Team;
                myAppearance         = lastGame.Away;
                lastGameJson["Me"]   = lastGameJson["Away"];
                lastGameJson["Them"] = lastGameJson["Home"];
            }
            lastGameJson["Away"].Parent.Remove();
            lastGameJson["Home"].Parent.Remove();
            teamJson["LastGame"] = lastGameJson;

            // time change and time since last game + bullpen rest
            var roadData = await Snapshot.Database.GetRoadData(me.TeamId, game.Date);

            teamJson["Rest"] = JObject.FromObject(new
            {
                HoursSinceLastGame          = game.Date.Subtract(lastGame.Date).TotalHours,
                HoursTimeChangeFromLastGame = (int)game.Location.Timezone - (int)lastGame.Location.Timezone,
                HoursTimeChangeFromHomeTown = (int)game.Location.Timezone - (int)me.Timezone,
                LastGameTotalInnings        = lastGame.Result.Innings.Count,
                DaysOnRoad             = roadData.DaysInARow,
                RecentPercentageOnRoad = roadData.PercentageOfLast,
                LastGameBullpenOuts    = myAppearance.Pitchers.Sum(p => p.StatLine.Outs) - myAppearance.StartingPitcher.StatLine.Outs,
                RecentBullpenOuts      = roadData.RecentBullpenOuts,
            });

            // detail out the starting pitcher with some extra stuff since it wont be here yet
            var startingP      = teamJson["StartingPitcher"];
            var pitcherIdToken = startingP?.SelectToken("Pitcher.PitcherId");

            if (startingP != null && pitcherIdToken != null)
            {
                var lastOuting = await Snapshot.Database.GetPitchersLastAppearance(pitcherIdToken.Value <int>(), game.Date);

                if (lastOuting != null)
                {
                    teamJson["StartingPitcherDetailed"] = JObject.FromObject(lastOuting);
                }
                else
                {
                    Logger.Warn("No previous pitcher entry for {0}", startingP["Pitcher"]["FullName"].Value <string>());
                }
            }
            else
            {
                Logger.Warn("No starting pitcher entry");
            }
        }