Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
* Changing internal components in TournamentManager
* Implement new round-robin classes
* Seprate MatchCreater and MatchScheduler
  • Loading branch information
axunonb committed Dec 12, 2023
1 parent 0744c12 commit 300bcb0
Show file tree
Hide file tree
Showing 21 changed files with 1,745 additions and 629 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public virtual EntityCollection<RoundEntity> GetTournamentRounds(long tournament
return result;
}

public virtual async Task<TournamentEntity?> GetTournamentEntityForMatchPlannerAsync(long tournamentId, CancellationToken cancellationToken)
public virtual async Task<TournamentEntity?> GetTournamentEntityForMatchSchedulerAsync(long tournamentId, CancellationToken cancellationToken)
{
var bucket = new RelationPredicateBucket(TournamentFields.Id == tournamentId);
bucket.Relations.Add(TournamentEntity.Relations.RoundEntityUsingTournamentId);
Expand Down
23 changes: 13 additions & 10 deletions TournamentManager/TournamentManager/Plan/AvailableMatchDates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

namespace TournamentManager.Plan;

public class AvailableMatchDates
/// <summary>
/// This class manages available match dates.
/// </summary>
internal class AvailableMatchDates
{
private readonly ITenantContext _tenantContext;
private readonly AppDb _appDb;
Expand Down Expand Up @@ -64,7 +67,7 @@ await _appDb.AvailableMatchDateRepository.GetAvailableMatchDatesAsync(
/// <param name="clear">Which entries to delete for the tournament.</param>
/// <param name="cancellationToken"></param>
/// <returns>Returns the number of deleted records.</returns>
internal async Task<int> ClearAsync(ClearMatchDates clear, CancellationToken cancellationToken)
public async Task<int> ClearAsync(MatchDateClearOption clear, CancellationToken cancellationToken)
{
var deleted = 0;

Expand All @@ -73,20 +76,20 @@ internal async Task<int> ClearAsync(ClearMatchDates clear, CancellationToken can
filterAvailable.PredicateExpression.Add(AvailableMatchDateFields.TournamentId ==
_tenantContext.TournamentContext.MatchPlanTournamentId);

if (clear == ClearMatchDates.All)
if (clear == MatchDateClearOption.All)
{
deleted = await _appDb.GenericRepository.DeleteEntitiesDirectlyAsync(typeof(AvailableMatchDateEntity),
null!, cancellationToken);
_generatedAvailableMatchDateEntities.Clear();
}
else if (clear == ClearMatchDates.OnlyAutoGenerated)
else if (clear == MatchDateClearOption.OnlyAutoGenerated)
{
filterAvailable.PredicateExpression.AddWithAnd(AvailableMatchDateFields.IsGenerated == true);
deleted = await _appDb.GenericRepository.DeleteEntitiesDirectlyAsync(typeof(AvailableMatchDateEntity),
filterAvailable, cancellationToken);
_generatedAvailableMatchDateEntities.Clear();
}
else if (clear == ClearMatchDates.OnlyManual)
else if (clear == MatchDateClearOption.OnlyManual)
{
filterAvailable.PredicateExpression.AddWithAnd(AvailableMatchDateFields.IsGenerated == false);
deleted = await _appDb.GenericRepository.DeleteEntitiesDirectlyAsync(typeof(AvailableMatchDateEntity),
Expand Down Expand Up @@ -130,7 +133,7 @@ private async Task<bool> IsDateUsable(DateTime matchDateTimeUtc, RoundLegEntity
/// <param name="round"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
internal async Task GenerateNewAsync(RoundEntity round, CancellationToken cancellationToken)
public async Task GenerateNewAsync(RoundEntity round, CancellationToken cancellationToken)
{
await Initialize(cancellationToken);

Expand Down Expand Up @@ -275,7 +278,7 @@ private bool IsExcludedDate(DateTime queryDate, long? roundId, long? teamId)
;
}

internal List<DateTime> GetGeneratedAndManualAvailableMatchDateDays(RoundLegEntity leg)
public List<DateTime> GetGeneratedAndManualAvailableMatchDateDays(RoundLegEntity leg)
{
var result = _generatedAvailableMatchDateEntities.Union(_availableMatchDateEntities)
.Where(gen => gen.TournamentId == _tenantContext.TournamentContext.MatchPlanTournamentId
Expand All @@ -288,10 +291,10 @@ internal List<DateTime> GetGeneratedAndManualAvailableMatchDateDays(RoundLegEnti
return result;
}

internal List<AvailableMatchDateEntity> GetGeneratedAndManualAvailableMatchDates(long homeTeamId,
public List<AvailableMatchDateEntity> GetGeneratedAndManualAvailableMatchDates(long homeTeamId,
DateTimePeriod datePeriod, List<DateTime>? excludedDates)
{
if (!(datePeriod.Start.HasValue && datePeriod.End.HasValue)) throw new ArgumentNullException(nameof(datePeriod));
if (datePeriod is not { Start: not null, End: not null }) throw new ArgumentNullException(nameof(datePeriod));

var result = _generatedAvailableMatchDateEntities.Union(_availableMatchDateEntities)
.Where(gen => gen.TournamentId == _tenantContext.TournamentContext.MatchPlanTournamentId
Expand All @@ -300,7 +303,7 @@ internal List<AvailableMatchDateEntity> GetGeneratedAndManualAvailableMatchDates
datePeriod.End.Value.Date.AddDays(1).AddSeconds(-1))
.OrderBy(gen => gen.MatchStartTime);

if (excludedDates != null && excludedDates.Count > 0)
if (excludedDates is { Count: > 0 })
return result.Where(dates => !excludedDates.Contains(dates.MatchStartTime.Date))
.OrderBy(dates => dates.MatchStartTime).ToList();

Expand Down
10 changes: 0 additions & 10 deletions TournamentManager/TournamentManager/Plan/ClearMatchDates.cs

This file was deleted.

126 changes: 0 additions & 126 deletions TournamentManager/TournamentManager/Plan/CombinationGroupOptimizer.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace TournamentManager.Plan;
/// <summary>
/// This class manages excluded match dates.
/// </summary>
public class ExcludeMatchDates
internal class ExcludeMatchDates
{
private readonly AppDb _appDb;
private readonly ILogger<ExcludeMatchDates> _logger;
Expand Down
16 changes: 16 additions & 0 deletions TournamentManager/TournamentManager/Plan/LegType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace TournamentManager.Plan;

/// <summary>
/// Specifies the type of the leg to create match combinations of a round
/// </summary>
public enum LegType
{
/// <summary>
/// The first leg.
/// </summary>
First = 1,
/// <summary>
/// The return leg.
/// </summary>
Return
}
Loading

0 comments on commit 300bcb0

Please sign in to comment.