Skip to content

Commit

Permalink
Merge pull request #56 from ARKlab/feature/AnalysisDate
Browse files Browse the repository at this point in the history
added support to analysis date parameter on versioned queries
  • Loading branch information
AndreaCuneo committed Aug 21, 2024
2 parents 4129667 + 62ba407 commit 3864c45
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
50 changes: 50 additions & 0 deletions Artesian/Artesian.SDK.Tests/VersionedTimeSerieQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2613,6 +2613,8 @@ public void Ver_PeriodRelativeIntervalChange()
}
}


[Test]
public void Ver_RelativePeriodExtractionWindowChange()
{
using (var httpTest = new HttpTest())
Expand Down Expand Up @@ -2650,9 +2652,57 @@ public void Ver_RelativePeriodExtractionWindowChange()
.WithQueryParam("id", 100000001)
.WithVerb(HttpMethod.Get)
.Times(1);
}
}

[Test]
public void Ver_RelativePeriodForAnalysisDate()
{
using (var httpTest = new HttpTest())
{
var qs = new QueryService(_cfg);

var partialQuery = qs.CreateVersioned()
.ForMarketData(new [] { 100000001 })
.InGranularity(Granularity.Hour)
.ForMUV()
.InRelativePeriod(Period.FromDays(5));

var test = partialQuery
.ForAnalysisDate(new LocalDate(2018, 07, 19))
.ExecuteAsync().Result;

httpTest.ShouldHaveCalledPath($"{_cfg.BaseAddress}query/v1.0/vts/MUV/Hour/P5D")
.WithQueryParam("id", 100000001)
.WithQueryParam("ad", "2018-07-19")
.WithVerb(HttpMethod.Get)
.Times(1);
}
}

[Test]
public void Ver_RelativePeriodExtractionWindowFail()
{
var qs = new QueryService(_cfg);

var query = qs.CreateVersioned()
.ForMarketData(new [] {100000001})
.InGranularity(Granularity.Day)
.ForLastNVersions(3)
.InAbsoluteDateRange(
new LocalDate(2018, 07, 15),
new LocalDate(2018, 07, 20)
)
.ForAnalysisDate(new LocalDate(2018, 07, 19))
;

Assert.Throws<ArtesianSdkClientException>(
() => {
query.ExecuteAsync().ConfigureAwait(true).GetAwaiter().GetResult();
}
);
}

#endregion

#region Filler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public IEnumerable<VersionedQueryParamaters> Partition(IEnumerable<VersionedQuer
queryParamater.VersionSelectionType,
queryParamater.VersionLimit,
queryParamater.FillerKindType,
queryParamater.FillerConfig
queryParamater.FillerConfig,
queryParamater.AnalysisDate
)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public VersionedQueryParamaters()
/// <param name="versionLimit"></param>
/// <param name="fillerK"></param>
/// <param name="fillerConfig"></param>
/// <param name="analysisDate"></param>
public VersionedQueryParamaters(
IEnumerable<int> ids,
ExtractionRangeSelectionConfig extractionRangeSelectionConfig,
Expand All @@ -47,7 +48,8 @@ public VersionedQueryParamaters(
VersionSelectionType? versionSelectionType,
LocalDateTime? versionLimit,
FillerKindType fillerK,
FillerConfig fillerConfig
FillerConfig fillerConfig,
LocalDate? analysisDate
)
: base(ids, extractionRangeSelectionConfig, extractionRangeType, timezone, filterId, fillerK, fillerConfig)
{
Expand All @@ -56,6 +58,7 @@ FillerConfig fillerConfig
this.Granularity = granularity;
this.TransformId = transformId;
this.VersionLimit = versionLimit;
this.AnalysisDate = analysisDate;
this.FillerConfig = fillerConfig;
}

Expand All @@ -79,5 +82,9 @@ FillerConfig fillerConfig
/// Version Limit
/// </summary>
public LocalDateTime? VersionLimit { get; set; }
/// <summary>
/// The analysis date from which apply the relative interval (default Today)
/// </summary>
public LocalDate? AnalysisDate { get; set; }
}
}
18 changes: 18 additions & 0 deletions Artesian/Artesian.SDK/Service/Query/VersionedQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NodaTime;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Threading;
Expand Down Expand Up @@ -327,6 +328,16 @@ public VersionedQuery ForVersion(LocalDateTime version)
return this;
}
/// <summary>
/// Set a specific analysis date from wich apply the relative interval/period
/// </summary>
/// <returns>VersionedQuery</returns>
public VersionedQuery ForAnalysisDate(LocalDate analysisDate)
{
_queryParamaters.AnalysisDate = analysisDate;

return this;
}
/// <summary>
/// Set the Filler strategy to Null
/// </summary>
/// <returns>VersionedQuery</returns>
Expand Down Expand Up @@ -415,6 +426,8 @@ protected override void _validateQuery()
}
}

if (_queryParamaters.ExtractionRangeType == ExtractionRangeType.DateRange && _queryParamaters.AnalysisDate != null)
throw new ArtesianSdkClientException("Analysis should be related to a Period. Provide a period or remove analysis date.");
}

private string _buildVersionRoute(VersionedQueryParamaters queryParamaters)
Expand Down Expand Up @@ -492,6 +505,11 @@ private List<string> _buildRequest()
.SetQueryParam("fillerK", qp.FillerKindType)
.SetQueryParam("fillerDV", qp.FillerConfig.FillerTimeSeriesDV)
.SetQueryParam("fillerP", qp.FillerConfig.FillerPeriod)
.SetQueryParam("ad",
qp.AnalysisDate.HasValue
? qp.AnalysisDate.Value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)
: null
)
.ToString())
.ToList();

Expand Down

0 comments on commit 3864c45

Please sign in to comment.