private double GetTeamAveragePriorToTheStartOfTheWeek(IEnumerable<WeeklyScore> weeklyScores, IEnumerable<Player> players, Week week) { TeamStats teamStats = new TeamStats(); double average = teamStats.GetTeamAverage(weeklyScores, players, week.WeekNumber - 1); return average; }
public void UpdatePointsForTeam(IEnumerable<WeeklyScore> team1Scores, IEnumerable<WeeklyScore> team2Scores, Week currentWeek, Team team1, Team team2, IEnumerable<Player> players) { List<Player> team1Players = players.Where(p => p.Team.Equals(team1)).ToList(); IEnumerable<Player> team2Players = players.Where(p => p.Team.Equals(team2)); double team1Average = GetTeamAveragePriorToTheStartOfTheWeek(team1Scores, team1Players, currentWeek); double team2Average = GetTeamAveragePriorToTheStartOfTheWeek(team2Scores, team2Players, currentWeek); Handicap handicap = new Handicap(); double team1Handicap = handicap.GetHandicap(team1Average, team2Average); double team2Handicap = handicap.GetHandicap(team2Average, team1Average); double team1Points = 0; double team2Points = 0; double team1Game1 = team1Scores.Where(s => s.Week.WeekNumber == currentWeek.WeekNumber).Sum(s => s.Game1); double team1Game2 = team1Scores.Where(s => s.Week.WeekNumber == currentWeek.WeekNumber).Sum(s => s.Game2); double team1Game3 = team1Scores.Where(s => s.Week.WeekNumber == currentWeek.WeekNumber).Sum(s => s.Game3); double team1Total = team1Scores.Where(s => s.Week.WeekNumber == currentWeek.WeekNumber).Sum(s => s.Total); double team2Game1 = team2Scores.Where(s => s.Week.WeekNumber == currentWeek.WeekNumber).Sum(s => s.Game1); double team2Game2 = team2Scores.Where(s => s.Week.WeekNumber == currentWeek.WeekNumber).Sum(s => s.Game2); double team2Game3 = team2Scores.Where(s => s.Week.WeekNumber == currentWeek.WeekNumber).Sum(s => s.Game3); double team2Total = team2Scores.Where(s => s.Week.WeekNumber == currentWeek.WeekNumber).Sum(s => s.Total); CalculatePointsPerRule(team1Game1, team1Handicap, team2Game1, team2Handicap, ref team1Points, ref team2Points); CalculatePointsPerRule(team1Game2, team1Handicap, team2Game2, team2Handicap, ref team1Points, ref team2Points); CalculatePointsPerRule(team1Game3, team1Handicap, team2Game3, team2Handicap, ref team1Points, ref team2Points); CalculatePointsPerRule(team1Total, team1Handicap*3, team2Total, team2Handicap*3, ref team1Points, ref team2Points); WeeklyPoint team1WeeklyPoint = team1.WeeklyPoints.FirstOrDefault(wp => wp.Week.Equals(currentWeek)); WeeklyPoint team2WeeklyPoint = team2.WeeklyPoints.FirstOrDefault(wp => wp.Week.Equals(currentWeek)); if (team1WeeklyPoint != null) { team1WeeklyPoint.Points = team1Points; } else { team1WeeklyPoint = new WeeklyPoint {Points = team1Points, Week = currentWeek}; team1.WeeklyPoints.Add(team1WeeklyPoint); } if (team2WeeklyPoint != null) { team2WeeklyPoint.Points = team2Points; } else { team2WeeklyPoint = new WeeklyPoint {Points = team2Points, Week = currentWeek}; team2.WeeklyPoints.Add(team2WeeklyPoint); } }
public void Print(SummaryReportData summaryReportData, Week currentWeek) { Application excelApplication = new Application {Visible = true}; Workbook excelWorkbook = excelApplication.Workbooks.Add(1); Worksheet excelWorksheet = (Worksheet) excelWorkbook.Sheets[1]; int rowIndex = 1; excelWorksheet.Cells[rowIndex, 1] = "Strikers Bowling League"; rowIndex += 2; excelWorksheet.Cells[rowIndex, 1] = "Team Standings"; rowIndex++; excelWorksheet.Cells[rowIndex, 1] = "Team Name"; excelWorksheet.Cells[rowIndex, 2] = "Points"; rowIndex++; foreach (Team team in summaryReportData.Teams) { if (team.Name == "Sub") continue; List<WeeklyPoint> pointsPriorToThisWeek = team.WeeklyPoints.Where(p => p.Week.WeekNumber < currentWeek.WeekNumber).ToList(); double totalPoints = pointsPriorToThisWeek.Sum(p => p.Points); excelWorksheet.Cells[rowIndex, 1] = team.Name; excelWorksheet.Cells[rowIndex, 2] = totalPoints; rowIndex++; } rowIndex += 5; excelWorksheet.Cells[rowIndex, 1] = "Last Week"; excelWorksheet.Cells[rowIndex, 4] = "Year to Date"; rowIndex++; WriteIndividualHighGame(excelWorksheet, ref rowIndex, summaryReportData.LastWeekMensHighGames, summaryReportData.OverallMensHighGames, "M"); rowIndex++; WriteIndividualHighGame(excelWorksheet, ref rowIndex, summaryReportData.LastWeekWomensHighGames, summaryReportData.OverallWomensHighGames, "F"); rowIndex++; WriteIndividualHighSeries(excelWorksheet, ref rowIndex, summaryReportData.LastWeekMensHighSeries, summaryReportData.OverallMensHighSeries, "M"); rowIndex++; WriteIndividualHighSeries(excelWorksheet, ref rowIndex, summaryReportData.LastWeekWomensHighSeries, summaryReportData.OverallWomensHighSeries, "F"); }
private WeeklyScore CreateWeeklyScore(int game1, int game2, int game3, Player player, Team team, Week week) { WeeklyScore score = A.Fake<WeeklyScore>(); score.Game1 = game1; score.Game2 = game2; score.Game3 = game3; score.Player = player; score.Team = team; score.Week = week; return score; }
private List<GridPlayerViewModel> CreateAllGridPlayers(Week selectedWeek, IEnumerable<WeeklyScore> allScores) { List<WeeklyScore> scoresForWeek = allScores.Where(s => s.Week.WeekNumber == selectedWeek.WeekNumber).ToList(); List<GridPlayerViewModel> gridPlayerViewModels; if (scoresForWeek.Count == 0) { gridPlayerViewModels = (from player in _players where player.Team.Name != "Sub" select new GridPlayerViewModel { PlayerId = player.Id, PlayerName = player.Name, Players = new ObservableCollection<Player>(_players), TeamName = player.Team.Name, Teams = new ObservableCollection<Team>(_teams), SelectedPlayer = player, SelectedTeam = player.Team }).ToList(); } else { gridPlayerViewModels = scoresForWeek.Select( weeklyScore => new GridPlayerViewModel { Absent = weeklyScore.Absent, Game1 = weeklyScore.Game1, Game2 = weeklyScore.Game2, Game3 = weeklyScore.Game3, PlayerId = weeklyScore.Player.Id, PlayerName = weeklyScore.Player.Name, Players = new ObservableCollection<Player>(_players), SelectedPlayer = weeklyScore.Player, SelectedTeam = weeklyScore.Team, TeamName = weeklyScore.Team.Name, Teams = new ObservableCollection<Team>(_teams) }).ToList(); } return gridPlayerViewModels; }
private void SaveScores(Week week) { if (week == null) { return; } List<WeeklyScore> scores = (from gridPlayerViewModel in _gridPlayers let model = gridPlayerViewModel let player = _players.FirstOrDefault(p => p.Id == model.PlayerId) let team = _teams.FirstOrDefault(t => t.Name == model.TeamName) select new WeeklyScore { Absent = gridPlayerViewModel.Absent, Game1 = gridPlayerViewModel.Game1, Game2 = gridPlayerViewModel.Game2, Game3 = gridPlayerViewModel.Game3, Player = player, Team = team, Week = SelectedWeek }).ToList(); List<WeeklyScore> scoresToRemove = _allScores.Where(weeklyScore => weeklyScore.Week.WeekNumber == week.WeekNumber).ToList(); foreach (WeeklyScore weeklyScore in scoresToRemove) { _allScores.Remove(weeklyScore); } _allScores.AddRange(scores); TeamPoints teamPoints = new TeamPoints(); IEnumerable<WeeklyMatchup> thisWeeksMatchups = _matchups.Where(m => m.Week.Equals(SelectedWeek)); foreach (WeeklyMatchup weeklyMatchup in thisWeeksMatchups) { WeeklyMatchup matchup = weeklyMatchup; Team team1 = _teams.Find(t => t.Equals(matchup.TeamOne)); Team team2 = _teams.Find(t => t.Equals(matchup.TeamTwo)); List<WeeklyScore> team1Scores = _allScores.Where(s => s.Team.Equals(team1)).ToList(); List<WeeklyScore> team2Scores = _allScores.Where(s => s.Team.Equals(team2)).ToList(); teamPoints.UpdatePointsForTeam(team1Scores, team2Scores, SelectedWeek, team1, team2, _players); } }
private void LoadScoresForSelectedWeek(Week week) { List<WeeklyScore> scoresForWeek = _allScores.Where(s => s.Week.WeekNumber == week.WeekNumber).ToList(); List<GridPlayerViewModel> gridPlayerViewModels; if (scoresForWeek.Count == 0) { gridPlayerViewModels = (from player in _players where player.Team.Name != "Sub" select new GridPlayerViewModel { PlayerId = player.Id, PlayerName = player.Name, Players = new ObservableCollection<Player>(_players), TeamName = player.Team.Name, Teams = new ObservableCollection<Team>(_teams), SelectedPlayer = player, SelectedTeam = player.Team }).ToList(); } else { gridPlayerViewModels = scoresForWeek.Select( weeklyScore => new GridPlayerViewModel { Absent = weeklyScore.Absent, Game1 = weeklyScore.Game1, Game2 = weeklyScore.Game2, Game3 = weeklyScore.Game3, PlayerId = weeklyScore.Player.Id, PlayerName = weeklyScore.Player.Name, Players = new ObservableCollection<Player>(_players), SelectedPlayer = weeklyScore.Player, SelectedTeam = weeklyScore.Team, TeamName = weeklyScore.Team.Name, Teams = new ObservableCollection<Team>(_teams) }).ToList(); } InitializeGridPlayers(gridPlayerViewModels); }