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

[WIP] Move scoring into a separate process #189

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "9.0.1",
"commands": [
"dotnet-ef"
],
"rollForward": false
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ ctf.*.json
data
obj
*.binlog
/data_bk
1 change: 1 addition & 0 deletions ENOWARS.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA0001" Action="None" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1623" Action="None" />
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1649" Action="None" />
Expand Down
41 changes: 0 additions & 41 deletions EnoConfig/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ public static int Main(string[] args)
debugFlagsCommand.Handler = CommandHandler.Create<int, FlagEncoding, string>(async (round, encoding, signing_key) => await program.Flags(round, encoding, signing_key));
rootCommand.AddCommand(debugFlagsCommand);

var roundWarpCommand = new Command("newround", "Start new round");
roundWarpCommand.Handler = CommandHandler.Create(program.NewRound);
rootCommand.AddCommand(roundWarpCommand);

return rootCommand.InvokeAsync(args).Result;
}

Expand Down Expand Up @@ -415,43 +411,6 @@ public async Task<int> Flags(int round, FlagEncoding encoding, string signing_ke
return 0;
}

public async Task<int> NewRound()
{
using var scope = this.serviceProvider.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<EnoDbContext>();
var lastRound = await dbContext.Rounds
.OrderByDescending(r => r.Id)
.FirstOrDefaultAsync();

Round round;
if (lastRound != null)
{
round = new Round(
lastRound.Id + 1,
DateTime.UtcNow,
DateTime.UtcNow,
DateTime.UtcNow,
DateTime.UtcNow,
DateTime.UtcNow);
}
else
{
round = new Round(
1,
DateTime.UtcNow,
DateTime.UtcNow,
DateTime.UtcNow,
DateTime.UtcNow,
DateTime.UtcNow);
}

Console.WriteLine($"Adding round {round}");
dbContext.Add(round);
await dbContext.SaveChangesAsync();

return 0;
}

private static JsonConfiguration? LoadConfig(FileInfo input)
{
if (!input.Exists)
Expand Down
36 changes: 18 additions & 18 deletions EnoCore.Models/AttackInfo/AttackInfo.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
namespace EEnoCore.Models.AttackInfo;

public record AttackInfo(
string[] AvailableTeams,
Dictionary<string, AttackInfoService> Services);

#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable SA1502 // Element should not be on a single line
public class AttackInfoService : Dictionary<string, AttackInfoServiceTeam>
{ }

public class AttackInfoServiceTeam : Dictionary<long, AttackInfoServiceTeamRound>
{ }

public class AttackInfoServiceTeamRound : Dictionary<long, string[]>
{ }
#pragma warning restore SA1502
#pragma warning restore SA1402
namespace EEnoCore.Models.AttackInfo;
public record AttackInfo(
string[] AvailableTeams,
Dictionary<string, AttackInfoService> Services);
#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable SA1502 // Element should not be on a single line
public class AttackInfoService : Dictionary<string, AttackInfoServiceTeam>
{ }
public class AttackInfoServiceTeam : Dictionary<long, AttackInfoServiceTeamRound>
{ }
public class AttackInfoServiceTeamRound : Dictionary<long, string[]>
{ }
#pragma warning restore SA1502
#pragma warning restore SA1402
32 changes: 26 additions & 6 deletions EnoCore.Models/Database/Round.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
namespace EnoCore.Models.Database;

public sealed record Round(long Id,
DateTimeOffset Begin,
DateTimeOffset Quarter2,
DateTimeOffset Quarter3,
DateTimeOffset Quarter4,
DateTimeOffset End);
public enum RoundStatus
{
Prepared,
Running,
Finished,
Scored,
}

public sealed record Round
{
public Round(long id, DateTimeOffset? begin, DateTimeOffset? end, RoundStatus status)
{
this.Id = id;
this.Begin = begin;
this.End = end;
this.Status = status;
}

public long Id { get; set; }

public DateTimeOffset? Begin { get; set; }

public DateTimeOffset? End { get; set; }

public RoundStatus Status { get; set; }
}
72 changes: 0 additions & 72 deletions EnoDatabase/EnoDb.AttackInfo.cs

This file was deleted.

Loading