-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDMS-200 captures ched types of movements & adds to analytics. One of… (
#36) * CDMS-200 captures ched types of movements & adds to analytics. One of the tests is failing so needs investigation * CDMS-200 finalising country filtering * Adds test generation unit test that instantiates and validates all scenario generators * Refactors to reuse chedtype & country filtering * Removing comments * Refactoring analytics to re-use link status analysis * Refactored Link status out of analytics to be calculated at write time and stored on movement * Fixed tests * Fixes tests
- Loading branch information
1 parent
504ff2d
commit a80c298
Showing
48 changed files
with
702 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Btms.Common.Extensions; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
using Btms.Analytics.Tests.Fixtures; | ||
using Btms.Model.Ipaffs; | ||
|
||
namespace Btms.Analytics.Tests; | ||
|
||
[Collection(nameof(BasicSampleDataTestCollection))] | ||
public class MovementsByMaxVersionTests( | ||
BasicSampleDataTestFixture basicSampleDataTestFixture, | ||
ITestOutputHelper testOutputHelper) | ||
{ | ||
// [Fact] | ||
// public async Task WhenCalledLastWeek_ReturnExpectedAggregation() | ||
// { | ||
// testOutputHelper.WriteLine("Querying for aggregated data"); | ||
// var result = (await basicSampleDataTestFixture.GetMovementsAggregationService(testOutputHelper) | ||
// .ByStatus(DateTime.Today.WeekAgo(), DateTime.Today.Tomorrow())); | ||
// | ||
// testOutputHelper.WriteLine("{0} aggregated items found", result.Values.Count); | ||
// | ||
// result.Values.Count.Should().Be(2); | ||
// result.Values.Keys.Order().Should().Equal("Linked", "Not Linked"); | ||
// } | ||
// | ||
// [Fact] | ||
// public async Task WhenCalledLast48Hours_ReturnExpectedAggregation() | ||
// { | ||
// testOutputHelper.WriteLine("Querying for aggregated data"); | ||
// var result = (await basicSampleDataTestFixture.GetMovementsAggregationService(testOutputHelper) | ||
// .ByStatus(DateTime.Now.NextHour().AddDays(-2), DateTime.Now.NextHour())); | ||
// | ||
// testOutputHelper.WriteLine($"{result.Values.Count} aggregated items found"); | ||
// | ||
// result.Values.Count.Should().Be(2); | ||
// result.Values.Keys.Order().Should().Equal("Linked", "Not Linked"); | ||
// } | ||
// | ||
// [Fact] | ||
// public async Task WhenCalledWithTimePeriodYieldingNoResults_ReturnEmptyAggregation() | ||
// { | ||
// testOutputHelper.WriteLine("Querying for aggregated data"); | ||
// var result = (await basicSampleDataTestFixture.GetMovementsAggregationService(testOutputHelper) | ||
// .ByStatus(DateTime.MaxValue.AddDays(-1), DateTime.MaxValue)); | ||
// | ||
// testOutputHelper.WriteLine($"{result.Values.Count} aggregated items found"); | ||
// | ||
// result.Values.Count.Should().Be(2); | ||
// result.Values.Keys.Order().Should().Equal("Linked", "Not Linked"); | ||
// } | ||
|
||
[Fact] | ||
public async Task WhenCalledWithChedType_ReturnsResults() | ||
{ | ||
testOutputHelper.WriteLine("Querying for aggregated data"); | ||
var result = (await basicSampleDataTestFixture.GetMovementsAggregationService(testOutputHelper) | ||
.ByMaxVersion(DateTime.Now.NextHour().AddDays(-2), DateTime.Now.NextHour(), chedTypes: [ImportNotificationTypeEnum.Cveda])); | ||
|
||
testOutputHelper.WriteLine($"{result.Values.Count} aggregated items found"); | ||
|
||
result.Values.Count.Should().Be(2); | ||
} | ||
|
||
[Fact] | ||
public async Task WhenCalledWithCountry_ReturnsResults() | ||
{ | ||
testOutputHelper.WriteLine("Querying for aggregated data"); | ||
var result = (await basicSampleDataTestFixture.GetMovementsAggregationService(testOutputHelper) | ||
.ByMaxVersion(DateTime.Now.NextHour().AddDays(-2), DateTime.Now.NextHour(), country: "AL")); | ||
|
||
testOutputHelper.WriteLine($"{result.Values.Count} aggregated items found"); | ||
|
||
result.Values.Count.Should().Be(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Btms.Model; | ||
using Btms.Model.Ipaffs; | ||
|
||
namespace Btms.Analytics.Extensions; | ||
|
||
public static class MovementExtensions | ||
{ | ||
public static IQueryable<Movement> WhereFilteredByCreatedDateAndParams(this IQueryable<Movement> source, DateTime from, DateTime to, | ||
ImportNotificationTypeEnum[]? chedTypes = null, string? country = null) | ||
{ | ||
return source | ||
.Where(m => (m.CreatedSource >= from && m.CreatedSource < to) | ||
&& (country == null || m.DispatchCountryCode == country) | ||
&& (chedTypes == null || !chedTypes!.Any() || | ||
!m.AlvsDecisionStatus!.Context!.ChedTypes!.Any() || | ||
m.AlvsDecisionStatus!.Context!.ChedTypes!.Any(c => chedTypes!.Contains(c)))); | ||
|
||
} | ||
|
||
public class MovementWithLinkStatus | ||
{ | ||
public required Movement Movement; | ||
public required DateTime CreatedSource; | ||
public required string Description; | ||
} | ||
|
||
public static IQueryable<MovementWithLinkStatus> SelectLinkStatus(this IQueryable<Movement> source) | ||
{ | ||
var m = source | ||
.Select(m => new MovementWithLinkStatus() { | ||
Movement = m, | ||
CreatedSource = m.CreatedSource!.Value, | ||
Description = | ||
m.Status.LinkStatus | ||
// m.Relationships.Notifications.Data.Count > 0 ? "Linked" : | ||
// m.AlvsDecisionStatus!.Context!.AlvsCheckStatus!.AnyMatch ? "Investigate" : | ||
// "Not Linked" | ||
}); | ||
|
||
return m; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.