Skip to content

Commit

Permalink
Merge pull request #199 from SSchulze1989/develop
Browse files Browse the repository at this point in the history
v 0.12.2
  • Loading branch information
SSchulze1989 authored Sep 23, 2024
2 parents 1d92c74 + 859c12d commit 81045bd
Show file tree
Hide file tree
Showing 31 changed files with 472 additions and 266 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.{cs,vb}]

# IDE0305: Initialisierung der Sammlung vereinfachen
dotnet_diagnostic.IDE0305.severity = none
1 change: 1 addition & 0 deletions iRLeagueApiCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iRLeagueApiCore.UnitTests",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7F90E099-56DE-4FEF-8CA2-4F4610CDEF19}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.github\workflows\dotnet_develop.yml = .github\workflows\dotnet_develop.yml
.github\workflows\dotnet_main_pr.yml = .github\workflows\dotnet_main_pr.yml
.github\workflows\dotnet_main_push.yml = .github\workflows\dotnet_main_push.yml
Expand Down
2 changes: 1 addition & 1 deletion src/iRLeagueApiCore.Client/iRLeagueApiCore.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<OutputType>Library</OutputType>
<TargetFrameworks>net6.0</TargetFrameworks>
<PackageId>iRLeagueApiCore.Client</PackageId>
<Version>0.12.1</Version>
<Version>0.12.2</Version>
<Authors>Simon Schulze</Authors>
<Company>Simon Schulze</Company>
<PackageDescription>This package contains shared objects for all members of the iRLeagueDatabase-iRLeagueApi stack</PackageDescription>
Expand Down
4 changes: 3 additions & 1 deletion src/iRLeagueApiCore.Common/Enums/ComparatorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public enum ComparatorType
IsBigger,
NotEqual,
InList,
ForEach, // special comparator that multiplies the configured bonus/penalty for each multiple of the provided value
ForEach, // special comparator that multiplies the configured bonus/penalty for each multiple of the provided value
Min,
Max,
}
1 change: 1 addition & 0 deletions src/iRLeagueApiCore.Common/Enums/FilterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public enum FilterType
ColumnProperty,
Member,
Team,
Count,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ namespace iRLeagueApiCore.Common.Models;
[DataContract]
public class BonusPointModel
{
[DataMember]
public string Name { get; set; } = string.Empty;
[DataMember]
public BonusPointType Type { get; set; }
[DataMember]
Expand Down
2 changes: 1 addition & 1 deletion src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PackageId>iRLeagueApiCore.Common</PackageId>
<Version>0.12.1</Version>
<Version>0.12.2</Version>
<Authors>Simon Schulze</Authors>
<Company>Simon Schulze</Company>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
2 changes: 1 addition & 1 deletion src/iRLeagueApiCore.Server/iRLeagueApiCore.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>0.12.1</Version>
<Version>0.12.2</Version>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using iRLeagueApiCore.Common.Enums;
using iRLeagueApiCore.Common.Models;
using iRLeagueApiCore.Services.ResultService.Calculation.Filters;
using iRLeagueApiCore.Services.ResultService.Extensions;
using iRLeagueApiCore.Services.ResultService.Models;
using MySqlX.XDevAPI.Relational;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ protected static IEnumerable<ResultRowCalculationResult> ApplyPoints(IEnumerable
// Calculation
pointRule.ApplyPoints(data, pointRows.ToList());
// remove points from filtered rows and set points eligible
pointRows.ForEach(x => x.PointsEligible = true);
pointRows.ForEach(x => x.PointsEligible = true);
rows.Except(pointRows)
.ForEach(x => {
.ForEach(x =>
{
x.RacePoints = 0;
x.PointsEligible = false;
});
Expand Down Expand Up @@ -74,7 +75,7 @@ protected static (TId? id, TimeSpan lap) GetBestLapValue<T, TId>(IEnumerable<T>
}
catch (Exception ex) when (ex is InvalidOperationException)
{
return Array.Empty<(TId? id, TValue value)>();
return [];
}
}

Expand Down Expand Up @@ -144,7 +145,7 @@ protected static IEnumerable<ResultRowCalculationResult> CombineResults<T>(IEnum
return combined.ToList();
}

private static AddPenaltyCalculationData CreateAddPenaltyFromAutoPenalty(ResultRowCalculationResult row, AutoPenaltyConfigurationData autoPenalty,
private static AddPenaltyCalculationData CreateAddPenaltyFromAutoPenalty(ResultRowCalculationResult row, AutoPenaltyConfigurationData autoPenalty,
int penaltyMultiplikator)
{
var penalty = new AddPenaltyCalculationData()
Expand All @@ -158,17 +159,17 @@ private static AddPenaltyCalculationData CreateAddPenaltyFromAutoPenalty(ResultR
return penalty;
}

private static IEnumerable<ResultRowCalculationResult> CalculateAutoPenalties(IEnumerable<ResultRowCalculationResult> rows,
private static IEnumerable<ResultRowCalculationResult> CalculateAutoPenalties(IEnumerable<ResultRowCalculationResult> rows,
IEnumerable<AutoPenaltyConfigurationData> autoPenalties)
{
foreach(var autoPenalty in autoPenalties)
foreach (var autoPenalty in autoPenalties)
{
var penaltyRows = autoPenalty.Conditions
.FilterRows(rows);
var grouped = penaltyRows.GroupBy(x => x);
foreach(var row in grouped.Where(x => x.Any()))
foreach (var row in grouped.Where(x => x.Any()))
{
row.Key.AddPenalties = row.Key.AddPenalties.Concat(new[] { CreateAddPenaltyFromAutoPenalty(row.Key, autoPenalty, row.Count()) });
row.Key.AddPenalties = [.. row.Key.AddPenalties, CreateAddPenaltyFromAutoPenalty(row.Key, autoPenalty, row.Count())];
}
}
return rows;
Expand Down Expand Up @@ -287,13 +288,12 @@ private static IEnumerable<ResultRowCalculationResult> ApplyBonusPoints(IEnumera
}

var minIncs = rows.Any(x => x.PenaltyPoints == 0) ? rows.Where(x => x.PenaltyPoints == 0).Min(x => x.Incidents) : -1;
var fastestLapRow = GetBestLapValue(rows, x => x, x => x.FastestLapTime);

foreach (var bonus in BonusPoints)
{
var bonusType = bonus.Type;
var bonusKeyValue = (int)bonus.Value;
var bonusPoints = (int)bonus.Points;
var bonusKeyValue = bonus.Value;
var bonusPoints = bonus.Points;
rows = bonusType switch
{
BonusPointType.Position => ApplyPositionBonusPoints(rows, bonusKeyValue, bonusPoints),
Expand All @@ -306,18 +306,19 @@ private static IEnumerable<ResultRowCalculationResult> ApplyBonusPoints(IEnumera
BonusPointType.LeadMostLaps => ApplyLeadMostLapsBonusPoints(rows, bonusPoints),
BonusPointType.NoIncidents => ApplyNoIncidentsBonusPoints(rows, bonusPoints),
BonusPointType.FastestAverageLap => ApplyFastestAverageLapBonusPoints(rows, bonusPoints),
BonusPointType.Custom => ApplyCustomBonusPoints(rows, bonus.Conditions, bonusPoints),
BonusPointType.Custom => ApplyCustomBonusPoints(rows, bonus, bonusPoints),
_ => rows,
};
}

return rows;
}

private static IEnumerable<ResultRowCalculationResult> ApplyCustomBonusPoints(IEnumerable<ResultRowCalculationResult> rows, FilterGroupRowFilter<ResultRowCalculationResult> conditions,
private static IEnumerable<ResultRowCalculationResult> ApplyCustomBonusPoints(IEnumerable<ResultRowCalculationResult> rows, BonusPointConfiguration bonus,
int bonusPoints)
{
var bonusRows = conditions.FilterRows(rows);
var bonusRows = bonus.Conditions.FilterRows(rows);

foreach (var row in bonusRows)
{
row.BonusPoints += bonusPoints;
Expand All @@ -337,63 +338,58 @@ private static IEnumerable<ResultRowCalculationResult> ApplyFastestAverageLapBon

private static IEnumerable<ResultRowCalculationResult> ApplyNoIncidentsBonusPoints(IEnumerable<ResultRowCalculationResult> rows, int points)
{
foreach(var row in rows)
var bonusRows = rows.Where(x => x.Incidents == 0);

foreach (var row in bonusRows)
{
if (row.Incidents == 0)
{
row.BonusPoints += points;
}
row.BonusPoints += points;
}
return rows;
}

private static IEnumerable<ResultRowCalculationResult> ApplyLeadMostLapsBonusPoints(IEnumerable<ResultRowCalculationResult> rows, int points)
{
var mostLapsLead = rows.Max(x => x.LeadLaps);
foreach(var row in rows)
var bonusRows = rows.Where(x => x.LeadLaps == mostLapsLead);

foreach (var row in bonusRows)
{
if (row.LeadLaps == mostLapsLead)
{
row.BonusPoints += points;
}
row.BonusPoints += points;
}
return rows;
}

private static IEnumerable<ResultRowCalculationResult> ApplyLeadOneLapBonusPoints(IEnumerable<ResultRowCalculationResult> rows, int points)
{
foreach(var row in rows)
var bonusRows = rows.Where(x => x.LeadLaps > 0);

foreach (var row in bonusRows)
{
if (row.LeadLaps > 0)
{
row.BonusPoints += points;
}
row.BonusPoints += points;
}
return rows;
}

private static IEnumerable<ResultRowCalculationResult> ApplyMostPositionsLostBonusPoints(IEnumerable<ResultRowCalculationResult> rows, int points)
{
var mostPositionsLost = rows.Max(x => x.PositionChange);
foreach (var row in rows)
var bonusRows = rows.Where(x => x.PositionChange == mostPositionsLost);

foreach (var row in bonusRows)
{
if (row.PositionChange == mostPositionsLost)
{
row.BonusPoints += points;
}
row.BonusPoints += points;
}
return rows;
}

private static IEnumerable<ResultRowCalculationResult> ApplyMostPositionsGainedBonusPoints(IEnumerable<ResultRowCalculationResult> rows, int points)
{
var mostPositionsGained = rows.Min(x => x.PositionChange);
foreach(var row in rows)
var bonusRows = rows.Where(x => x.PositionChange == mostPositionsGained);

foreach (var row in bonusRows)
{
if (row.PositionChange == mostPositionsGained)
{
row.BonusPoints += points;
}
row.BonusPoints += points;
}
return rows;
}
Expand All @@ -416,6 +412,7 @@ private static IEnumerable<ResultRowCalculationResult> ApplyCleanestDriverBonusP
var minIncRows = GetBestValues(rows.Where(condition), x => x.Incidents, x => x, x => x.Min())
.Select(x => x.id)
.NotNull();

foreach (var row in minIncRows)
{
row.BonusPoints += points;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using iRLeagueApiCore.Common.Enums;
using iRLeagueApiCore.Common.Models;
using iRLeagueApiCore.Services.ResultService.Calculation.Filters;
using iRLeagueApiCore.Services.ResultService.Models;

namespace iRLeagueApiCore.Services.ResultService.Calculation;
Expand Down
Loading

0 comments on commit 81045bd

Please sign in to comment.