Skip to content

Commit

Permalink
CDMS-179 fixes errors when no matches found (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigedmunds authored and Ian Shimmings committed Dec 10, 2024
1 parent 7bd2c2e commit 65c627b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Btms.Analytics/ImportNotificationsAggregationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public Task<MultiSeriesDataset[]> ByCommodityCount(DateTime from, DateTime to)
.GroupBy(r => new { r.Key.ImportNotificationType, r.Key.Linked })
.ToList();

var maxCommodities = result.Max(r => r.Max(i => i.Key.CommodityCount));
// var maxCommodities = result.Max(r => r.Max(i => i.Key.CommodityCount));

var maxCommodities = result.Count > 0 ?
result.Max(r => r.Any() ? r.Max(i => i.Key.CommodityCount) : 0) : 0;

var list = result
.SelectMany(g =>
Expand Down
7 changes: 4 additions & 3 deletions Btms.Analytics/MovementsAggregationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public Task<MultiSeriesDataset[]> ByItemCount(DateTime from, DateTime to)
var dictionary = mongoResult
.ToDictionary(g => new { Title = AnalyticsHelpers.GetLinkedName(g.Linked), g.ItemCount }, g => g.Count);

var maxCount = mongoResult
.Max(r => r.Count);
var maxCount = mongoResult.Count > 0 ?
mongoResult.Max(r => r.Count) : 0;

return Task.FromResult(AnalyticsHelpers.GetMovementSegments()
.Select(title => new MultiSeriesDataset(title, "Item Count") {
Expand Down Expand Up @@ -114,7 +114,8 @@ public Task<MultiSeriesDataset[]> ByUniqueDocumentReferenceCount(DateTime from,
g => new { Title = AnalyticsHelpers.GetLinkedName(g.Linked), g.DocumentReferenceCount },
g => g.MovementCount);

var maxReferences = mongoResult.Max(r => r.DocumentReferenceCount);
var maxReferences = mongoResult.Count > 0 ?
mongoResult.Max(r => r.DocumentReferenceCount) : 0;

return Task.FromResult(AnalyticsHelpers.GetMovementSegments()
.Select(title => new MultiSeriesDataset(title, "Document Reference Count") {
Expand Down

0 comments on commit 65c627b

Please sign in to comment.