Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team composition #494

Merged
merged 4 commits into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Data/DataModel/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class Team
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }

public int EventID { get; set; }
[Required]
public virtual Event Event { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions ServerCore/Pages/Swag/Report.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
ViewData["PlayRoute"] = "../Swag/Report";
}

<a asp-page="/Teams/Index">Back to team list</a>
<br/>
<h2>Lunch and T-Shirt Report</h2>

<table class="table">
Expand Down
15 changes: 9 additions & 6 deletions ServerCore/Pages/Teams/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@
<a asp-page="Create">Create New</a>
}
</p>
@if (Model.Event.IsInternEvent)
{
<div>
<a asp-page="/Swag/Report">Intern T-shirts and Lunch</a>
</div>
}
<h4>Registered Teams: @Model.Teams.Count/@Model.Event.MaxNumberOfTeams, Registered Players: @Model.PlayerCount/@(Model.Event.MaxNumberOfTeams * Model.Event.MaxTeamSize)</h4>
@if (Model.EventRole == ModelBases.EventRole.admin)
{
<div>
Summaries:
<a asp-page="/Teams/TeamCompositionSummary">Team Composition</a> @("|")
@if (Model.Event.IsInternEvent)
{
<a asp-page="/Swag/Report">Intern T-shirts and Lunch</a> @("|")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hides the swag report from authors. I think they might need access to it.

}
</div>
<br />
<a asp-page="/Events/Mailer" asp-route-group="PrimaryContacts">Email all team primary contacts from the bulk mailer</a>
}
<table class="table">
Expand Down
83 changes: 83 additions & 0 deletions ServerCore/Pages/Teams/TeamCompositionSummary.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
@page "/{eventId}/{eventRole}/Teams/TeamCompositionSummary"
@model ServerCore.Pages.Teams.TeamCompositionSummaryModel
@{
ViewData["Title"] = "Team Index";
ViewData["AdminRoute"] = "/Teams/TeamCompositionSummary";
ViewData["AuthorRoute"] = "/Teams/Index";
ViewData["PlayRoute"] = "/Teams/Index";
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>TeamCompositionSummary</title>
<style>
td, th {
text-align:center;
}
</style>
</head>
<body>
<a asp-page="/Teams/Index">Back to team list</a>
<br />
<h2>Team Composition Summary</h2>
<div>
<table class="table">
<thead>
<tr>
<th>
Team Name
</th>
<th>
Total
</th>
<th>
Employee Count
</th>
<th>
Intern Count
</th>
<th>
Non-Microsoft Count
</th>
<th>
Possible Employee Aliases
</th>
</tr>
</thead>
<tbody>
@foreach (var teamComp in Model.TeamCompositions)
{
<tr>
<td>
<a asp-page="./Details" asp-route-teamId="@teamComp.TeamID">@teamComp.TeamName</a>
</td>
<td>
@teamComp.Total
</td>
<td>
@teamComp.MicrosoftNonInternCount
</td>
<td>
@teamComp.InternCount
</td>
<td>
@teamComp.NonMicrosoftCount
</td>
<td>
@teamComp.PossibleEmployeeAliases.Count
@if (teamComp.PossibleEmployeeAliases.Count > 0)
{
<br/>
@string.Format("({0})", string.Join("; ", teamComp.PossibleEmployeeAliases))
}
</td>
</tr>
}
</tbody>
</table>
</div>
</body>
</html>
104 changes: 104 additions & 0 deletions ServerCore/Pages/Teams/TeamCompositionSummary.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ServerCore.DataModel;
using ServerCore.Helpers;
using ServerCore.ModelBases;

namespace ServerCore.Pages.Teams
{
/// <summary>
/// Model for the author/admin's view of the feedback items for a specific puzzle
/// /used for viewing and aggregating feedback for a specific puzzle
/// </summary>
[Authorize(Policy = "IsEventAdmin")]
public class TeamCompositionSummaryModel : EventSpecificPageModel
{
// AlphaNumeric or dashes only
public Regex aliasRegex = new Regex("^[a-zA-Z0-9-]*$");

public TeamCompositionSummaryModel(PuzzleServerContext serverContext, UserManager<IdentityUser> userManager) : base(serverContext, userManager)
{
}

public class TeamComposition
{
public TeamComposition(int teamId)
{
this.TeamID = teamId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this. required

this.PossibleEmployeeAliases = new List<string>();
}

public int TeamID { get; }
public string TeamName { get; set; }
public int MicrosoftNonInternCount { get; set; }
public int InternCount { get; set; }
public int NonMicrosoftCount { get; set; }
public int Total { get; set; }
public List<string> PossibleEmployeeAliases { get; set; }
}

public IEnumerable<TeamComposition> TeamCompositions { get; set; }

public IActionResult OnGet()
{
TeamCompositions = _context.Teams.Where(team => team.EventID == Event.ID)
.Join(
_context.TeamMembers,
team => team.ID,
teamMember => teamMember.Team.ID,
(team, teamMember) => new IntermediateTeamMember() { TeamID = team.ID, TeamName = team.Name, TeamMember = teamMember.Member })
.GroupBy(intermediate => intermediate.TeamID)
.Select(this.MapToTeamComposition);

return Page();
}

private TeamComposition MapToTeamComposition(IGrouping<int, IntermediateTeamMember> group)
{
TeamComposition toReturn = new TeamComposition(group.Key);

foreach (IntermediateTeamMember groupMember in group)
{
toReturn.TeamName = groupMember.TeamName;
toReturn.Total += 1;

string email = groupMember.TeamMember.Email;
string alias = groupMember.TeamMember.EmployeeAlias;
if (email.EndsWith("@microsoft.com"))
{
if (email.StartsWith("t-"))
{
toReturn.InternCount += 1;
}
else
{
toReturn.MicrosoftNonInternCount += 1;
}
}
else if (!string.IsNullOrEmpty(alias) && aliasRegex.IsMatch(alias))
{
toReturn.PossibleEmployeeAliases.Add(alias);
}
else
{
toReturn.NonMicrosoftCount += 1;
}
}

return toReturn;
}

private class IntermediateTeamMember
{
public int TeamID { get; set; }
public string TeamName { get; set; }
public PuzzleUser TeamMember { get; set; }
}
}
}