Beispiel #1
0
        private bool UpdatePlayer(PlayerEnhanced plr, string gameId)
        {
            bool isNew        = true;
            int  replaceIndex = -1;

            for (int i = 0; i < PlayersEnhanced.Count; i++)
            {
                if (plr.Player.playerID == PlayersEnhanced[i].Player.playerID)
                {
                    isNew        = false;
                    replaceIndex = i;
                    break;
                }
            }

            if (isNew)
            {
                plr.GamesPlayedIn.Add(gameId);
                PlayersEnhanced.Add(plr);
                Console.WriteLine($"New Player Created - {plr.Player.playerID}");
                return(true);
            }
            else if (!PlayersEnhanced[replaceIndex].GamesPlayedIn.TryGetValue(gameId, out string value))
            {
                PlayersEnhanced[replaceIndex].GameStats.Add(plr.GameStats[0]);
                PlayersEnhanced[replaceIndex].GamesPlayedIn.Add(gameId);
                Console.WriteLine($"Existing Player Updated - {plr.Player.playerID}");
                return(true);
            }
            else
            {
                Console.WriteLine($"Existing Player duplicate, no update - {plr.Player.playerID}");
                return(false);
            }
        }
Beispiel #2
0
 public FantasyPoints(PlayerEnhanced player, int lastX = int.MaxValue)
 {
     PlayerId    = player.Player.playerID;
     this.player = player;
     this.lastX  = Math.Min(lastX, player.GameStats.Count());
     Init();
 }
Beispiel #3
0
        private void UpdatePlayerData(DateTime date)
        {
            string     dateString = date.ToString("yyyy-MM-dd");
            ConfigFile file       = new ConfigFile(true);

            if (file.ScheduleDaysLoaded.Contains(dateString))
            {
                return;
            }
            Schedule sched = new Schedule(dateString);
            bool     save  = true;

            if (sched.games != null)
            {
                foreach (Game game in sched.games)
                {
                    List <Player> plrs = game.gameParticipants;
                    if (plrs != null && plrs.Count > 0)
                    {
                        Dictionary <int, int> plrsIndex = Player.PlayerIdToIndexVault(plrs);
                        BoxScore bs = game.gameBoxScore;
                        List <PlayerGameStats> playerGameStats = bs.awayTeamStats.teamPlayers.Concat(bs.homeTeamStats.teamPlayers).ToList();
                        for (int i = 0; i < playerGameStats.Count(); i++)
                        {
                            PlayerEnhanced plrE = new PlayerEnhanced();
                            int            index;
                            plrsIndex.TryGetValue(playerGameStats[i].playerID, out index);
                            plrE.Player = plrs[index];
                            plrE.GameStats.Add(playerGameStats[i]);
                            UpdatePlayer(plrE, game.gameID);
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine($"gameParticipants found to be null or empty. File not saved for {dateString}");
                        save = false;
                    }
                }
                if (save)
                {
                    this.SaveToFile();
                    file.ScheduleDaysLoaded.Add(dateString);
                    file.SaveToFile();
                }
            }
        }