protected object JSONGetScoreKeeperSchedule(string data, Dictionary <string, object> sessionData) { Dictionary <string, object> schedule = new Dictionary <string, object>(); string accessCode = getAccessCode(sessionData); CourtRound currentCourtRound = getCurrentCourtRound(accessCode); int? currentCourtRoundNum = null; if (currentCourtRound != null) { currentCourtRoundNum = currentCourtRound.RoundNumber; } List <int> startableCourtRoundNums = new List <int>(); int? activeCourtRoundNum = null; CourtRound activeCourtRound = Controller.Tournament.ActiveCourtRound; if (activeCourtRound != null) { activeCourtRoundNum = activeCourtRound.RoundNumber; } if (Controller.Tournament != null) { foreach (CourtRound courtRound in Controller.Tournament.CourtRounds) { string key = courtRound.RoundNumber.ToString(); object value; Game courtRoundGame = getGameInCourtRoundForAccessCode(courtRound, accessCode); if (courtRoundGame != null && courtRoundGame.Enabled) { value = new GameWebData(courtRoundGame); //This game can be manually started if (!courtRoundGame.IsCompleted) { startableCourtRoundNums.Add(courtRound.RoundNumber); } } else { value = new { NotAssigned = true } }; schedule.Add(key, value); } } return (new { Schedule = schedule, CurrentCourtRoundNum = currentCourtRoundNum, ActiveCourtRoundNum = activeCourtRoundNum, StartableCourtRoundNums = startableCourtRoundNums }); }
protected Game getGameInCourtRoundForAccessCode(CourtRound courtRound, string accessCode) { foreach (Game game in courtRound.Games) { if (game != null && game.ScoreKeeper != null && game.ScoreKeeper.AssociatedAccessCode == accessCode) { return(game); } } return(null); }
protected object JSONGetCurrentGame(string data, Dictionary <string, object> sessionData) { Game game = null; bool gameCompleted = false; bool notAssigned = false; int? currentRound = null; if (Controller.Tournament != null) { CourtRound activeCourtRound = Controller.Tournament.ActiveCourtRound; if (activeCourtRound != null) { Game activeCourtRoundGame = getGameInCourtRoundForAccessCode(activeCourtRound, getAccessCode(sessionData)); if (activeCourtRoundGame != null && !activeCourtRoundGame.IsCompleted) { game = activeCourtRoundGame; } else { notAssigned = activeCourtRoundGame == null; if (activeCourtRoundGame != null) { gameCompleted = activeCourtRoundGame.IsCompleted; } currentRound = activeCourtRound.RoundNumber; } } } object gameData = null; if (game != null && game.Enabled) { gameData = new GameWebData(game); } else { gameData = new { NotAssigned = notAssigned, GameCompleted = gameCompleted, CourtRoundNum = currentRound } }; return(gameData); }
protected CourtRound getCurrentCourtRound(string scoreKeeperAccessCode) { if (Controller.Tournament != null) { CourtRound activeCourtRound = Controller.Tournament.ActiveCourtRound; if (activeCourtRound != null) { Game courtRoundGame = getGameInCourtRoundForAccessCode(activeCourtRound, scoreKeeperAccessCode); if (courtRoundGame != null) { if (!courtRoundGame.IsCompleted) { return(activeCourtRound); } else { if (Controller.Tournament.CourtRounds.Count > activeCourtRound.RoundNumber) { CourtRound nextCourtRound = Controller.Tournament.CourtRounds[activeCourtRound.RoundNumber]; return(nextCourtRound); } else { return(null); } } } else { if (Controller.Tournament.CourtRounds.Count > activeCourtRound.RoundNumber) { CourtRound nextCourtRound = Controller.Tournament.CourtRounds[activeCourtRound.RoundNumber]; Game nextCourtRoundGame = getGameInCourtRoundForAccessCode(nextCourtRound, scoreKeeperAccessCode); if (nextCourtRoundGame != null) { Game gameOnNextCourt = null; if (activeCourtRound.Games.Count >= nextCourtRoundGame.CourtNumber) { gameOnNextCourt = activeCourtRound.Games[nextCourtRoundGame.CourtNumber - 1]; } if (gameOnNextCourt != null) { if (!gameOnNextCourt.IsCompleted) { return(activeCourtRound); } else { return(nextCourtRound); } } else { return(activeCourtRound); } } else { return(activeCourtRound); } } else { return(activeCourtRound); } } } } return(null); }
protected override void OnPrintPage(PrintPageEventArgs e) { base.OnPrintPage(e); if (Tournament == null) { return; } Graphics gdiPage = e.Graphics; Rectangle marginBounds = e.MarginBounds; int drawTop = marginBounds.Top; int drawLeft; //Header drawLeft = marginBounds.Left; Font headerFont = new Font(Font, FontStyle.Bold); StringFormat headerStringFormat = new StringFormat(); headerStringFormat.Alignment = StringAlignment.Center; headerStringFormat.LineAlignment = StringAlignment.Center; //Round number header RectangleF roundHeaderRect = new RectangleF( drawLeft, drawTop, roundColumnWidth, headerHeight); e.Graphics.FillRectangle(headerBackgroundBrush, roundHeaderRect); e.Graphics.DrawLine(headerSeparatorPen, new PointF(roundHeaderRect.Right - 1, roundHeaderRect.Top), new PointF(roundHeaderRect.Right - 1, roundHeaderRect.Bottom - 1)); e.Graphics.DrawString("Round", headerFont, textBrush, roundHeaderRect, headerStringFormat); drawLeft += roundColumnWidth; //Court headers int numCourts = Tournament.NumCourts; int courtColumnWidth = (int)Math.Floor((double)((marginBounds.Width - defaultRoundColumnWidth) / numCourts)); for (int courtNum = 0; courtNum < numCourts; courtNum++) { char courtLetter = Convert.ToChar((courtNum) + 65); string headerTitle = String.Format("Court {0}", courtLetter); RectangleF courtHeaderRect = new RectangleF( drawLeft, drawTop, courtColumnWidth, headerHeight); e.Graphics.FillRectangle(headerBackgroundBrush, courtHeaderRect); e.Graphics.DrawLine(headerSeparatorPen, new PointF(courtHeaderRect.Right - 1, courtHeaderRect.Top), new PointF(courtHeaderRect.Right - 1, courtHeaderRect.Bottom - 1)); e.Graphics.DrawString(headerTitle, headerFont, textBrush, courtHeaderRect, headerStringFormat); drawLeft += courtColumnWidth; } e.Graphics.DrawLine(headerSeparatorPen, new PointF(marginBounds.Left, roundHeaderRect.Bottom - 1), new PointF(marginBounds.Right, roundHeaderRect.Bottom - 1)); drawTop += headerHeight; //Draw each court round Font roundNumberFont = new Font(Font, FontStyle.Bold); StringFormat roundNumberStringFormat = new StringFormat(); roundNumberStringFormat.Alignment = StringAlignment.Center; roundNumberStringFormat.LineAlignment = StringAlignment.Far; while (drawTop + courtRoundHeight < marginBounds.Bottom && _courtRoundIndex < Tournament.CourtRounds.Count) { //Draw a single court round drawLeft = marginBounds.Left; CourtRound courtRound = Tournament.CourtRounds[_courtRoundIndex]; //Round number int roundNumberBottomSpacing = 5; RectangleF roundNumberRect = new RectangleF( drawLeft, drawTop, roundColumnWidth, courtRoundHeight); RectangleF roundNumberTextRect = roundNumberRect; roundNumberTextRect.Height -= roundNumberBottomSpacing; e.Graphics.FillRectangle(headerBackgroundBrush, roundNumberRect); e.Graphics.DrawLine(headerSeparatorPen, new PointF(roundNumberRect.Left, roundNumberRect.Bottom - 1), new PointF(roundNumberRect.Right - 1, roundNumberRect.Bottom - 1)); e.Graphics.DrawLine(headerSeparatorPen, new PointF(roundNumberRect.Right - 1, roundNumberRect.Top), new PointF(roundNumberRect.Right - 1, roundNumberRect.Bottom - 1)); e.Graphics.DrawString(courtRound.RoundNumber.ToString(), roundNumberFont, textBrush, roundNumberTextRect, roundNumberStringFormat); drawLeft += roundColumnWidth; //Games foreach (Game game in courtRound.Games) { RectangleF gameRectangle = new RectangleF( drawLeft, drawTop, courtColumnWidth, courtRoundHeight); if (game.Enabled) { Color gameFillColor = game.RobinRoundNum % 2 != 0 ? Color.FromArgb(255, 240, 215) : Color.White; e.Graphics.FillRectangle(new SolidBrush(gameFillColor), gameRectangle); int gamePadding = 2; int gameWidth = courtColumnWidth - gamePadding * 2; int gameHeight = courtRoundHeight - gamePadding * 2; int teamDrawTop = drawTop + gamePadding; int teamDrawLeft = drawLeft + gamePadding; int teamDrawHeight = gameHeight / game.NumTeams; foreach (Team team in game.Teams) { if (team != null) { if (team.Name != team.Id) { //Team id StringFormat teamIdStringFormat = new StringFormat(); teamIdStringFormat.Alignment = StringAlignment.Near; teamIdStringFormat.LineAlignment = StringAlignment.Center; Font teamIdFont = new Font(Font, FontStyle.Bold); RectangleF teamIdRect = new RectangleF( drawLeft + 2, teamDrawTop, e.Graphics.MeasureString(team.Id, teamIdFont).Width, teamDrawHeight); e.Graphics.DrawString(team.Id + " ", teamIdFont, textBrush, teamIdRect, teamIdStringFormat); //Team name StringFormat teamNameStringFormat = new StringFormat(); teamNameStringFormat.Alignment = StringAlignment.Near; teamNameStringFormat.LineAlignment = StringAlignment.Center; teamNameStringFormat.FormatFlags = StringFormatFlags.NoWrap; teamNameStringFormat.Trimming = StringTrimming.EllipsisCharacter; Font teamNameFont = new Font(Font, FontStyle.Regular); RectangleF teamNameRect = new RectangleF( teamIdRect.Right, teamDrawTop, gameWidth - teamIdRect.Width, teamDrawHeight); e.Graphics.DrawString(team.Name, teamNameFont, textBrush, teamNameRect, teamNameStringFormat); } else { //Team id StringFormat teamIdStringFormat = new StringFormat(); teamIdStringFormat.Alignment = StringAlignment.Near; teamIdStringFormat.LineAlignment = StringAlignment.Center; Font teamIdFont = new Font(Font, FontStyle.Bold); RectangleF teamIdRect = new RectangleF( drawLeft, teamDrawTop, gameWidth, teamDrawHeight); e.Graphics.DrawString(team.Id, teamIdFont, textBrush, teamIdRect, teamIdStringFormat); } } e.Graphics.DrawLine(gamesSeparatorPen, new PointF(gameRectangle.Right - 1, gameRectangle.Top), new PointF(gameRectangle.Right - 1, gameRectangle.Bottom - 1)); e.Graphics.DrawLine(gamesSeparatorPen, new PointF(gameRectangle.Left, gameRectangle.Bottom - 1), new PointF(gameRectangle.Right - 1, gameRectangle.Bottom - 1)); teamDrawTop += teamDrawHeight; } } drawLeft += courtColumnWidth; } //Prepare for next court round drawTop += courtRoundHeight; _courtRoundIndex++; } //If more court rounds exist, print another page. if (_courtRoundIndex < Tournament.CourtRounds.Count - 1) { e.HasMorePages = true; } else { e.HasMorePages = false; } }
private void DistributeTeamsAcrossCourts(Tournament tournament) { if (tournament.NumCourts < 2) { return; } Dictionary <Division, Dictionary <int, Dictionary <int, int> > > timesTeamsOnCourtByDivision = new Dictionary <Division, Dictionary <int, Dictionary <int, int> > >(); foreach (CourtRound courtRound in tournament.CourtRounds) { foreach (Game game in courtRound.Games) { if (!timesTeamsOnCourtByDivision.ContainsKey(game.Division)) { timesTeamsOnCourtByDivision.Add(game.Division, new Dictionary <int, Dictionary <int, int> >()); } Dictionary <int, Dictionary <int, int> > timesTeamsOnCourtForDivision = timesTeamsOnCourtByDivision[game.Division]; foreach (Team team in game.Teams) { if (!timesTeamsOnCourtForDivision.ContainsKey(team.NumId)) { timesTeamsOnCourtForDivision.Add(team.NumId, new Dictionary <int, int>()); } Dictionary <int, int> timesTeamOnCourt = timesTeamsOnCourtForDivision[team.NumId]; if (timesTeamOnCourt.ContainsKey(game.CourtNumber)) { timesTeamOnCourt[game.CourtNumber]++; } else { timesTeamOnCourt.Add(game.CourtNumber, 1); } } } } int largestDistributionDifference = int.MinValue; string largestDistributionDiffereceId = ""; foreach (KeyValuePair <Division, Dictionary <int, Dictionary <int, int> > > timesOnCourtForDivision in timesTeamsOnCourtByDivision) { Dictionary <int, int> MaxTimesOnCourt = new Dictionary <int, int>(); Dictionary <int, int> MinTimesOnCourt = new Dictionary <int, int>(); //Initilize the values for the FirstTimesOnCourt dictionary for (int i = 1; i <= tournament.NumCourts; i++) { MaxTimesOnCourt.Add(i, int.MinValue); MinTimesOnCourt.Add(i, int.MaxValue); } foreach (KeyValuePair <int, Dictionary <int, int> > timesOnCourtForTeam in timesOnCourtForDivision.Value) { foreach (KeyValuePair <int, int> timesOnCourtPair in timesOnCourtForTeam.Value) { int courtNumber = timesOnCourtPair.Key; int timesOnCourt = timesOnCourtPair.Value; if (timesOnCourt > MaxTimesOnCourt[courtNumber]) { MaxTimesOnCourt[courtNumber] = timesOnCourt; } if (timesOnCourt < MinTimesOnCourt[courtNumber]) { MinTimesOnCourt[courtNumber] = timesOnCourt; } } } for (int i = 1; i <= tournament.NumCourts; i++) { int difference = MaxTimesOnCourt[i] - MinTimesOnCourt[i]; if (difference > largestDistributionDifference) { largestDistributionDifference = difference; largestDistributionDiffereceId = "on " + CourtRound.CourtNumToCourtName(i) + " " + timesOnCourtForDivision.Key.Name; } } } if (largestDistributionDifference > 5) { Trace.WriteLine(GetTournamentId(tournament) + " - Largest team distribution difference: " + largestDistributionDifference.ToString() + "; " + largestDistributionDiffereceId); } }