Skip to content

Commit

Permalink
Merge branch 'master' of github.com:PuzzleServer/mainpuzzleserver
Browse files Browse the repository at this point in the history
  • Loading branch information
lambertwang-zz committed Oct 11, 2018
2 parents 99cb9b3 + 0e86fa1 commit 2f1a8d9
Show file tree
Hide file tree
Showing 16 changed files with 913 additions and 51 deletions.
62 changes: 62 additions & 0 deletions Data/DataModel/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,81 @@ public Uri URL
public bool IsInternEvent { get; set; }
public DateTime TeamRegistrationBegin { get; set; }
public DateTime TeamRegistrationEnd { get; set; }

/// <summary>
/// Returns whether or not team registration is active.
/// </summary>
/// <returns>True if the current date is between the team registration begin and end times.</returns>
[NotMapped]
public bool IsTeamRegistrationActive
{
get
{
return DateTime.UtcNow.CompareTo(TeamRegistrationBegin) > 0 &&
DateTime.UtcNow.CompareTo(TeamRegistrationEnd) < 0;
}
}

public DateTime TeamNameChangeEnd { get; set; }
public DateTime TeamMembershipChangeEnd { get; set; }
public DateTime TeamMiscDataChangeEnd { get; set; }
public DateTime TeamDeleteEnd { get; set; }
public DateTime EventBegin { get; set; }

/// <summary>
/// Returns whether or not the event has started. Does not necessarily indicate the event
/// is currently active.
/// </summary>
/// <returns>True if the current date is after the EventBegin time</returns>
[NotMapped]
public bool EventHasStarted
{
get { return DateTime.UtcNow.CompareTo(EventBegin) > 0; }
}

public DateTime AnswerSubmissionEnd { get; set; }

/// <summary>
/// Returns whether or not answer submission is active.
/// </summary>
/// <returns>True if the current date is after the event start and before the answer submission end times.</returns>
[NotMapped]
public bool IsAnswerSubmissionActive
{
get
{
return DateTime.UtcNow.CompareTo(EventBegin) > 0 &&
DateTime.UtcNow.CompareTo(AnswerSubmissionEnd) < 0;
}
}

public DateTime AnswersAvailableBegin { get; set; }

/// <summary>
/// Returns whether or not the puzzle answers should be available now.
/// </summary>
/// <returns>True if the current date is after the AnswersAvailableBegin time</returns>
[NotMapped]
public bool AreAnswersAvailableNow
{
get { return DateTime.UtcNow.CompareTo(AnswersAvailableBegin) > 0; }
}

/// <summary>
/// Automatically makes the standings page available at the DateTime below
/// </summary>
public DateTime StandingsAvailableBegin { get; set; }

/// <summary>
/// Returns whether or not the standings page should be available now.
/// </summary>
/// <returns>True if the current date is after the StandingsAvailableBegin time</returns>
[NotMapped]
public bool AreStandingsAvailableNow
{
get { return DateTime.UtcNow.CompareTo(StandingsAvailableBegin) > 0; }
}

/// <summary>
/// Allows event owners to hide standings during the event if they prefer - overrides the timed setting
/// </summary>
Expand Down
68 changes: 68 additions & 0 deletions ServerCore/Pages/Events/FastestSolves.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@page "/{eventId}/Events/FastestSolves"
@model ServerCore.Pages.Events.FastestSolvesModel

@{
ViewData["Title"] = "Fastest Solves";
}

<h2>Fastest Solves</h2>

<table class="table table-condensed">
<thead>
<tr>
<th>
Rank
</th>
<th>
@Html.DisplayNameFor(model => model.Puzzles[0].Puzzle.Name)
</th>
<th>
Teams
</th>
<th>
First
</th>
<th>
Second
</th>
<th>
Third
</th>
</tr>
</thead>
<tbody>
@for (int y = 0; y < Model.Puzzles.Count; y++) {
var puzzle = Model.Puzzles[y];
<tr>
<td>
@(puzzle.SortOrder + 1)
</td>
<td>
@(puzzle.Puzzle.Name)
</td>
<td>
@(puzzle.SolveCount)
</td>
@* TODO: Highlight the cell if this is your team's ID Same for second and third place. *@
<td>
@if (puzzle.Fastest.Length >= 1)
{
<text>@puzzle.Fastest[0].Name (@puzzle.Fastest[0].Time)</text>
}
</td>
<td>
@if (puzzle.Fastest.Length >= 2)
{
<text>@puzzle.Fastest[1].Name (@puzzle.Fastest[1].Time)</text>
}
</td>
<td>
@if (puzzle.Fastest.Length >= 3)
{
<text>@puzzle.Fastest[2].Name (@puzzle.Fastest[2].Time)</text>
}
</td>
</tr>
}
</tbody>
</table>
69 changes: 69 additions & 0 deletions ServerCore/Pages/Events/FastestSolves.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using ServerCore.DataModel;
using ServerCore.ModelBases;

namespace ServerCore.Pages.Events
{
public class FastestSolvesModel : EventSpecificPageModel
{
private readonly ServerCore.Models.PuzzleServerContext _context;

public List<PuzzleStats> Puzzles { get; private set; }

public FastestSolvesModel(ServerCore.Models.PuzzleServerContext context)
{
_context = context;
}

public async Task OnGetAsync()
{
// get the page data: puzzle, solve count, top three fastest
var puzzlesData = await PuzzleStateHelper.GetSparseQuery(_context, this.Event, null, null)
.Where(s => s.SolvedTime != null && s.Puzzle.IsPuzzle)
.GroupBy(state => state.Puzzle)
.Select(g => new {
Puzzle = g.Key,
SolveCount = g.Count(),
Fastest = g.OrderBy(s => s.SolvedTime - s.UnlockedTime).Take(3).Select(s => new { s.Team.ID, s.Team.Name, Time = s.SolvedTime - s.UnlockedTime})
})
.OrderByDescending(p => p.SolveCount).ThenBy(p => p.Puzzle.Name)
.ToListAsync();

var puzzles = new List<PuzzleStats>(puzzlesData.Count);
for (int i = 0; i < puzzlesData.Count; i++)
{
var data = puzzlesData[i];
var stats = new PuzzleStats()
{
Puzzle = data.Puzzle,
SolveCount = data.SolveCount,
SortOrder = i,
Fastest = data.Fastest.Select(f => new FastRecord() { ID = f.ID, Name = f.Name, Time = f.Time }).ToArray()
};

puzzles.Add(stats);
}

this.Puzzles = puzzles;
}

public class PuzzleStats
{
public Puzzle Puzzle;
public int SolveCount;
public int SortOrder;
public FastRecord[] Fastest;
}

public class FastRecord
{
public int ID;
public string Name;
public TimeSpan? Time;
}
}
}
5 changes: 4 additions & 1 deletion ServerCore/Pages/Events/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
<a asp-page="./Details" asp-route-id="@item.ID">Details</a> |
<a asp-page="./Delete" asp-route-id="@item.ID">Delete</a> |
<a asp-page="/Puzzles/Index" asp-route-eventId="@item.ID">Puzzles</a> |
<a asp-page="/Teams/Index" asp-route-eventId="@item.ID">Teams</a>
<a asp-page="/Teams/Index" asp-route-eventId="@item.ID">Teams</a> |
<a asp-page="/Events/Standings" asp-route-eventId="@item.ID">Standings</a> |
<a asp-page="/Events/FastestSolves" asp-route-eventId="@item.ID">Fastest</a> |
<a asp-page="/Events/Map" asp-route-eventId="@item.ID">Map</a>
</td>
</tr>
}
Expand Down
60 changes: 60 additions & 0 deletions ServerCore/Pages/Events/Map.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@page "/{eventId}/Events/Map"
@model ServerCore.Pages.Events.MapModel

@{
ViewData["Title"] = "Puzzle State Map";
}

<h2>Puzzle State Map</h2>

<table class="table table-condensed ph-statemap">
<thead>
<tr>
<th>
Rank
</th>
<th>
@Html.DisplayNameFor(model => model.Teams[0].Team.Name)
</th>
<th>
Puzzles
</th>
<th>
@Html.DisplayNameFor(model => model.Teams[0].Score)
</th>
@foreach (var puzzle in Model.Puzzles)
{
<th>
<a asp-page="/Puzzles/Status" asp-route-id="@puzzle.Puzzle.ID">@(puzzle.Puzzle.Name) (@puzzle.SolveCount)</a>
</th>
}
</tr>
</thead>
<tbody>
@for (int y = 0; y < Model.Teams.Count; y++) {
var team = Model.Teams[y];
<tr>
<td>
@(team.Rank)
</td>
<td>
<a asp-page="/Teams/Status" asp-route-id="@team.Team.ID">@(team.Team.Name)</a>
</td>
<td>
@Html.DisplayFor(modelItem => team.SolveCount)
</td>
<td>
@Html.DisplayFor(modelItem => team.Score)
</td>
@for (int x = 0; x < Model.Puzzles.Count; x++)
{
var teamState = Model.StateMap[x, y] ?? MapModel.StateStats.Default;

<td @if(teamState.DisplayLightness < 30) { <text> class= "dark"</text> } style="background-color: hsl(@teamState.DisplayHue, 100%, @teamState.DisplayLightness%)">
<a href="">@teamState.DisplayText</a>
</td>
}
</tr>
}
</tbody>
</table>
Loading

0 comments on commit 2f1a8d9

Please sign in to comment.