private static MemberForAnnouncerJson CalculateBlockerStats(AnnouncerJson an, TeamNumberEnum team, GamePositionEnum position, Guid skaterId) { var blocker = new MemberForAnnouncerJson(); try { blocker.Name = NameFunctions.skaterName(team, position); blocker.Number = NameFunctions.skaterNumber(team, position); blocker.Jams = JamCalculations.jamCount(team, GamePositionEnum.L, skaterId); int pointsFor = JamCalculations.pointsFor(team, GamePositionEnum.L, skaterId); blocker.PointsPerJam = JamCalculations.blockerPointsPerJam(skaterId, team, GamePositionEnum.L).ToString("N2"); blocker.Points = pointsFor; blocker.PointsPerMinute = "0"; blocker.LeadJamPc = "0"; } catch (Exception exception) { ErrorViewModel.Save(exception, exception.GetType(), additionalInformation: Logger.Instance.getLoggedMessages()); } return blocker; }
private static MemberForAnnouncerJson CalculateJammerStats(AnnouncerJson an, TeamNumberEnum team, Guid skaterId) { var jammer = new MemberForAnnouncerJson(); try { jammer.Name = NameFunctions.skaterName(team, GamePositionEnum.J); jammer.Number = NameFunctions.skaterNumber(team, GamePositionEnum.J); jammer.PointsPerJam = JamCalculations.jammerPointsPerJam(skaterId, team).ToString("N2"); jammer.Jams = JamCalculations.jamCount(team, GamePositionEnum.J, skaterId); jammer.Points = JamCalculations.pointsFor(team, GamePositionEnum.J, skaterId); jammer.PointsPerMinute = JamCalculations.jammerPointsPerMinute(skaterId, GamePositionEnum.J, team).ToString("N2"); jammer.LeadJamPc = JamCalculations.leadJams(team, GamePositionEnum.J, skaterId).ToString("N1"); } catch (Exception exception) { ErrorViewModel.Save(exception, exception.GetType(), additionalInformation: Logger.Instance.getLoggedMessages()); } return jammer; }
public static string GetAnnouncerPage() { AnnouncerJson an = new AnnouncerJson(); try { if (GameViewModel.Instance.CurrentJam != null) { if (GameViewModel.Instance.Team1 != null) an.team1Name = GameViewModel.Instance.Team1.TeamName; if (GameViewModel.Instance.Team2 != null) an.team2Name = GameViewModel.Instance.Team2.TeamName; if (GameViewModel.Instance.CurrentJam.JammerT1 != null) an.JammerT1 = CalculateJammerStats(an, TeamNumberEnum.Team1, GameViewModel.Instance.CurrentJam.JammerT1.SkaterId); if (GameViewModel.Instance.CurrentJam.PivotT1 != null) an.PivotT1 = CalculateBlockerStats(an, TeamNumberEnum.Team1, GamePositionEnum.P, GameViewModel.Instance.CurrentJam.PivotT1.SkaterId); if (GameViewModel.Instance.CurrentJam.Blocker1T1 != null) an.Blocker1T1 = CalculateBlockerStats(an, TeamNumberEnum.Team1, GamePositionEnum.B1, GameViewModel.Instance.CurrentJam.Blocker1T1.SkaterId); if (GameViewModel.Instance.CurrentJam.Blocker2T1 != null) an.Blocker2T1 = CalculateBlockerStats(an, TeamNumberEnum.Team1, GamePositionEnum.B2, GameViewModel.Instance.CurrentJam.Blocker2T1.SkaterId); if (GameViewModel.Instance.CurrentJam.Blocker3T1 != null) an.Blocker3T1 = CalculateBlockerStats(an, TeamNumberEnum.Team1, GamePositionEnum.B3, GameViewModel.Instance.CurrentJam.Blocker3T1.SkaterId); if (GameViewModel.Instance.CurrentJam.Blocker4T1 != null) an.Blocker4T1 = CalculateBlockerStats(an, TeamNumberEnum.Team1, GamePositionEnum.B4, GameViewModel.Instance.CurrentJam.Blocker4T1.SkaterId); if (GameViewModel.Instance.CurrentJam.JammerT2 != null) an.JammerT2 = CalculateJammerStats(an, TeamNumberEnum.Team2, GameViewModel.Instance.CurrentJam.JammerT2.SkaterId); if (GameViewModel.Instance.CurrentJam.PivotT2 != null) an.PivotT2 = CalculateBlockerStats(an, TeamNumberEnum.Team2, GamePositionEnum.P, GameViewModel.Instance.CurrentJam.PivotT2.SkaterId); if (GameViewModel.Instance.CurrentJam.Blocker1T2 != null) an.Blocker1T2 = CalculateBlockerStats(an, TeamNumberEnum.Team2, GamePositionEnum.B1, GameViewModel.Instance.CurrentJam.Blocker1T2.SkaterId); if (GameViewModel.Instance.CurrentJam.Blocker2T2 != null) an.Blocker2T2 = CalculateBlockerStats(an, TeamNumberEnum.Team2, GamePositionEnum.B2, GameViewModel.Instance.CurrentJam.Blocker2T2.SkaterId); if (GameViewModel.Instance.CurrentJam.Blocker3T2 != null) an.Blocker3T2 = CalculateBlockerStats(an, TeamNumberEnum.Team2, GamePositionEnum.B3, GameViewModel.Instance.CurrentJam.Blocker3T2.SkaterId); if (GameViewModel.Instance.CurrentJam.Blocker4T2 != null) an.Blocker1T2 = CalculateBlockerStats(an, TeamNumberEnum.Team2, GamePositionEnum.B4, GameViewModel.Instance.CurrentJam.Blocker4T2.SkaterId); //two for loops to set out the rosters var rostah = GameViewModel.Instance.Team1.TeamMembers.OrderBy(x => x.SkaterName); an.PlayerStatsT1 = new List<LivePlayerStat>(); foreach (var member in rostah) { var p = CalculateLivePlayerStats(member, TeamNumberEnum.Team1); an.PlayerStatsT1.Add(p); } rostah = GameViewModel.Instance.Team2.TeamMembers.OrderBy(x => x.SkaterName); an.PlayerStatsT2 = new List<LivePlayerStat>(); foreach (var member in rostah) { { var p = CalculateLivePlayerStats(member, TeamNumberEnum.Team2); an.PlayerStatsT2.Add(p); } } an.currentJam = GameViewModel.Instance.CurrentJam.JamNumber; an.currentJamId = GameViewModel.Instance.CurrentJam.JamId; an.totalJams = GameViewModel.Instance.Jams.Count + 1; } else { if (GameViewModel.Instance.CurrentJam != null) { an.currentJam = 0; an.currentJamId = new Guid(); an.totalJams = 0; } } } catch (Exception exception) { ErrorViewModel.Save(exception, exception.GetType(), additionalInformation: Logger.Instance.getLoggedMessages()); } JavaScriptSerializer s = new JavaScriptSerializer(); return s.Serialize(an); }