public async Task GatherAndWriteAllPlayerStats() { var path = Path.Combine(root_di.FullName, String.Format("Week_{0}", DateTime.Now.Iso8601WeekOfYear().ToString("D2"))); if (!Directory.Exists(path)) { data_di = Directory.CreateDirectory(path); } else { data_di = new DirectoryInfo(path); } var playersProcessed = 0; PopulateErrorList(); foreach (var player in _pg.ReadPlayerList()) { try { if (!File.Exists(Path.Combine(data_di.FullName, player.FileName)) && !_error_names.Contains(player.FullName)) // TODO: Check if an error file exists and parse out missing players to do similar checks { await WritePlayerData(player, await GatherPlayerData(player)); } } catch (WebException) { OnPlayerDownloadFailed(new DownloadingPlayerErrorEventArgs { Message = $"An error occured; the program could not download player data: {player.FullName}", TimeError = DateTime.Now, ErrorDirectory = data_di }); } finally { _progress?.Report(++playersProcessed); } _ct.ThrowIfCancellationRequested(); } }
public List <PlayerStats> PopulateAllPlayerStats() { var player_ids = _pg.ReadPlayerList(); var stat_list = new List <PlayerStats>(); foreach (var player in player_ids) { if (File.Exists(Path.Combine(_working_directory, player.FileName))) { var statDict = new StatisticsDictionary(_working_directory, _serializer); statDict.PopulatingPlayer += PopulatingAttempt; try { stat_list.Add(new PlayerStats() { player = player, stats = statDict.PopulateWithValuesForPlayer(player.FileName).Select(item => item.Value).OrderBy(n => n.Name).ToList() }); } catch (JsonReaderException) { OnPopulationFailure(new PopulatingStatsErrorEventArgs { Message = $"File was not in proper JSON format: {player.FileName}", TimeError = DateTime.Now, ErrorDirectory = new DirectoryInfo(_working_directory) }); } } } using (var dksalfile = new TextFieldParser(Path.Combine(_working_directory, "DKSalaries.csv"))) { dksalfile.TextFieldType = FieldType.Delimited; dksalfile.SetDelimiters(","); dksalfile.ReadLine(); // read the header line while (!dksalfile.EndOfData) { var fields = dksalfile.ReadFields(); var name = fields[1]; var salary = Double.Parse(fields[2]); var fpts = Double.Parse(fields[4]); var pl = stat_list.Where(p => p.player.FullName == name.Replace('-', ' ')); if (pl.Any()) { pl.First().AddDraftKingsStats(salary, fpts); } } } return(stat_list); }