Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ozangoktan committed Sep 4, 2024
1 parent c0ee64c commit 7f47ec3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cognite.Extensions/CogniteResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public static bool ContainsIdentity(this HashSet<IIdentity> set, long? idt)
/// <param name="set">Set of identities</param>
/// <param name="idt">IntanceId to test</param>
/// <returns>True if instance id is non-null and set contains it, false otherwise</returns>
public static bool ContainsIdentity(this HashSet<IdentityWithInstanceId> set, InstanceIdentifier? idt)
public static bool ContainsIdentity(this HashSet<IdentityWithInstanceId> set, InstanceIdentifier idt)
{
if (idt == null) return false;
return set.Contains(IdentityWithInstanceId.Create(idt));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using CogniteSdk;
using CogniteSdk.Alpha;
using CogniteSdk.Beta.DataModels;
using System.Collections.Generic;
using System.Linq;

namespace Cognite.Extensions
{
Expand All @@ -10,24 +12,23 @@ private static bool IsAffected<T>(SourcedNodeWrite<T> ts, HashSet<IIdentity> bad
{
return error.Resource switch
{
ResourceType.SpaceId => badValues.ContainsIdentity(ts.Space),
ResourceType.ExternalId => badValues.ContainsIdentity(ts.ExternalId),
ResourceType.InstanceId => new HashSet<IdentityWithInstanceId>(badValues.Where(x => x is IdentityWithInstanceId).Select(x => (IdentityWithInstanceId)x)).ContainsIdentity(new InstanceIdentifier(ts.Space, ts.ExternalId)),
_ => false,
};
}

/// <summary>
/// Clean list of TimeSeriesCreate objects based on CogniteError
/// Clean list of SourceNodeWrite objects based on CogniteError
/// </summary>
/// <param name="error">Error that occured with a previous push</param>
/// <param name="timeseries">Timeseries to clean</param>
/// <returns>TimeSeries that are not affected by the error</returns>
/// <param name="timeseries">Nodes to clean</param>
/// <returns>Nodes that are not affected by the error</returns>
public static IEnumerable<SourcedNodeWrite<T>> CleanFromError<T>(
CogniteError<SourcedNodeWrite<T>> error,
IEnumerable<SourcedNodeWrite<T>> timeseries)
{
return CleanFromErrorCommon(error, timeseries, IsAffected,
ts => ts.ExternalId == null ? null : Identity.Create(ts.ExternalId),
ts => ts.ExternalId == null || ts.Space == null ? null : IdentityWithInstanceId.Create(new InstanceIdentifier(ts.Space, ts.ExternalId)),
CdfMetrics.TimeSeriesSkipped);
}
}
Expand Down
21 changes: 8 additions & 13 deletions ExtractorUtils/Cognite/Beta/CogniteDestinationWithIDM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using CogniteSdk;
using CogniteSdk.Beta.DataModels;
using Microsoft.Extensions.Logging;
using Cognite.Extractor.Common;
using CogniteSdk.Beta.DataModels.Core;
using CogniteSdk.Alpha;

Expand Down Expand Up @@ -61,11 +60,11 @@ public CogniteDestinationWithIDM(Client client, ILogger<CogniteDestination> logg
/// <paramref name="retryMode"/>
/// </summary>
/// <param name="instanceIds">Instance Ids</param>
/// <param name="buildTimeSeries">Function that builds CogniteSdk TimeSeriesCreate objects</param>
/// <param name="buildTimeSeries">Function that builds CogniteSdk TimeSeries objects</param>
/// <param name="retryMode">How to handle failed requests</param>
/// <param name="sanitationMode">The type of sanitation to apply to timeseries before creating</param>
/// <param name="sanitationMode">The type of sanitation to apply to TimeSeries before creating</param>
/// <param name="token">Cancellation token</param>
/// <returns>A <see cref="CogniteResult{TResult, TError}"/> containing errors that occurred and a list of the created and found timeseries</returns>
/// <returns>A <see cref="CogniteResult{TResult, TError}"/> containing errors that occurred and a list of the created and found TimeSeries</returns>
public async Task<CogniteResult<SourcedNode<T>, SourcedNodeWrite<T>>> GetOrCreateTimeSeriesAsync<T>(
IEnumerable<InstanceIdentifier> instanceIds,
Func<IEnumerable<InstanceIdentifier>, IEnumerable<SourcedNodeWrite<T>>> buildTimeSeries,
Expand Down Expand Up @@ -96,11 +95,11 @@ public async Task<CogniteResult<SourcedNode<T>, SourcedNodeWrite<T>>> GetOrCreat
/// <paramref name="retryMode"/>
/// </summary>
/// <param name="instanceIds">Instance Ids</param>
/// <param name="buildTimeSeries">Async function that builds CogniteSdk TimeSeriesCreate objects</param>
/// <param name="buildTimeSeries">Async function that builds CogniteSdk TimeSeries objects</param>
/// <param name="retryMode">How to handle failed requests</param>
/// <param name="sanitationMode">The type of sanitation to apply to timeseries before creating</param>
/// <param name="sanitationMode">The type of sanitation to apply to TimeSeries before creating</param>
/// <param name="token">Cancellation token</param>
/// <returns>A <see cref="CogniteResult{TResult, TError}"/> containing errors that occured and a list of the created and found timeseries</returns>
/// <returns>A <see cref="CogniteResult{TResult, TError}"/> containing errors that occured and a list of the created and found TimeSeries</returns>
public async Task<CogniteResult<SourcedNode<T>, SourcedNodeWrite<T>>> GetOrCreateTimeSeriesAsync<T>(
IEnumerable<InstanceIdentifier> instanceIds,
Func<IEnumerable<InstanceIdentifier>, Task<IEnumerable<SourcedNodeWrite<T>>>> buildTimeSeries,
Expand All @@ -125,11 +124,11 @@ public async Task<CogniteResult<SourcedNode<T>, SourcedNodeWrite<T>>> GetOrCreat
/// by setting <paramref name="retryMode"/>.
/// TimeSeries will be returned in the same order as given.
/// </summary>
/// <param name="updates">List of CogniteSdk TimeSeriesUpdateItem objects</param>
/// <param name="updates">List of CogniteSdk TimeSeries objects</param>
/// <param name="retryMode">How to do retries. Keeping duplicates is not valid for this method.</param>
/// <param name="sanitationMode">The type of sanitation to apply to assets before updating</param>
/// <param name="token">Cancellation token</param>
/// <returns>A <see cref="CogniteResult{TResult, TError}"/> containing errors that occured and a list of the updated timeseries</returns>
/// <returns>A <see cref="CogniteResult{TResult, TError}"/> containing errors that occured and a list of the updated TimeSeries</returns>
public async Task<CogniteResult<SlimInstance, SourcedNodeWrite<T>>> UpdateTimeSeriesAsync<T>(
IEnumerable<SourcedNodeWrite<T>> updates,
RetryMode retryMode,
Expand Down Expand Up @@ -255,7 +254,6 @@ public async Task<DeleteError> DeleteDataPointsIgnoreErrorsAsync(
#endregion

#region ranges

/// <summary>
/// Fetches the range of datapoints present in CDF. Limited by given ranges for each id.
/// Note that end limits closer to actual endpoints in CDF is considerably faster.
Expand Down Expand Up @@ -283,7 +281,6 @@ public async Task<DeleteError> DeleteDataPointsIgnoreErrorsAsync(
token);
}


/// <summary>
/// Fetches the range of datapoints present in CDF. Limited by given ranges for each id.
/// Note that end limits closer to actual endpoints in CDF is considerably faster.
Expand All @@ -310,8 +307,6 @@ public async Task<DeleteError> DeleteDataPointsIgnoreErrorsAsync(
earliest,
token);
}


#endregion
}
}
1 change: 0 additions & 1 deletion ExtractorUtils/Cognite/CogniteDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Cognite.Extensions.DataModels.CogniteExtractorExtensions;
using Cognite.Extractor.StateStorage;
using CogniteSdk;
using CogniteSdk.Beta.DataModels;
using Microsoft.Extensions.Logging;
using TimeRange = Cognite.Extractor.Common.TimeRange;

Expand Down

0 comments on commit 7f47ec3

Please sign in to comment.