internal static double AverageNetScoreForYear(this team team, year year) { var results = team.AllResultsForYear(year); if (results == null || results.Count() == 0) { return(0.0); } double totalScore = 0; int roundCount = 0; int value = 0; foreach (var result in results) { value = result.NetScoreDifference().Value; if (value < 60) { totalScore += value; roundCount++; } } if (roundCount == 0) { return(0.0); } return(totalScore / roundCount); }
public static double?AverageOpponentNetScoreForYear(this player player, year year, IEnumerable <result> results) { if (results == null || results.Count() == 0) { return(null); } double totalOpponentScore = 0; int opponentCount = 0; int value = 0; foreach (var result in results) { value = result.OpponentResult().NetScoreDifference().Value; if (value < 60) { totalOpponentScore += value; opponentCount++; } } if (opponentCount == 0) { return(0.0); } return((double)totalOpponentScore / (double)opponentCount); }
public static double AverageOpponentScoreForYear(this team team, year year) { var results = team.AllResultsForYear(year); if (results == null || results.Count() == 0) { return(0); } double totalScore = 0; double opponentCount = 0; foreach (var result in results) { int val = result.OpponentResult().ScoreDifference().Value; if (val < 60) { totalScore += val; opponentCount++; } } if (opponentCount == 0) { return(0.0); } return(totalScore / opponentCount); }
public static double AverageHandicapForYear(this team team, year year) { // Get all results for year var resultsForYear = team.AllResultsForYear(year); // Get all players for these results var playersWhichPlayedForYear = resultsForYear.Select(x => x.player).Where(x => x.validPlayer).GroupBy(x => x.id).Select(x => x.First()); // get year data for all players List <playeryeardata> yds = new List <playeryeardata>(); foreach (var player in playersWhichPlayedForYear) { var yd = player.playeryeardatas.FirstOrDefault(y => y.year.id == year.id); if (yd == null) { continue; } yds.Add(yd); } var handicapSum = yds.Sum(x => x.finishingHandicap); if (playersWhichPlayedForYear.Count() == 0) { return(0.0); } return((double)handicapSum / (double)playersWhichPlayedForYear.Count()); }
public static double AverageMarginOfNetVictoryForYear(this player player, year year, IEnumerable <result> results) { if (results == null || results.Count() == 0) { return(0.0); } double totalMargin = 0; int roundCount = 0; int playerValue = 0, oppValue = 0; foreach (var result in results) { playerValue = result.NetScoreDifference().Value; oppValue = result.OpponentResult().NetScoreDifference().Value; if (oppValue < 60) { totalMargin += oppValue - playerValue; roundCount++; } } if (roundCount == 0) { return(0.0); } return(totalMargin / roundCount); }
internal static double AverageMarginOfNetVictoryForYear(this team team, year year) { var results = team.AllResultsForYear(year); if (results == null || results.Count() == 0) { return(0.0); } double totalMargin = 0; int roundCount = 0; int playerValue = 0, oppValue = 0; foreach (var result in results) { playerValue = result.NetScoreDifference().Value; oppValue = result.OpponentResult().NetScoreDifference().Value; if (oppValue < 60) { totalMargin += oppValue - playerValue; roundCount++; } } if (roundCount == 0) { return(0.0); } return(totalMargin / roundCount); }
// TODO: is this a board that should not be processed without results? public static double RecordRatioForYear(this player player, year year, IEnumerable <result> results) { var record = player.RecordForYear(year, results); double totalWins = record[0] + ((double)record[2] / 2); int totalMatches = record[0] + record[1] + record[2]; return(totalMatches == 0 ? 0.0 : totalWins / (double)totalMatches); }
public RosterInitializer(IEnumerable <TeamRoster> rostersToInitialize, IEnumerable <player> allLeaguePlayers, year yearToInitialize) { this.playersLookup = allLeaguePlayers.ToDictionary(x => x.name.ToLowerInvariant()); this.rosters = rostersToInitialize; this.yearToInitialize = yearToInitialize; this.NewPlayers = this.IntializeRosters(); }
public static YearResponse From(year y) { return(new YearResponse { Id = y.id, IsComplete = y.isComplete, Value = y.value }); }
public static double?LowRoundForYear(this player player, year year, IEnumerable <result> results) { var bestScore = results.OrderBy(x => x.score).FirstOrDefault(); if (bestScore == null) { return(null); } return(bestScore.score.Value); }
public static List <player> AllPlayersForYear(this WestBlue westBlue, year year, bool includeResults = false, bool includeInvalidPlayers = false) { IQueryable <player> playersSet = westBlue.players; if (includeResults) { playersSet = playersSet.Include(x => x.results); } return(playersSet.Where(x => x.playeryeardatas.Any(y => y.year.id == year.id) && (includeInvalidPlayers || x.validPlayer)).ToList()); }
public static int TotalPointsForYear(this team team, year year) { var allResults = team.AllResultsForYear(year); int total = 0; foreach (var result in allResults) { total += result.points.Value; } return(total); }
public static int ImprovedInYear(this team team, year year) { int totalImproved = 0; var allPlayers = team.AllPlayersForYear(year); foreach (var p in allPlayers) { totalImproved += (int)p.ImprovedInYear(year); } return(totalImproved); }
public static double RecordRatioForYear(this team team, year year) { var record = team.RecordForYear(year); double totalWins = (double)record[0] + ((double)record[2] / 2.0); int totalWeeks = record[0] + record[1] + record[2]; if (totalWeeks == 0) { return(0.0); } return(totalWins / (double)totalWeeks); }
internal static double IndividualRecordRatioForYear(this team team, year year) { var record = team.IndividualRecordForYear(year); double totalWins = record[0] + ((double)record[2] / 2.0); double totalWeeks = record[0] + record[1] + record[2]; if (totalWeeks == 0) { return(0); } return(totalWins / totalWeeks); }
// TODO: is this a board that should not be processed without results? public static double AveragePointsInYear(this player player, year year, IEnumerable <result> results) { if (results == null || results.Count() == 0) { return(0.0); } int totalPoints = 0; foreach (var result in results) { totalPoints += result.points.Value; } return((double)totalPoints / (double)results.Count()); }
public IHttpActionResult AddYear([FromUri] bool addYear, [FromUri] int year) { var Years = (from y in _db.years where y.yearInt == year select new YearData { yearInt = y.yearInt }).ToList(); if (Years.FirstOrDefault() != null) { if (Years.FirstOrDefault().active == 1) { return(Ok()); } else { _db.years.Where(i => i.yearInt == year).FirstOrDefault().active = 1; _db.SaveChanges(); return(StatusCode(HttpStatusCode.Accepted)); } } else { var yeartoAdd = new year(); yeartoAdd.active = 1; yeartoAdd.yearInt = year; _db.years.Add(yeartoAdd); _db.SaveChanges(); } var YearsAdded = (from y in _db.years where y.yearInt == year select new YearData { yearInt = y.yearInt }).ToList(); if (YearsAdded.FirstOrDefault() != null) { return(Created("YearTable", year)); } else { return(InternalServerError()); } }
public static double?AverageNetScoreForYear(this player player, year year, IEnumerable <result> results) { if (results == null || results.Count() == 0) { return(null); } double totalRoundScore = 0; int roundCount = 0; foreach (var result in results) { totalRoundScore += result.NetScoreDifference().Value; roundCount++; } return((double)totalRoundScore / (double)roundCount); }
public static double?MostPointsInMatchForYear(this player player, year year, IEnumerable <result> results) { if (results == null || results.Count() == 0) { return(null); } int mostPoints = 0; foreach (var result in results) { if (result.points > mostPoints) { mostPoints = result.points.Value; } } return(mostPoints); }
public Date() { var d = DateTime.Now; var dn = Ico.getValue <db>().GetUnivdb().years.ToList().LastOrDefault(); // Where(Y => Y.year1.Year == d.Year).ToList().SingleOrDefault(); if (dn != null) { this._date = dn; } else { this._date = Ico.getValue <db>().GetUnivdb().years.Add(new year() { year1 = d }); Ico.getValue <db>().savedb(); } this._prev_date = Ico.getValue <db>().GetUnivdb().years.ToList().Where(Y => Y.year1.Year == (d.Year - 1)).ToList().SingleOrDefault(); }
private void CreateTeamYearData() { // first, create the year // TODO: remove hardcoded 2017. this.CreatedYear = new year { value = 2019, isComplete = false }; this.CreatedTeamYearDatas = new List <teamyeardata>(this.teams.Count); // create team year datas. foreach (team t in this.teams) { var tyd = new teamyeardata { team = t, year = this.CreatedYear }; //t.teamyeardata.Add(tyd); this.CreatedTeamYearDatas.Add(tyd); } }
public static double LowNetForYear(this player player, year year, IEnumerable <result> results) { // TODO: ask Mike what the significance of the 10 is. if (results == null || results.Count() == 0) { return(10); } int lowNet = 100; foreach (var result in results) { int netScoreDifference = result.NetScoreDifference().Value; if (netScoreDifference < lowNet) { lowNet = netScoreDifference; } } return(lowNet); }
internal static int MostPointsInWeekForYear(this team team, year year) { var results = team.AllResultsForYear(year); // group results by week var groupedResults = results.GroupBy(x => x.match.teammatchup.week.seasonIndex, x => x, (key, elements) => new { WeekId = key, Results = elements }); int max = 0; foreach (var r in groupedResults) { int total = r.Results.Select(x => x.points.Value).Sum(); if (total >= max) { max = total; } } return(max); }
public static int[] RecordForYear(this player player, year year, IEnumerable <result> results) { int wins = 0, losses = 0, ties = 0; foreach (var result in results) { if (result.WasWin()) { wins++; } else if (result.WasLoss()) { losses++; } else { ties++; } } return(new int[] { wins, losses, ties }); }
public static double[] IndividualRecordForYear(this team team, year year) { var results = team.AllResultsForYear(year); int wins = 0, losses = 0, ties = 0; foreach (var result in results) { if (result.WasWin()) { wins++; } else if (result.WasLoss()) { losses++; } else { ties++; } } return(new double[] { wins, losses, ties }); }
public static int[] RecordForYear(this team team, year year) { var allResults = team.AllResultsForYear(year); int wins = 0, losses = 0, ties = 0; int[] pointsForWeek = Enumerable.Repeat(0, 30).ToArray(); foreach (var result in allResults) { int seasonIndex = result.match.teammatchup.week.seasonIndex; pointsForWeek[seasonIndex] = pointsForWeek[seasonIndex] + result.points.Value; } foreach (int p in pointsForWeek) { if (p == 0) { continue; } if (p > 48) { wins++; } else if (p == 48) { ties++; } else if (p < 48) { losses++; } } return(new int[] { wins, losses, ties }); }
public override IEnumerable <result> AllResultsForYear(team t, year y) { return(t.AllResultsForYear(y)); }
public abstract IEnumerable <result> AllResultsForYear(T t, year y);
public double?DoCalculation(T t, year year, IEnumerable <result> results) { return(this.calc(t, year, results)); }
public override IEnumerable <result> AllResultsForYear(player p, year y) { return(p.AllResultsForYear(y)); }