Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
L3tum committed Dec 2, 2019
1 parent b8e1e38 commit db2c85f
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 102 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
82 changes: 0 additions & 82 deletions CPU-Benchmark-Database-Aggregator/Aggregators/ByCPUAggregator.cs

This file was deleted.

108 changes: 108 additions & 0 deletions CPU-Benchmark-Database-Aggregator/Aggregators/ByScoreAggregator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#region using

using System.Collections.Generic;
using System.Linq;
using CPU_Benchmark_Database_Aggregator.Models;
using CPU_Benchmark_Server_Aggregator.Models;

#endregion

namespace CPU_Benchmark_Database_Aggregator.Aggregators
{
internal class ByScoreAggregator : IAggregator
{
private readonly Dictionary<string, List<Save>> byBenchmarkResults = new Dictionary<string, List<Save>>();
private readonly Dictionary<uint, List<Save>> byCoreResults = new Dictionary<uint, List<Save>>();

public void ProcessSave(Save save)
{
foreach (var result in save.Results)
{
if (!byCoreResults.ContainsKey(result.Key))
{
byCoreResults.Add(result.Key, new List<Save> {save});
}
else
{
var inserted = false;

for (var i = 0; i < byCoreResults[result.Key].Count; i++)
{
var currentSave = byCoreResults[result.Key][i];
var eligibleResults = currentSave.Results[result.Key]
.Where(r => !r.Benchmark.StartsWith("Category:")).ToList();
var score = eligibleResults.Sum(r => r.Points) / eligibleResults.Count;

var newEligibleResults = save.Results[result.Key]
.Where(r => !r.Benchmark.StartsWith("Category:"))
.ToList();
var newScore = newEligibleResults.Sum(r => r.Points) / newEligibleResults.Count;

if (newScore > score)
{
byCoreResults[result.Key].Insert(i, save);
inserted = true;
break;
}
}

if (!inserted && byCoreResults[result.Key].Count < 100)
{
byCoreResults[result.Key].Add(save);
}
}

foreach (var res in result.Value)
{
var key = $"{res.Benchmark} @ {result.Key} Threads";

if (!byBenchmarkResults.ContainsKey(key))
{
byBenchmarkResults.Add(key, new List<Save> {save});
}
else
{
var inserted = false;

for (var i = 0; i < byBenchmarkResults[key].Count; i++)
{
var currentScore = byBenchmarkResults[key][i].Results[result.Key]
.First(r => r.Benchmark == res.Benchmark);

if (res.Points > currentScore.Points)
{
byBenchmarkResults[key].Insert(i, save);
inserted = true;
break;
}
}

if (!inserted && byBenchmarkResults[key].Count < 100)
{
byBenchmarkResults[key].Add(save);
}
}
}
}
}

public IEnumerable<Aggregate> GetAggregatedResults()
{
var list = new List<Aggregate>();

foreach (var byCoreResult in byCoreResults)
{
list.Add(new Aggregate($"Threads {byCoreResult.Key}", "byCores",
byCoreResult.Value.GetRange(0, 100).Select(s => s.UUID)));
}

foreach (var byBenchmarkResult in byBenchmarkResults)
{
list.Add(new Aggregate(byBenchmarkResult.Key, "byBenchmarks",
byBenchmarkResult.Value.GetRange(0, 100).Select(s => s.UUID)));
}

return list;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RootNamespace>CPU_Benchmark_Database_Aggregator</RootNamespace>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HardwareInformation" Version="2.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.5" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>

Expand Down
18 changes: 18 additions & 0 deletions CPU-Benchmark-Database-Aggregator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM mcr.microsoft.com/dotnet/core/runtime:3.0-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ["CPU-Benchmark-Database-Aggregator/CPU-Benchmark-Database-Aggregator.csproj", "CPU-Benchmark-Database-Aggregator/"]
RUN dotnet restore "CPU-Benchmark-Database-Aggregator/CPU-Benchmark-Database-Aggregator.csproj"
COPY . .
WORKDIR "/src/CPU-Benchmark-Database-Aggregator"
RUN dotnet build "CPU-Benchmark-Database-Aggregator.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "CPU-Benchmark-Database-Aggregator.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CPU-Benchmark-Database-Aggregator.dll"]
31 changes: 20 additions & 11 deletions CPU-Benchmark-Database-Aggregator/Models/Aggregate.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
using CPU_Benchmark_Server_Aggregator.Models;
using HardwareInformation;
using System;
#region using

using System.Collections.Generic;
using System.Text;

#endregion

namespace CPU_Benchmark_Database_Aggregator.Models
{
class Aggregate
{
public List<Result> ResultsST = new List<Result>();
public List<Result> ResultsMT = new List<Result>();
public MachineInformation MachineInformation = new MachineInformation();
}
}
internal class Aggregate
{
public Aggregate(string name, string category, IEnumerable<string> resultSaveUUIDs)
{
Name = name;
Category = category;
ResultSaveUUIDs = resultSaveUUIDs;
}

public string Name { get; set; }

public string Category { get; set; }

public IEnumerable<string> ResultSaveUUIDs { get; set; }
}
}
83 changes: 74 additions & 9 deletions CPU-Benchmark-Database-Aggregator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,78 @@
using System;
#region using

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using CPU_Benchmark_Database_Aggregator.Aggregators;
using CPU_Benchmark_Database_Aggregator.Models;
using CPU_Benchmark_Server_Aggregator.Models;
using Newtonsoft.Json;

#endregion

namespace CPU_Benchmark_Database_Aggregator
{
class Program
{
static void Main(string[] args)
{
var saves = Directory.GetFiles(Environment.GetEnvironmentVariable("GITHUB_WORKSPACE") + "/saves");
}
}
}
internal class Program
{
private static readonly IEnumerable<IAggregator> aggregators = new[]
{
new ByScoreAggregator()
};

private static void Main(string[] args)
{
var baseDirectory = Environment.GetEnvironmentVariable("GITHUB_WORKSPACE") + "/saves";
var saves = Directory.GetFiles(baseDirectory, "*.json");
var aggregates = new List<Aggregate>();

foreach (var saveFile in saves)
{
try
{
var save = JsonConvert.DeserializeObject<Save>(saveFile);

foreach (var aggregator in aggregators)
{
aggregator.ProcessSave(save);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

foreach (var aggregator in aggregators)
{
aggregates.AddRange(aggregator.GetAggregatedResults());
}

foreach (var aggregate in aggregates)
{
var dir = $"{baseDirectory}/{aggregate.Category}";

if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}

var validName = new StringBuilder(aggregate.Name);

foreach (var c in Path.GetInvalidFileNameChars())
{
validName = validName.Replace(c, '_');
}

var file = $"{dir}/{validName}";

if (File.Exists(file))
{
File.Delete(file);
}

File.WriteAllText(file, JsonConvert.SerializeObject(aggregate));
}
}
}
}
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# action.yml
name: 'CPU-Benchmark-Database-Aggregator'
description: 'Aggregator for the CPU Benchmark Database'
runs:
using: 'docker'
image: 'CPU-Benchmark-Database-Aggregator/Dockerfile'

0 comments on commit db2c85f

Please sign in to comment.