9152c86d41
Add Scheduler
288 lines
12 KiB
Plaintext
288 lines
12 KiB
Plaintext
@using Core.Calculation
|
|
@using Microsoft.EntityFrameworkCore
|
|
@page "/meeting-schedule/scheduler"
|
|
@inject IConfiguration Configuration
|
|
@inject AppDbContext Context
|
|
|
|
<PageTitle>@Configuration["ChapterSettings:Shortname"] TSA Schedule @Configuration["ChapterSettings:CompetitionYear"]</PageTitle>
|
|
|
|
<MudText Typo="Typo.h3">@Configuration["ChapterSettings:Shortname"] TSA Schedule @Configuration["ChapterSettings:CompetitionYear"]</MudText>
|
|
|
|
|
|
<MudPaper Class="pa-4 mt-5">
|
|
<MudGrid>
|
|
<MudItem Style="width:160px;">
|
|
<MudNumericField @bind-Value="_parameters.TimeSlots"
|
|
Label="Time Slots" Min="1" Max="4"></MudNumericField>
|
|
</MudItem>
|
|
@foreach (var evt in _options)
|
|
{
|
|
<MudItem Style="width:200px">
|
|
|
|
<MudButtonGroup>
|
|
<MudTooltip Text="Require">
|
|
<MudToggleIconButton @bind-Toggled="@evt.Require"
|
|
Icon="@Icons.Material.Filled.CheckBoxOutlineBlank"
|
|
ToggledIcon="@Icons.Material.Filled.CheckBox"
|
|
ToggledColor="@Color.Success"
|
|
Disabled="@evt.Omit"
|
|
Size="Size.Small"
|
|
title="@(evt.Require ? "Required" : "Optional")" />
|
|
</MudTooltip>
|
|
<MudTooltip Text="Extend">
|
|
<MudToggleIconButton @bind-Toggled="@evt.Extend"
|
|
Icon="@Icons.Material.Filled.PlusOne"
|
|
ToggledIcon="@Icons.Material.Filled.PlusOne"
|
|
ToggledColor="@Color.Success"
|
|
Disabled="@evt.Omit"
|
|
Size="Size.Small"
|
|
title="@(evt.Extend ? "Extend" : "Single")" />
|
|
</MudTooltip>
|
|
<MudTooltip Text="Extend">
|
|
<MudToggleIconButton @bind-Toggled="@evt.Omit"
|
|
Icon="@Icons.Material.Filled.EventBusy"
|
|
ToggledIcon="@Icons.Material.Filled.EventBusy"
|
|
ToggledColor="@Color.Error"
|
|
Size="Size.Small"
|
|
title="@(evt.Omit ? "Omit" : "Optional")" />
|
|
</MudTooltip>
|
|
</MudButtonGroup>
|
|
<MudTooltip Text="@string.Join(", ", evt.Team.Students.Select(e => e.FirstName))">
|
|
<MudText>@evt.Team.ToString()</MudText>
|
|
</MudTooltip>
|
|
</MudItem>
|
|
}
|
|
@* <MudItem>
|
|
<MudTooltip Text="Require at least one On-Site Event">
|
|
<MudSwitch @bind-Value="_parameters" Color="Color.Info"
|
|
Label="On-Site" />
|
|
</MudTooltip>
|
|
</MudItem>
|
|
<MudItem>
|
|
<MudTooltip Text="Require at least one Regional Event">
|
|
<MudSwitch @bind-Value="_parameters.RequireRegional" Color="Color.Info"
|
|
Label="Regional" />
|
|
</MudTooltip>
|
|
</MudItem>
|
|
<MudItem>
|
|
<MudStack Style="width:100px;">
|
|
<MudTooltip Text="Student Event Count Assignment Range">
|
|
<MudInputLabel>Event Count</MudInputLabel>
|
|
</MudTooltip>
|
|
<MudNumericField @bind-Value="_parameters.EventsLowerBound"
|
|
Label="At Least" Min="2" Max="4"></MudNumericField>
|
|
|
|
<MudNumericField @bind-Value="_parameters.EventsUpperBound"
|
|
Label="Up to" Min="3" Max="5"></MudNumericField>
|
|
</MudStack>
|
|
</MudItem>
|
|
<MudItem>
|
|
<MudStack Style="width:100px;">
|
|
<MudTooltip Text="Student Level of Effort Range">
|
|
<MudInputLabel>LOE</MudInputLabel>
|
|
</MudTooltip>
|
|
<MudNumericField @bind-Value="_parameters.EffortLowerBound"
|
|
Label="At Least" Min="4" Max="7"></MudNumericField>
|
|
|
|
<MudNumericField @bind-Value="_parameters.EffortUpperBound"
|
|
Label="Up to" Min="7" Max="12"></MudNumericField>
|
|
</MudStack>
|
|
</MudItem>
|
|
<MudItem>
|
|
<MudInputLabel>Assignment Requirements</MudInputLabel>
|
|
<MudTable T="AssignmentRequirement" ServerData="ReloadAssignmentRequirements" @ref="_assignmentRequirementData">
|
|
|
|
<RowTemplate Context="item">
|
|
<MudTd Class="align-center">
|
|
<MudIconButton Icon="@Icons.Material.Filled.RemoveCircle" Size="Size.Small"
|
|
OnClick="() => RemoveRequireEvent(item)"></MudIconButton>
|
|
</MudTd>
|
|
<MudTd Class="align-center">
|
|
@item.Student.FirstName
|
|
@item.EventDefinition.ShortName
|
|
@if (item.Requirement == Requirement.Include)
|
|
{
|
|
<MudIcon Class="ml-3" Icon="@Icons.Material.Filled.ThumbUp" Size="Size.Small"></MudIcon>
|
|
}
|
|
@if (item.Requirement == Requirement.Exclude)
|
|
{
|
|
<MudIcon Class="ml-3" Icon="@Icons.Material.Filled.ThumbDownAlt" Size="Size.Small"></MudIcon>
|
|
}
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
</MudItem>
|
|
<MudItem>
|
|
<MudInputLabel>Two Team Events</MudInputLabel>
|
|
<MudTable T="EventDefinition" ServerData="ReloadEventTwoTeam" @ref="_eventTwoTeamData">
|
|
|
|
<RowTemplate Context="item">
|
|
<MudTd Class="align-center">
|
|
<MudIconButton Icon="@Icons.Material.Filled.RemoveCircle" Size="Size.Small"
|
|
OnClick="() => RemoveTwoTeam(item)"></MudIconButton>
|
|
</MudTd>
|
|
<MudTd Class="align-center">@item.ShortName</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
</MudItem>
|
|
<MudItem>
|
|
<MudInputLabel>Omitted Events</MudInputLabel>
|
|
<MudTable T="EventDefinition" ServerData="ReloadOmittedEvents" @ref="_eventOmittedData">
|
|
|
|
<RowTemplate Context="item">
|
|
<MudTd Class="align-center">
|
|
<MudIconButton Icon="@Icons.Material.Filled.RemoveCircle" Size="Size.Small"
|
|
OnClick="() => RemoveOmitted(item)"></MudIconButton>
|
|
</MudTd>
|
|
<MudTd Class="align-center">@item.ShortName</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
</MudItem> *@
|
|
</MudGrid>
|
|
<MudButton Class="ma-3" OnClick="Solve" Variant="Variant.Filled" Color="Color.Primary" Disabled="@_isSolving">Solve</MudButton>
|
|
</MudPaper>
|
|
|
|
|
|
<MudItem xs="12" lg="4">
|
|
<MudText Typo="Typo.h4">Time Slots</MudText>
|
|
<MudTable T="Team[]" ServerData="SolveSchedule" @ref="_solutionData">
|
|
<HeaderContent>
|
|
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd>
|
|
@{
|
|
var ol = TeamSchedulerSolution.GetStudentTeamOverlaps(context);}
|
|
@foreach (var t in context)
|
|
{
|
|
<MudItem>
|
|
@t.ToString() -
|
|
@string.Join(", ", t.Students.Select(s => s.FirstName + " " + (ol.Any(o => o.Item1.Equals(s)) ? "*" : "" )) )
|
|
</MudItem>
|
|
}
|
|
@* @foreach (var overlap in ol)
|
|
{
|
|
<MudItem>
|
|
@string.Join(", ", overlap.Item1)
|
|
</MudItem>
|
|
} *@
|
|
|
|
@{ var notInTimeSLot = TeamSchedulerSolution.GetStudentsNotInTimSlot(context, _students); }
|
|
@if (notInTimeSLot.Any()) {
|
|
<MudItem>
|
|
<i>
|
|
Not scheduled: @string.Join(", ", notInTimeSLot.Select(s => s.FirstName))
|
|
</i>
|
|
</MudItem>
|
|
}
|
|
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
</MudItem>
|
|
|
|
@code {
|
|
private Team[]? _teams;
|
|
private Student[]? _students;
|
|
MudTable<Team[]> _solutionData;
|
|
private TeamSchedulerSolution _solution;
|
|
private TeamSchedulerOptions _parameters;
|
|
bool _isSolving = false;
|
|
|
|
public class TeamOptions
|
|
{
|
|
public Team Team { get; set; }
|
|
public bool Require { get; set; } = false;
|
|
public bool Omit { get; set; } = false;
|
|
public bool Extend { get; set; } = false;
|
|
}
|
|
|
|
private TeamOptions[]? _options;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_parameters =
|
|
new TeamSchedulerOptions(
|
|
timeSlots: 4,
|
|
mustIncludeEvents:
|
|
[
|
|
// "Medical Technology", "Electrical Applications" , "RegionalTeam",
|
|
// ,"Dragster", "Flight"
|
|
],
|
|
extended:
|
|
[
|
|
// "Invention", "Construction Challenge", "Mechanical", "Mass", "Micro"
|
|
//"STEM"
|
|
//"Community", "Vlogging"// "Microcontroller"
|
|
],
|
|
omittedEvents:
|
|
[
|
|
// "Vlogging", "Junior", "Community Service Video", "Digital Photography",
|
|
// "STEM"
|
|
|
|
//"Leadership",// "Electrical", //"Construction"
|
|
// "Forensic",
|
|
//"CAD"
|
|
//"I&I Team 1", "I&I Team 2"//, "Website Design",
|
|
],
|
|
absentStudents:
|
|
[
|
|
]
|
|
);
|
|
|
|
|
|
_teams
|
|
= await Context.Teams
|
|
.Include(e => e.Event)
|
|
.Include(e => e.Students)
|
|
.OrderBy(e => e.Event.Name)
|
|
.ThenBy(e => e.Number)
|
|
.ToArrayAsync();
|
|
|
|
_students =
|
|
await Context.Students
|
|
.Include(e => e.Teams)
|
|
.ThenInclude(e => e.Captain)
|
|
.Include(e => e.EventRankings)
|
|
.ThenInclude(e => e.EventDefinition)
|
|
.OrderBy(e => e.FirstName).ToArrayAsync();
|
|
|
|
_options = _teams
|
|
.Select(e => new TeamOptions { Team = e })
|
|
.ToArray();
|
|
|
|
}
|
|
|
|
private async Task<TableData<Team[]>> SolveSchedule(TableState arg1, CancellationToken arg2)
|
|
{
|
|
//_isSolving = true;
|
|
|
|
|
|
|
|
var mustIncludeTeams = _teams;
|
|
mustIncludeTeams = mustIncludeTeams.Where(t => t.Event.EventFormat != EventFormat.Individual).ToArray();
|
|
mustIncludeTeams = mustIncludeTeams.Where(t => !t.ToString().Contains("#1")).ToArray();
|
|
//mustIncludeTeams = mustIncludeTeams.Where(t => !t.ToString().Contains("Photo")).ToArray();
|
|
|
|
var teamScheduler = new TeamScheduler(mustIncludeTeams, 3);
|
|
|
|
// teamScheduler
|
|
// .ScheduleSeparate(
|
|
// _teams.First(e => e.Event.Name.Contains("Data Science")),
|
|
// _teams.First(e => e.Event.Name.Contains("Microcontroller Design"))
|
|
// );
|
|
|
|
_solution = teamScheduler.Solve();
|
|
|
|
await InvokeAsync(StateHasChanged); // let the UI know that the solution has been found
|
|
|
|
return new TableData<Team[]> { Items = _solution.TimeSlots};
|
|
}
|
|
|
|
|
|
private void Solve()
|
|
{
|
|
_solutionData.ReloadServerData();
|
|
}
|
|
}
|