private bool IsHottie(Pitcher sp, PlayerGameLogViewModel gl) { if (sp.FantasyTeam.Equals("FA") && gl.EarnedRuns.Equals(0)) return true; return false; }
private void PlayerDump( PlayerGameLogViewModel totalLog, string p) { _weekReport.Player = p; _weekReport.PlayerSlug = string.Empty; _weekReport.WeekStarts = WeekStarts; _weekReport.Hitters = Hitters; _weekReport.JerseyNumber = _rosterMaster.JerseyNumber( FantasyTeam, p, Hitters); totalLog.Add(_weekReport.DumpWeek(0)); }
private void CalculateAverages(PlayerGameLogViewModel result) { result.BattingAverage += Utility.BattingAverage( result.Hits, result.AtBats); result.OpponentsBattingAverage = Utility.BattingAverage( result.HitsAllowed, result.OutsRecorded + result.HitsAllowed); result.WOBA = Utility.WOBA( walks: result.Walks, intentionalWalks: result.IntentionalWalks, hitByPitch: result.HitByPitch, singles: result.Singles, doubles: result.Doubles, triples: result.Triples, homeRuns: result.HomeRuns, atBats: result.AtBats, sacrifices: result.Sacrifices); }
public PlayerGameLogViewModel DumpSeason() { SetFantasyTeam(); var totalLog = new PlayerGameLogViewModel { HasGame = true }; var playerSlug = Utility.PlayerSlug(Player); for (int d = 0; d < (6 * 30); d++) { var queryDate = SeasonStarts.AddDays(d); if (queryDate.Equals(DateTime.Now.Date.AddDays(-1))) { break; } var logResult = _gameLogRepository.Submit( queryDate: queryDate, playerSlug: playerSlug); if (logResult.IsSuccess) { var log = logResult.Value; totalLog.Add(log); if (log.HasGame) { totalLog.IsPitcher = log.IsPitcher; totalLog.IsBatter = log.IsBatter; } if (d == 0) { DisplayHeading(log, _rosterMaster); } if (log.HasGame) { Console.WriteLine(log.DateLine()); } } } DisplayTotals(totalLog); return(totalLog); }
public decimal AbBySlug( string playerSlug, DateTime startDate, DateTime endDate) { var totalLog = new PlayerGameLogViewModel { HasGame = true, IsBatter = true, IsPitcher = false }; TallyLogs( startDate, endDate, totalLog, playerSlug); return(totalLog.AtBats); }
protected void DisplayHeading( PlayerGameLogViewModel log, IRosterMaster rosterMaster) { Console.WriteLine(log.HeaderLine()); Console.WriteLine($@"({ JerseyNumber }) { Player } { FantasyTeam } { rosterMaster.GetMlbTeam(Player) } { rosterMaster.GetPosition(Player) }" ); Console.WriteLine(log.HeaderLine()); Console.WriteLine(log.DateHeaderLine()); }
public decimal Woba( string playerName, DateTime startDate, DateTime endDate) { var totalLog = new PlayerGameLogViewModel { HasGame = true, IsBatter = true, IsPitcher = false }; var playerSlug = Utility.PlayerSlug(playerName); decimal stat = TallyLogs( startDate, endDate, totalLog, playerSlug); return(stat); }
public PlayerGameLogViewModel DumpSeason() { var totalLog = new PlayerGameLogViewModel { HasGame = true }; System.Collections.Generic.List <string> roster = GetRoster( _rosterMaster, FantasyTeam, SeasonStarts); foreach (var p in roster) { _seasonReport.Player = p; _seasonReport.SeasonStarts = SeasonStarts; // _seasonReport.JerseyNumber = _rosterMaster.BatterNumber(FantasyTeam, p); totalLog.Add(_seasonReport.DumpSeason()); } DisplayTotals(totalLog); return(totalLog); }
private decimal TallyLogs( DateTime startDate, DateTime endDate, PlayerGameLogViewModel totalLog, string playerSlug) { decimal stat; var daysToReport = DaysInRange( endDate, startDate); var queryDate = startDate; for (int d = 0; d < daysToReport; d++) { var result = _gameLogRepository.Submit( queryDate: queryDate, playerSlug: playerSlug); if (result.IsSuccess) { var log = result.Value; totalLog.Add(log); if (log.HasGame) { totalLog.IsPitcher = log.IsPitcher; totalLog.IsBatter = log.IsBatter; } } queryDate = queryDate.AddDays(1); if (queryDate.Equals(DateTime.Now.Date.AddDays(-1)) && Utility.ItsBeforeFour()) { break; } } ; totalLog.WOBA = totalLog.Woba(); stat = totalLog.WOBA; return(stat); }
private void MapLogStats( LogDto logDto, PlayerGameLogViewModel result) { result.IsPitcher = logDto.IsPitcher(); result.IsBatter = logDto.IsBatter(); result.GameStarted = Boolean.Parse(logDto.GameStarted); result.Hits += SetDecimal(logDto.Hits); result.HomeRuns += SetDecimal(logDto.HomeRuns); result.Runs += SetDecimal(logDto.Runs); result.RunsBattedIn += SetDecimal(logDto.RunsBattedIn); result.TotalBases += SetDecimal(logDto.TotalBases); result.Walks += SetDecimal(logDto.Walks); result.StrikeOuts += SetDecimal(logDto.StrikeOuts); result.StolenBases += SetDecimal(logDto.StolenBases); result.CaughtStealing += SetDecimal(logDto.CaughtStealing); result.AtBats += SetInt(logDto.AtBats); result.Era = SetDecimal(logDto.ERA); result.EarnedRuns += EarnedRuns(logDto); result.HitsAllowed += SetInt(logDto.HitsAllowed); result.OutsRecorded += SetInt(logDto.Outs); result.BattersStruckOut += SetInt(logDto.BattersStruckOut); result.WalksAllowed += SetInt(logDto.WalksAllowed); result.InningsPitched += SetDecimal(logDto.InningsPitched); result.Wins += SetInt(logDto.Wins); result.Losses += SetInt(logDto.Losses); result.Saves += SetInt(logDto.Saves); result.QualityStarts += SetInt(logDto.QualityStarts); result.Whip = SetDecimal(logDto.Whip); result.OBP = SetDecimal(logDto.OBP); result.OPS = SetDecimal(logDto.OPS); result.Singles += SetDecimal(logDto.Singles); result.Doubles += SetDecimal(logDto.Doubles); result.Triples += SetDecimal(logDto.Triples); result.IntentionalWalks += SetDecimal(logDto.IntentionalWalks); result.HitByPitch += SetDecimal(logDto.HitByPitch); result.Sacrifices += SetDecimal(logDto.SacrificeFlys) + SetDecimal(logDto.SacrificeHits); }
public PlayerGameLogViewModel DumpWeek(int playerNo) { SetOutput(); DateLine(); var totalLog = new PlayerGameLogViewModel { HasGame = true, IsPitcher = !Hitters, IsBatter = Hitters }; var roster = GetRoster( _rosterMaster, FantasyTeam, WeekStarts); foreach (var p in roster) { PlayerDump(totalLog, p); } DisplayTotals(totalLog); CloseOutput(); return(totalLog); }
public Result <PlayerGameLogViewModel> Submit( DateTime queryDate, string playerSlug) { var result = new PlayerGameLogViewModel { AsOf = queryDate }; HttpWebRequest httpWebRequest = SetQueryParams( queryDate, playerSlug); HttpWebResponse httpResponse; try { httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); } catch (Exception ex) { if (ex.Message.Contains("404")) { var errMsg = $"Cant find {playerSlug}"; Console.WriteLine(errMsg); return(Result.Fail <PlayerGameLogViewModel>(errMsg)); } else { return(Result.Fail <PlayerGameLogViewModel>( ex.Message)); } } using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var json = streamReader.ReadToEnd(); var dto = JsonConvert.DeserializeObject <GameLogDto>(json); Teams = dto.Teams; Logs = dto.Logs; } if (Logs.Count > 0) { // can play a double header for (int i = 0; i < Logs.Count; i++) { if (!EmptyLog(Logs[i])) { result.HasGame = true; } MapLogStats(Logs[i], result); } CalculateAverages(result); } result.AsOf = queryDate; result.Player = new Domain.Player { Name = playerSlug }; return(Result.Ok(result)); }
public PlayerGameLogViewModel DumpWeek(int playerNo) { SetOutput(); if (IncludePriorWeek) { WeekStarts = WeekStarts.AddDays(-7); } var totalLog = new PlayerGameLogViewModel { HasGame = true, IsBatter = Hitters, IsPitcher = !Hitters }; if (string.IsNullOrEmpty(PlayerSlug)) { PlayerSlug = Utility.PlayerSlug(Player); } FantasyTeam = _rosterMaster.GetOwnerOf(Player); if (playerNo > 0) { JerseyNumber = playerNo; } var daysToReport = 7; if (IncludePriorWeek) { daysToReport += 7; } for (int d = 0; d < daysToReport; d++) { var queryDate = WeekStarts.AddDays(d); if (queryDate.Equals(DateTime.Now.Date.AddDays(-1)) && Utility.ItsBeforeFour()) { break; } var result = _gameLogRepository.Submit( queryDate: queryDate, playerSlug: PlayerSlug); if (result.IsSuccess) { var log = result.Value; log.IsBatter = Hitters; log.IsPitcher = !Hitters; totalLog.Add(log); if (log.HasGame) { totalLog.IsPitcher = log.IsPitcher; totalLog.IsBatter = log.IsBatter; } if (d == 0) { DisplayHeading(log, _rosterMaster); } Console.WriteLine(log.DateLine()); } } DisplayTotals(totalLog); CloseOutput(); return(totalLog); }
protected static void DisplayTotals(PlayerGameLogViewModel totalLog) { Console.WriteLine(totalLog.HeaderLine()); Console.WriteLine(totalLog.DateLine("Total")); Console.WriteLine(totalLog.HeaderLine()); }