From 60c5469942e94696d5fa87090ede075ea5b3f35f Mon Sep 17 00:00:00 2001 From: Anna Dodson Date: Tue, 5 Nov 2019 22:04:52 +0000 Subject: [PATCH] New Highest Stepper property on team scoreboard - So a team can see who is their highest stepper for the day, added a new bool property onto the team score board model - The participant or participants with the highest scores get the new `ParticipantHighestStepper` flag set to true - On the front end, add a new style class which underlines their initial and add a well done message into the title text - Closes issue #79 --- StepChallenge.Tests/TeamScoreboardTests.cs | 66 ++++++++++++++++++- StepChallenge.Tests/TeamTests.Data.cs | 34 ++++++++++ StepChallenge/ClientApp/src/App.css | 5 ++ .../src/components/TeamScoreboard.js | 2 +- .../ClientApp/src/components/TeamStep.js | 7 +- StepChallenge/DataModels/TeamScoreBoard.cs | 2 + .../Model/GraphQL/ParticipantStepStatus.cs | 1 + StepChallenge/Services/StepsService.cs | 3 +- StepChallenge/Services/TeamService.cs | 19 +++++- 9 files changed, 131 insertions(+), 8 deletions(-) diff --git a/StepChallenge.Tests/TeamScoreboardTests.cs b/StepChallenge.Tests/TeamScoreboardTests.cs index db8aaa9..f66c233 100644 --- a/StepChallenge.Tests/TeamScoreboardTests.cs +++ b/StepChallenge.Tests/TeamScoreboardTests.cs @@ -60,7 +60,71 @@ public void Test_TeamMembersStepStatus_IsFalseIfStepsTotalIsZero() Assert.IsFalse(resultFirstParticipantStepsStatus, $"Expected participant to have step status of False but got {resultFirstParticipantStepsStatus}"); } - + + /// + /// Tests that if a participant has the most steps, they are returned as the highest stepper + /// + [Test] + public void Test_TeamMembersStepStatus_ParticipantHasHighestScore() + { + var team = TestData.CreateTeamWithHighestStepper(); + + var teamService = new TeamService(GetMockStepContext(team)); + var result = teamService.GetTeamScoreBoard(1); + + var actual = false; + var participant = result.First().ParticipantsStepsStatus.SingleOrDefault(p => p.ParticipantId == 1); + if (participant != null) + { + actual = participant.ParticipantHighestStepper; + } + + Assert.IsTrue(actual, $"Expected participant to have highest step status of True but got {actual}"); + } + + /// + /// Tests that if two participants have the most steps, they are both returned as highest stepper set to true + /// + [Test] + public void Test_TeamMembersStepStatus_ParticipantHasHighestScoreIfStepsAreSame() + { + var team = TestData.CreateTeamWithHighestStepper(); + team.Participants.ElementAt(1).Steps.First().StepCount = team.Participants.ElementAt(0).Steps.First().StepCount; + + var teamService = new TeamService(GetMockStepContext(team)); + var result = teamService.GetTeamScoreBoard(1); + + var actualOne = false; + var actualTwo = false; + + var participantOne = result.First().ParticipantsStepsStatus.SingleOrDefault(p => p.ParticipantId == 1); + var participantTwo = result.First().ParticipantsStepsStatus.SingleOrDefault(p => p.ParticipantId == 1); + if (participantOne != null && participantTwo != null) + { + actualOne = participantOne.ParticipantHighestStepper; + actualTwo = participantTwo.ParticipantHighestStepper; + } + + Assert.IsTrue(actualOne && actualTwo, $"Expected participants to both have highest step status of True but got {actualOne} & {actualTwo}"); + } + + /// + /// Tests that if all participants have zero steps, there is no highest stepper + /// + [Test] + public void Test_TeamMembersStepStatus_ParticipantsWithZeroStepsAreHighestStepper() + { + var team = TestData.CreateTeamWithHighestStepper(); + team.Participants.ElementAt(0).Steps.First().StepCount = 0; + team.Participants.ElementAt(1).Steps.First().StepCount = 0; + team.Participants.ElementAt(2).Steps.First().StepCount = 0; + + var teamService = new TeamService(GetMockStepContext(team)); + var result = teamService.GetTeamScoreBoard(1); + + Assert.IsTrue(result.All(r => r.ParticipantsStepsStatus.All(s => s.ParticipantHighestStepper == false)), $"Expected all participants to have highest step status of False but got True"); + } + private StepContext GetMockStepContext(Team team) { var teamSteps = new List(); diff --git a/StepChallenge.Tests/TeamTests.Data.cs b/StepChallenge.Tests/TeamTests.Data.cs index 6aec080..4bcbf90 100644 --- a/StepChallenge.Tests/TeamTests.Data.cs +++ b/StepChallenge.Tests/TeamTests.Data.cs @@ -88,6 +88,40 @@ public static Team CreateTeamForTeamScoreboard() }; } + public static Team CreateTeamWithHighestStepper() + { + return new Team + { + TeamId = 1, + TeamName = "Team_1", + NumberOfParticipants = 3, + Participants = new List + { + new Participant + { + ParticipantName = "B_ParticipantNameOne", + ParticipantId = 1, + Steps = CreateSteps(10, 1, StartDate), + TeamId = 1, + }, + new Participant + { + ParticipantName = "A_ParticipantNameTwo", + ParticipantId = 2, + Steps = CreateSteps(5, 2, StartDate), + TeamId = 1, + }, + new Participant + { + ParticipantName = "C_ParticipantNameThree", + ParticipantId = 3, + Steps = CreateSteps(1, 3, StartDate), + TeamId = 1, + }, + } + }; + } + private static IQueryable CreateThreeTeams() { return (new List diff --git a/StepChallenge/ClientApp/src/App.css b/StepChallenge/ClientApp/src/App.css index 0711206..e4ac676 100644 --- a/StepChallenge/ClientApp/src/App.css +++ b/StepChallenge/ClientApp/src/App.css @@ -13,3 +13,8 @@ font-size: 0.55em; text-align: center; font-weight: 700; } + +.goldStar { + border: "1px solid red"; + text-decoration: underline; +} diff --git a/StepChallenge/ClientApp/src/components/TeamScoreboard.js b/StepChallenge/ClientApp/src/components/TeamScoreboard.js index e5e3b51..0a4a9c2 100644 --- a/StepChallenge/ClientApp/src/components/TeamScoreboard.js +++ b/StepChallenge/ClientApp/src/components/TeamScoreboard.js @@ -8,7 +8,7 @@ async function loadUserSteps(id) { var apiHelper = new ApiHelper() var query = `{"query": "query teamQuery( $teamId : ID! ) { teamSteps( teamId : $teamId ) - {stepCount, dateOfSteps, participantsStepsStatus { participantName, participantAddedStepCount} }, + {stepCount, dateOfSteps, participantsStepsStatus { participantName, participantAddedStepCount, participantHighestStepper} }, team (teamId: $teamId ) {teamName, numberOfParticipants, participants { participantName }} } ", diff --git a/StepChallenge/ClientApp/src/components/TeamStep.js b/StepChallenge/ClientApp/src/components/TeamStep.js index fb32edc..aa20380 100644 --- a/StepChallenge/ClientApp/src/components/TeamStep.js +++ b/StepChallenge/ClientApp/src/components/TeamStep.js @@ -33,12 +33,14 @@ class TeamStep extends Component { var status = { name : "User not registered yet", initials: "-", - steps: false + steps: false, + highestStepper: false } if(this.state.participantsStatus[i] != null ){ status.name = this.state.participantsStatus[i].participantName status.initials = this.state.participantsStatus[i].participantName.charAt(0).toUpperCase() status.steps = this.state.participantsStatus[i].participantAddedStepCount + status.highestStepper = this.state.participantsStatus[i].participantHighestStepper } info[i] = status } @@ -50,7 +52,7 @@ class TeamStep extends Component {
{info.map(s => - {s.initials} + {s.initials} )}
@@ -58,5 +60,4 @@ class TeamStep extends Component { } } - export default TeamStep; \ No newline at end of file diff --git a/StepChallenge/DataModels/TeamScoreBoard.cs b/StepChallenge/DataModels/TeamScoreBoard.cs index d8fbf2a..1a26913 100644 --- a/StepChallenge/DataModels/TeamScoreBoard.cs +++ b/StepChallenge/DataModels/TeamScoreBoard.cs @@ -16,5 +16,7 @@ public class ParticipantsStepsStatus public string ParticipantName { get; set; } public int ParticipantId { get; set; } public bool ParticipantAddedStepCount { get; set; } + public int ParticipantStepCount { get; set; } + public bool ParticipantHighestStepper { get; set; } } } \ No newline at end of file diff --git a/StepChallenge/Model/GraphQL/ParticipantStepStatus.cs b/StepChallenge/Model/GraphQL/ParticipantStepStatus.cs index a883618..a69be46 100644 --- a/StepChallenge/Model/GraphQL/ParticipantStepStatus.cs +++ b/StepChallenge/Model/GraphQL/ParticipantStepStatus.cs @@ -12,6 +12,7 @@ public ParticipantStepStatusType() Field(x => x.ParticipantName, type: typeof(StringGraphType)).Description("The Date of the step count"); Field(x => x.ParticipantAddedStepCount, type: typeof(BooleanGraphType)).Description("If the participant has filled in their steps or not"); + Field(x => x.ParticipantHighestStepper, type: typeof(BooleanGraphType)).Description("Participants with the highest step count will be set to true"); } } diff --git a/StepChallenge/Services/StepsService.cs b/StepChallenge/Services/StepsService.cs index e906032..07eb0e4 100644 --- a/StepChallenge/Services/StepsService.cs +++ b/StepChallenge/Services/StepsService.cs @@ -99,7 +99,7 @@ public List GetTeamScores(IQueryable teams, DateTime thisMonda { TeamId = t.TeamId, TeamName = t.TeamName, - NumberOfParticipants = t.NumberOfParticipants, //TODO - need to know how many are in a team, if participants haven't registered yet then we can't rely on counting all participants + NumberOfParticipants = t.NumberOfParticipants, TeamStepCount = t.Participants.Sum(p => p.Steps .Where(s => s.DateOfSteps >= startDate && s.DateOfSteps < thisMonday || t.Participants.All(u => u.Steps.All(x => x.StepCount == 0))) @@ -107,6 +107,7 @@ public List GetTeamScores(IQueryable teams, DateTime thisMonda }) .ToList(); + // add a pretend participant with averaged steps to teams with less participants foreach (var teamScore in sortedTeams.Where(t => t.NumberOfParticipants != averageTeamSize && t.NumberOfParticipants != 0)) { teamScore.TeamStepCount = ((teamScore.TeamStepCount / teamScore.NumberOfParticipants) * diff --git a/StepChallenge/Services/TeamService.cs b/StepChallenge/Services/TeamService.cs index f9b38fb..b2780d5 100644 --- a/StepChallenge/Services/TeamService.cs +++ b/StepChallenge/Services/TeamService.cs @@ -54,13 +54,28 @@ public List GetTeamScoreBoard(int teamId) foreach (var teamStep in teamSteps) { - teamStep.ParticipantsStepsStatus = participants + var stepsStatuses = participants .Select(p => new ParticipantsStepsStatus { ParticipantName = p.ParticipantName, ParticipantId = p.ParticipantId, - ParticipantAddedStepCount = p.Steps.Any(ps => ps.DateOfSteps == teamStep.DateOfSteps && ps.StepCount != 0) + ParticipantAddedStepCount = + p.Steps.Any(ps => ps.DateOfSteps == teamStep.DateOfSteps && ps.StepCount != 0), + ParticipantStepCount = p.Steps.Where(ps => ps.DateOfSteps == teamStep.DateOfSteps).Sum(ps => ps.StepCount), }) + .OrderByDescending(p => p.ParticipantStepCount) + .ToList(); + + var highest = stepsStatuses.First().ParticipantStepCount; + if (highest != 0) + { + foreach (var stepStatus in stepsStatuses.Where(p => p.ParticipantStepCount == highest)) + { + stepStatus.ParticipantHighestStepper = true; + } + } + + teamStep.ParticipantsStepsStatus = stepsStatuses .OrderBy(p => p.ParticipantName) .ToList(); }