Skip to content

Commit

Permalink
Fix sonarqube issue
Browse files Browse the repository at this point in the history
  • Loading branch information
craigedmunds committed Feb 3, 2025
1 parent 2a79e0b commit dd720c9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
9 changes: 5 additions & 4 deletions Btms.Analytics/MovementExceptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Btms.Analytics.Extensions;
using Btms.Backend.Data;
Expand All @@ -20,9 +21,10 @@ private static string FormatUnmatched(DecisionStatusEnum decisionStatus, Movemen

return matched.ToString();
}
//Returns a summary of the exceptions or a list
// Means we can share the same anonymous / query code without needing to create loads
// of classes

[SuppressMessage("SonarLint", "S3776",
Justification =
"Means we can share the same anonymous / query code without needing to create loads of classes for the intermediate state")]
public (SingleSeriesDataset summary, List<ExceptionResult>) GetAllExceptions(DateTime from, DateTime to, bool finalisedOnly, bool summary, ImportNotificationTypeEnum[]? chedTypes = null, string? country = null)
{
var exceptionsSummary = new SingleSeriesDataset();
Expand All @@ -31,7 +33,6 @@ private static string FormatUnmatched(DecisionStatusEnum decisionStatus, Movemen
var simplifiedMovementView = context
.Movements
.WhereFilteredByCreatedDateAndParams(from, to, finalisedOnly, chedTypes, country)
// .Where(m => m.Id == "24GBE3BA7NHLFZMAR1")
.Select(m => new
{
// NB - we should think about pre-calculating this stuff and storing it on the movement...
Expand Down
18 changes: 6 additions & 12 deletions Btms.Analytics/MovementsAggregationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace Btms.Analytics;

public class MovementsAggregationService(IMongoDbContext context, ILogger<MovementsAggregationService> logger) : IMovementsAggregationService
{

private const string AggregatedMessage = "Aggregated Data {Result}";

/// <summary>
/// Aggregates movements by createdSource and returns counts by date period. Could be refactored to use a generic/interface in time
/// </summary>
Expand Down Expand Up @@ -290,7 +291,7 @@ private Task<MultiSeriesDatetimeDataset> Aggregate(DateTime[] dateRange, Func<Bs
.Select(status => mongoResult.AsDataset(dateRange, enumLookup.GetValue(status)))
.AsOrderedArray(m => m.Name);

logger.LogDebug("Aggregated Data {Result}", output.ToList().ToJsonString());
logger.LogDebug(AggregatedMessage, output.ToList().ToJsonString());

return Task.FromResult(new MultiSeriesDatetimeDataset() { Series = output.ToList() });
}
Expand Down Expand Up @@ -322,7 +323,7 @@ public Task<SingleSeriesDataset> ByAlvsDecision(DateTime from,
.GroupBy(m => m.Same)
.Execute(logger);

logger.LogDebug("Aggregated Data {Result}", mongoQuery.ToJsonString());
logger.LogDebug(AggregatedMessage, mongoQuery.ToJsonString());

var r = new SingleSeriesDataset();
return Task.FromResult(r);
Expand All @@ -344,7 +345,6 @@ public Task<SummarisedDataset<SingleSeriesDataset, StringBucketDimensionResult>>
var mongoQuery = context
.Movements
.WhereFilteredByCreatedDateAndParams(from, to, finalisedOnly, chedTypes, country)
// .Where(m => m.Id == "24GBE3BA7NHLFZMAR1")
.SelectMany(d => d
.AlvsDecisionStatus.Context.DecisionComparison!.Checks
.Select(c => new
Expand Down Expand Up @@ -381,7 +381,7 @@ public Task<SummarisedDataset<SingleSeriesDataset, StringBucketDimensionResult>>
})
.Execute(logger);

logger.LogDebug("Aggregated Data {Result}", mongoQuery.ToJsonString());
logger.LogDebug(AggregatedMessage, mongoQuery.ToJsonString());

var enumLookup = new JsonStringEnumConverterEx<DecisionStatusEnum>();
var summaryValues = mongoQuery
Expand Down Expand Up @@ -438,24 +438,18 @@ public Task<SummarisedDataset<SingleSeriesDataset, StringBucketDimensionResult>>
.GroupBy(d => new
{
d.BtmsStatus.Segment,
// Segment = d.BtmsStatus.Segment ?? MovementSegmentEnum.None,
d.BtmsStatus.LinkStatus,
d.BtmsStatus.Status,
d.DecisionStatus,
// d.AlvsDecisionStatus.Context.DecisionComparison != null ? d.AlvsDecisionStatus.Context.DecisionComparison.DecisionStatus.ToString() : "None",
d.DecisionMatched,
// d.AlvsDecisionStatus?.Context?.DecisionComparison?.DecisionMatched
// d.Check.CheckCode,
// d.Check.AlvsDecisionCode,
// d.Check.BtmsDecisionCode
})
.Select(g => new
{
g.Key, Count = g.Count()
})
.Execute(logger);

logger.LogDebug("Aggregated Data {Result}", mongoQuery.ToJsonString());
logger.LogDebug(AggregatedMessage, mongoQuery.ToJsonString());

var enumLookup = new JsonStringEnumConverterEx<MovementSegmentEnum>();
var summaryValues = mongoQuery
Expand Down
64 changes: 36 additions & 28 deletions Btms.Business/Builders/MovementBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,40 @@ private void GuardNullMovement()
"Can't call this without first calling 'From' to initialise the builder.");
}
}

private StatusChecker GetAlvsCheckStatus(List<ItemCheck> alvsChecks)
{
return new StatusChecker()
{
AllMatch = alvsChecks.All(c => !c.AlvsDecisionCode.StartsWith('X')),
AnyMatch = alvsChecks.Any(c => !c.AlvsDecisionCode.StartsWith('X')),
AllNoMatch = alvsChecks.All(c => c.AlvsDecisionCode.StartsWith('X')),
AnyNoMatch = alvsChecks.Any(c => c.AlvsDecisionCode.StartsWith('X')),
AllRefuse = alvsChecks.All(c => c.AlvsDecisionCode.StartsWith('N')),
AnyRefuse = alvsChecks.Any(c => c.AlvsDecisionCode.StartsWith('N')),
AllRelease = alvsChecks.All(c => c.AlvsDecisionCode.StartsWith('C')),
AnyRelease = alvsChecks.Any(c => c.AlvsDecisionCode.StartsWith('C')),
AllHold = alvsChecks.All(c => c.AlvsDecisionCode.StartsWith('H')),
AnyHold = alvsChecks.Any(c => c.AlvsDecisionCode.StartsWith('H'))
};
}

private StatusChecker GeBtmsCheckStatus(List<ItemCheck> alvsChecks)
{
return new StatusChecker()
{
AllMatch = alvsChecks.All(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('X')),
AnyMatch = alvsChecks.Any(c => !(c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('X'))),
AllNoMatch = alvsChecks.All(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('X')),
AnyNoMatch = alvsChecks.Any(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('X')),
AllRefuse = alvsChecks.All(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('N')),
AnyRefuse = alvsChecks.Any(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('N')),
AllRelease = alvsChecks.All(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('C')),
AnyRelease = alvsChecks.Any(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('C')),
AllHold = alvsChecks.All(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('H')),
AnyHold = alvsChecks.Any(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('H'))
};
}

private void CompareDecisions(AlvsDecision alvsDecision, CdsDecision btmsDecision)
{
Expand Down Expand Up @@ -352,34 +386,8 @@ private void CompareDecisions(AlvsDecision alvsDecision, CdsDecision btmsDecisio
.ToList();

alvsDecision.Context.DecisionComparison.Checks = alvsChecks;

alvsDecision.Context.AlvsCheckStatus = new StatusChecker()
{
AllMatch = alvsChecks.All(c => !c.AlvsDecisionCode.StartsWith('X')),
AnyMatch = alvsChecks.Any(c => !c.AlvsDecisionCode.StartsWith('X')),
AllNoMatch = alvsChecks.All(c => c.AlvsDecisionCode.StartsWith('X')),
AnyNoMatch = alvsChecks.Any(c => c.AlvsDecisionCode.StartsWith('X')),
AllRefuse = alvsChecks.All(c => c.AlvsDecisionCode.StartsWith('N')),
AnyRefuse = alvsChecks.Any(c => c.AlvsDecisionCode.StartsWith('N')),
AllRelease = alvsChecks.All(c => c.AlvsDecisionCode.StartsWith('C')),
AnyRelease = alvsChecks.Any(c => c.AlvsDecisionCode.StartsWith('C')),
AllHold = alvsChecks.All(c => c.AlvsDecisionCode.StartsWith('H')),
AnyHold = alvsChecks.Any(c => c.AlvsDecisionCode.StartsWith('H'))
};

alvsDecision.Context.BtmsCheckStatus = new StatusChecker()
{
AllMatch = alvsChecks.All(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('X')),
AnyMatch = alvsChecks.Any(c => !(c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('X'))),
AllNoMatch = alvsChecks.All(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('X')),
AnyNoMatch = alvsChecks.Any(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('X')),
AllRefuse = alvsChecks.All(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('N')),
AnyRefuse = alvsChecks.Any(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('N')),
AllRelease = alvsChecks.All(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('C')),
AnyRelease = alvsChecks.Any(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('C')),
AllHold = alvsChecks.All(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('H')),
AnyHold = alvsChecks.Any(c => c.BtmsDecisionCode.HasValue() && c.BtmsDecisionCode.StartsWith('H'))
};
alvsDecision.Context.AlvsCheckStatus = GetAlvsCheckStatus(alvsChecks);
alvsDecision.Context.BtmsCheckStatus = GeBtmsCheckStatus(alvsChecks);

var decisionStatus = DecisionStatusEnum.InvestigationNeeded;
var checksMatch = alvsChecks.All(c => c.AlvsDecisionCode == c.BtmsDecisionCode);
Expand Down

0 comments on commit dd720c9

Please sign in to comment.