Skip to content

Commit

Permalink
added DerivedCfg parameters in metadata readonly and nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopocinaark committed Jan 10, 2025
1 parent b8c2948 commit c4e5008
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 48 deletions.
44 changes: 27 additions & 17 deletions Artesian/Artesian.SDK.Tests/Samples/DerivedTimeSerieTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,40 @@ public async Task CreateDerivedCoalesceTimeSeries()
}

// Update DerivedCfg
curveIds.Reverse();
var derivedCfgUpdate = new DerivedCfgCoalesce()
if (marketData.Metadata.DerivedCfgCoalesce != null)
{
OrderedReferencedMarketDataIds = curveIds.ToArray(),
};
curveIds.Reverse();
var derivedCfgUpdate = new DerivedCfgCoalesce()
{
OrderedReferencedMarketDataIds = curveIds.ToArray(),
};

marketData.UpdateDerivedConfiguration(derivedCfgUpdate, false).ConfigureAwait(true).GetAwaiter().GetResult();
if (!marketData.Metadata.DerivedCfgCoalesce.OrderedReferencedMarketDataIds.SequenceEqual(derivedCfgUpdate.OrderedReferencedMarketDataIds))
{
marketData.UpdateDerivedConfiguration(derivedCfgUpdate, false).ConfigureAwait(true).GetAwaiter().GetResult();

await Task.Delay(2000);
await Task.Delay(2000);

ts = await qs.CreateActual()
.ForMarketData(new[] { marketData.MarketDataId.Value })
.InGranularity(Granularity.Day)
.InAbsoluteDateRange(new LocalDate(2018, 10, 01), new LocalDate(2018, 10, 10))
.ExecuteAsync();
ts = await qs.CreateActual()
.ForMarketData(new[] { marketData.MarketDataId.Value })
.InGranularity(Granularity.Day)
.InAbsoluteDateRange(new LocalDate(2018, 10, 01), new LocalDate(2018, 10, 10))
.ExecuteAsync();

foreach (var item in ts)
{
if (item.Time.Date <= new DateTime(2018, 10, 3))
ClassicAssert.AreEqual(100, item.Value);
foreach (var item in ts)
{
if (item.Time.Date <= new DateTime(2018, 10, 3))
ClassicAssert.AreEqual(100, item.Value);

if (item.Time.Date > new DateTime(2018, 10, 3))
ClassicAssert.AreEqual(200, item.Value);
if (item.Time.Date > new DateTime(2018, 10, 3))
ClassicAssert.AreEqual(200, item.Value);
}
}
else
throw new InvalidOperationException("OrderedReferencedMarketDataIds are not with the expected order");
}
else
throw new InvalidOperationException("DerivedCfg is not Coalesce");

/*******************************************************************
* Tidy Up
Expand Down
39 changes: 39 additions & 0 deletions Artesian/Artesian.SDK/Dto/DerivedCfg/DerivedCfgCoalesceReadOnly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;

using System.Collections.Generic;

namespace Artesian.SDK.Dto.DerivedCfg
{
/// <summary>
/// DerivedCoalesce Configuration Readonly
/// </summary>
public record DerivedCfgCoalesceReadOnly : DerivedCfgCoalesce
{
/// <summary>
/// DerivedCoalesce constructor
/// </summary>
/// <param name="cfg"></param>
public DerivedCfgCoalesceReadOnly(DerivedCfgCoalesce cfg)
{
// Copy properties from the original cfg to the read-only version
this.Version = cfg.Version;
this.DerivedAlgorithm = cfg.DerivedAlgorithm;
this.OrderedReferencedMarketDataIds = new List<int>(cfg.OrderedReferencedMarketDataIds).AsReadOnly();
// Copy other properties as needed
}

/// <summary>
/// MarketData ReferenceIds list
/// </summary>
public new IReadOnlyList<int> OrderedReferencedMarketDataIds { get; }
/// <summary>
/// DerivedAlgorithm
/// </summary>
public new DerivedAlgorithm DerivedAlgorithm { get; }
/// <summary>
/// Version
/// </summary>
public new int Version { get; }

}
}
32 changes: 32 additions & 0 deletions Artesian/Artesian.SDK/Dto/DerivedCfg/DerivedCfgMuvReadOnly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;

namespace Artesian.SDK.Dto.DerivedCfg
{
/// <summary>
/// DerivedMuv Configuration Readonly
/// </summary>
public record DerivedCfgMuvReadOnly : DerivedCfgMuv
{
/// <summary>
/// DerivedCoalesce constructor
/// </summary>
/// <param name="cfg"></param>
public DerivedCfgMuvReadOnly(DerivedCfgMuv cfg)
{
// Copy properties from the original cfg to the read-only version
this.Version = cfg.Version;
this.DerivedAlgorithm = cfg.DerivedAlgorithm;
// Copy other properties as needed
}

/// <summary>
/// DerivedAlgorithm
/// </summary>
public new DerivedAlgorithm DerivedAlgorithm { get; }
/// <summary>
/// Version
/// </summary>
public new int Version { get; }

}
}
39 changes: 39 additions & 0 deletions Artesian/Artesian.SDK/Dto/DerivedCfg/DerivedCfgSumReadOnly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Artesian.SDK.Dto.DerivedCfg.Enums;

using System.Collections.Generic;

namespace Artesian.SDK.Dto.DerivedCfg
{
/// <summary>
/// DerivedSum Configuration Readonly
/// </summary>
public record DerivedCfgSumReadOnly : DerivedCfgSum
{
/// <summary>
/// DerivedCoalesce constructor
/// </summary>
/// <param name="cfg"></param>
public DerivedCfgSumReadOnly(DerivedCfgSum cfg)
{
// Copy properties from the original cfg to the read-only version
this.Version = cfg.Version;
this.DerivedAlgorithm = cfg.DerivedAlgorithm;
this.OrderedReferencedMarketDataIds = new List<int>(cfg.OrderedReferencedMarketDataIds).AsReadOnly();
// Copy other properties as needed
}

/// <summary>
/// MarketData ReferenceIds list
/// </summary>
public new IReadOnlyList<int> OrderedReferencedMarketDataIds { get; }
/// <summary>
/// DerivedAlgorithm
/// </summary>
public new DerivedAlgorithm DerivedAlgorithm { get; }
/// <summary>
/// Version
/// </summary>
public new int Version { get; }

}
}
10 changes: 3 additions & 7 deletions Artesian/Artesian.SDK/Dto/MarketData/MarketDataEntityInputExt.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using Artesian.SDK.Dto.DerivedCfg;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Artesian.SDK.Dto.MarketData
{
Expand All @@ -28,13 +24,13 @@ public static void ValidateUpdate(this MarketDataEntity.Input marketDataEntityIn
throw new ArgumentException("Aggregation Rule must be Undefined if Type is MarketAssessment", nameof(marketDataEntityInput));
}

public static void ValidateDerivedCfg(this MarketDataEntity.Output marketDataEntityOutput, DerivedCfgBase derivedCfg)
public static void ValidateUpdateDerivedCfg(this MarketDataEntity.Output marketDataEntityOutput, DerivedCfgBase derivedCfg)
{
if (marketDataEntityOutput.DerivedCfg == null)
throw new ArgumentException("Derived Configuration is null for the MarketData selected", nameof(marketDataEntityOutput));
throw new ArgumentException("DerivedCfg cannot be added to a MarketData that has not", nameof(marketDataEntityOutput));

if (marketDataEntityOutput.DerivedCfg.DerivedAlgorithm != derivedCfg.DerivedAlgorithm)
throw new ArgumentException("Derived Algorithm is different from the one in the update", nameof(marketDataEntityOutput));
throw new ArgumentException("Derived Algorithm cannot be update", nameof(marketDataEntityOutput));
}
}
}
6 changes: 3 additions & 3 deletions Artesian/Artesian.SDK/Factory/IMarketData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public interface IMarketData
/// <param name="force">Force the update of configuration also if another rebuild process is running (Defualt=false)</param>
/// <param name="ctk">Cancellation Token</param>
/// <returns></returns>
Task UpdateDerivedConfiguration(DerivedCfgMuv derivedCfg, bool force = false, CancellationToken ctk = default);
Task UpdateDerivedConfiguration(DerivedCfgMuv derivedCfg, bool force, CancellationToken ctk = default);

/// <summary>
/// Update Derived Configuration
Expand All @@ -145,7 +145,7 @@ public interface IMarketData
/// <param name="force">Force the update of configuration also if another rebuild process is running (Defualt=false)</param>
/// <param name="ctk">Cancellation Token</param>
/// <returns></returns>
Task UpdateDerivedConfiguration(DerivedCfgCoalesce derivedCfg, bool force = false, CancellationToken ctk = default);
Task UpdateDerivedConfiguration(DerivedCfgCoalesce derivedCfg, bool force, CancellationToken ctk = default);

/// <summary>
/// Update Derived Configuration
Expand All @@ -162,7 +162,7 @@ public interface IMarketData
/// <param name="force">Force the update of configuration also if another rebuild process is running (Defualt=false)</param>
/// <param name="ctk">Cancellation Token</param>
/// <returns></returns>
Task UpdateDerivedConfiguration(DerivedCfgSum derivedCfg, bool force = false, CancellationToken ctk = default);
Task UpdateDerivedConfiguration(DerivedCfgSum derivedCfg, bool force, CancellationToken ctk = default);
}

/// <summary>
Expand Down
20 changes: 10 additions & 10 deletions Artesian/Artesian.SDK/Factory/MarketData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ public async Task UpdateDerivedConfiguration(DerivedCfgMuv derivedCfg, Cancellat
/// <param name="force">Force the update of configuration also if another rebuild process is running (Defualt=false)</param>
/// <param name="ctk">Cancellation Token</param>
/// <returns></returns>
public async Task UpdateDerivedConfiguration(DerivedCfgMuv derivedCfg, bool force = false, CancellationToken ctk = default)
public async Task UpdateDerivedConfiguration(DerivedCfgMuv derivedCfg, bool force, CancellationToken ctk = default)
{
_entity.ValidateDerivedCfg(derivedCfg);
_entity.ValidateUpdateDerivedCfg(derivedCfg);

_entity = await _marketDataService.UpdateDerivedConfigurationAsync(_entity.MarketDataId, derivedCfg, force, ctk).ConfigureAwait(false);

Expand All @@ -255,7 +255,7 @@ public async Task UpdateDerivedConfiguration(DerivedCfgMuv derivedCfg, bool forc
/// <summary>
/// Update Derived Configuration
/// </summary>
/// <param name="derivedCfg">The Derived Configuration Muv to be updated</param>
/// <param name="derivedCfg">The Derived Configuration Coalesce to be updated</param>
/// <param name="ctk">Cancellation Token</param>
/// <returns></returns>
public async Task UpdateDerivedConfiguration(DerivedCfgCoalesce derivedCfg, CancellationToken ctk = default)
Expand All @@ -266,13 +266,13 @@ public async Task UpdateDerivedConfiguration(DerivedCfgCoalesce derivedCfg, Canc
/// <summary>
/// Update Derived Configuration
/// </summary>
/// <param name="derivedCfg">The Derived Configuration Muv to be updated</param>
/// <param name="derivedCfg">The Derived Configuration Coalesce to be updated</param>
/// <param name="force">Force the update of configuration also if another rebuild process is running (Defualt=false)</param>
/// <param name="ctk">Cancellation Token</param>
/// <returns></returns>
public async Task UpdateDerivedConfiguration(DerivedCfgCoalesce derivedCfg, bool force = false, CancellationToken ctk = default)
public async Task UpdateDerivedConfiguration(DerivedCfgCoalesce derivedCfg, bool force, CancellationToken ctk = default)
{
_entity.ValidateDerivedCfg(derivedCfg);
_entity.ValidateUpdateDerivedCfg(derivedCfg);

_entity = await _marketDataService.UpdateDerivedConfigurationAsync(_entity.MarketDataId, derivedCfg, force, ctk).ConfigureAwait(false);

Expand All @@ -282,7 +282,7 @@ public async Task UpdateDerivedConfiguration(DerivedCfgCoalesce derivedCfg, bool
/// <summary>
/// Update Derived Configuration
/// </summary>
/// <param name="derivedCfg">The Derived Configuration Muv to be updated</param>
/// <param name="derivedCfg">The Derived Configuration Sum to be updated</param>
/// <param name="ctk">Cancellation Token</param>
/// <returns></returns>
public async Task UpdateDerivedConfiguration(DerivedCfgSum derivedCfg, CancellationToken ctk = default)
Expand All @@ -293,13 +293,13 @@ public async Task UpdateDerivedConfiguration(DerivedCfgSum derivedCfg, Cancellat
/// <summary>
/// Update Derived Configuration
/// </summary>
/// <param name="derivedCfg">The Derived Configuration Muv to be updated</param>
/// <param name="derivedCfg">The Derived Configuration Sum to be updated</param>
/// <param name="force">Force the update of configuration also if another rebuild process is running (Defualt=false)</param>
/// <param name="ctk">Cancellation Token</param>
/// <returns></returns>
public async Task UpdateDerivedConfiguration(DerivedCfgSum derivedCfg, bool force = false, CancellationToken ctk = default)
public async Task UpdateDerivedConfiguration(DerivedCfgSum derivedCfg, bool force, CancellationToken ctk = default)
{
_entity.ValidateDerivedCfg(derivedCfg);
_entity.ValidateUpdateDerivedCfg(derivedCfg);

_entity = await _marketDataService.UpdateDerivedConfigurationAsync(_entity.MarketDataId, derivedCfg, force, ctk).ConfigureAwait(false);

Expand Down
33 changes: 24 additions & 9 deletions Artesian/Artesian.SDK/Factory/MarketDataMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Artesian.SDK.Dto;
using Artesian.SDK.Dto.DerivedCfg;
using Artesian.SDK.Dto.DerivedCfg.Enums;

using NodaTime;

using System;
using System.Collections.Generic;
using DerivedAlg = Artesian.SDK.Dto.DerivedCfg.Enums.DerivedAlgorithm;

namespace Artesian.SDK.Factory
{
Expand Down Expand Up @@ -96,23 +93,41 @@ internal MarketDataMetadata(MarketDataEntity.Output output)
/// <summary>
/// The DerivedCfgCoalesce
/// </summary>
public DerivedCfgCoalesce DerivedCfgCoalesce
public DerivedCfgCoalesceReadOnly? DerivedCfgCoalesce
{
get => _output.DerivedCfg as DerivedCfgCoalesce;
get
{
if (_output.DerivedCfg is DerivedCfgCoalesce)
return new DerivedCfgCoalesceReadOnly(_output.DerivedCfg as DerivedCfgCoalesce);
else
return null;
}
}
/// <summary>
/// The DerivedCfgSum
/// </summary>
public DerivedCfgSum DerivedCfgSum
public DerivedCfgSumReadOnly? DerivedCfgSum
{
get => _output.DerivedCfg as DerivedCfgSum;
get
{
if (_output.DerivedCfg is DerivedCfgSum)
return new DerivedCfgSumReadOnly(_output.DerivedCfg as DerivedCfgSum);
else
return null;
}
}
/// <summary>
/// The DerivedCfgMuv
/// </summary>
public DerivedCfgMuv DerivedCfgMuv
public DerivedCfgMuvReadOnly? DerivedCfgMuv
{
get => _output.DerivedCfg as DerivedCfgMuv;
get
{
if (_output.DerivedCfg is DerivedCfgMuv)
return new DerivedCfgMuvReadOnly(_output.DerivedCfg as DerivedCfgMuv);
else
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public Task DeleteMarketDataAsync(int id, CancellationToken ctk = default)
{
var marketDataOutput = ReadMarketDataRegistryAsync(marketDataId, ctk).ConfigureAwait(true).GetAwaiter().GetResult();

marketDataOutput.ValidateDerivedCfg(derivedCfg);
marketDataOutput.ValidateUpdateDerivedCfg(derivedCfg);

var url = "/marketdata/entity/".AppendPathSegment(marketDataId.ToString(CultureInfo.InvariantCulture)).AppendPathSegment("updateDerivedConfiguration")
.SetQueryParam("force", force);
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ await marketData.Update();
await marketData.Load();
```

In marketData.Metadata, there are three different read-only properties: DerivedCfgCoalesce, DerivedCfgSum, and DerivedCfgMuv. When the TimeSerie is of type Derived, only the corresponding DerivedCfg property is populated. The other two properties remain null.

Updating the DerivedCfg can be performed with `UpdateDerivedConfiguration` on MarketData. A validation will be done on the existing DerivedCfg of the MarketData, that should be not null and with same type as the update.

```csharp
Expand All @@ -413,7 +415,9 @@ var derivedCfgUpdate = new DerivedCfgCoalesce()
OrderedReferencedMarketDataIds = new int[]{ 10002, 10001, 10000}.ToArray(),
};

marketData.UpdateDerivedConfiguration(derivedCfgUpdate, false);
marketData.UpdateDerivedConfiguration(derivedCfgUpdate);
// an overload with force parameter (to force the update and rebuild) is provided
//marketData.UpdateDerivedConfiguration(derivedCfgUpdate, true);
```

Using `Write mode` to edit MarketData and `Save` to save the data of the current MarketData providing an instant. Can be used `Delete` specifying a range to delete a specific range of the time serie.
Expand Down

0 comments on commit c4e5008

Please sign in to comment.