Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollo3zehn committed Jul 24, 2024
1 parent e92f038 commit 5427b04
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 60 deletions.
3 changes: 0 additions & 3 deletions src/Nexus/API/SourcesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace Nexus.Controllers;
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
internal class SourcesController(
AppState appState,
IExtensionHive extensionHive,
IPipelineService pipelineService
) : ControllerBase
Expand All @@ -31,8 +30,6 @@ IPipelineService pipelineService
// POST /api/sources/registrations
// DELETE /api/sources/registrations/{registrationId}

private readonly AppState _appState = appState;

private readonly IExtensionHive _extensionHive = extensionHive;

private readonly IPipelineService _pipelineService = pipelineService;
Expand Down
5 changes: 1 addition & 4 deletions src/Nexus/API/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ namespace Nexus.Controllers;
[Route("api/v{version:apiVersion}/[controller]")]
internal class UsersController(
IDBService dBService,
ITokenService tokenService,
ILogger<UsersController> logger) : ControllerBase
ITokenService tokenService) : ControllerBase
{
// [anonymous]
// GET /api/users/authenticate
Expand Down Expand Up @@ -55,8 +54,6 @@ internal class UsersController(

private readonly ITokenService _tokenService = tokenService;

private readonly ILogger<UsersController> _logger = logger;

#region Anonymous

/// <summary>
Expand Down
37 changes: 16 additions & 21 deletions src/Nexus/Extensibility/DataSource/DataSourceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task InitializeAsync(
foreach (var (dataSource, registration) in _dataSources
.Zip(_registrations))
{
var logger = loggerFactory
var dataSourceLogger = loggerFactory
.CreateLogger($"{registration.Type} - {registration.ResourceLocator?.ToString() ?? "<null>"}");

var clonedSourceConfiguration = registration.Configuration is null
Expand All @@ -102,7 +102,7 @@ public async Task InitializeAsync(
SourceConfiguration: clonedSourceConfiguration,
RequestConfiguration: _requestConfiguration);

await dataSource.SetContextAsync(context, logger, cancellationToken);
await dataSource.SetContextAsync(context, dataSourceLogger, cancellationToken);
}
}

Expand Down Expand Up @@ -154,16 +154,13 @@ public async Task<ResourceCatalog> GetCatalogAsync(
_logger.LogDebug("Load catalog {CatalogId}", catalogId);

var catalog = new ResourceCatalog(catalogId);
var pipelinePosition = 0;

foreach (var dataSource in _dataSources)
for (var pipelinePosition = 0; pipelinePosition < _dataSources.Length; pipelinePosition++)
{
catalog = await dataSource.EnrichCatalogAsync(catalog, cancellationToken);
catalog = await _dataSources[pipelinePosition].EnrichCatalogAsync(catalog, cancellationToken);

// TODO: Is it the best solution to inject these additional properties here? Similar code exists in SourcesController.GetExtensionDescriptions()
catalog = catalog.EnsureAndSanitizeMandatoryProperties(pipelinePosition, _dataSources);

pipelinePosition++;
}

if (catalog.Id != catalogId)
Expand Down Expand Up @@ -247,8 +244,8 @@ public async Task<CatalogAvailability> GetAvailabilityAsync(
}

averagedAvailabilities[i] = count == 0
? averagedAvailabilities[i] = sum
: averagedAvailabilities[i] = sum / count;
? sum
: sum / count;
}

return new CatalogAvailability(Data: averagedAvailabilities);
Expand Down Expand Up @@ -301,9 +298,7 @@ public async Task ReadAsync(
*/

/* preparation */
var readUnits = PrepareReadUnits(
catalogItemRequestPipeWriters);

var readUnits = PrepareReadUnits(catalogItemRequestPipeWriters);
var readingTasks = new List<Task>(capacity: readUnits.Length);
var targetElementCount = ExtensibilityUtilities.CalculateElementCount(begin, end, samplePeriod);
var targetByteCount = sizeof(double) * targetElementCount;
Expand All @@ -323,13 +318,13 @@ public async Task ReadAsync(

var originalProgress = new Progress<double>();
var originalProgressFactor = originalReadUnits.Length / (double)readUnits.Length;
var originalProgress_old = 0.0;
var originalProgressValue_old = 0.0;

originalProgress.ProgressChanged += (sender, progressValue) =>
originalProgress.ProgressChanged += (sender, originalProgressValue) =>
{
var actualProgress = progressValue - originalProgress_old;
originalProgress_old = progressValue;
totalProgress += actualProgress;
var actualProgress = originalProgressValue - originalProgressValue_old;
originalProgressValue_old = originalProgressValue;
totalProgress += actualProgress * originalProgressFactor;
progress.Report(totalProgress);
};

Expand Down Expand Up @@ -361,13 +356,13 @@ public async Task ReadAsync(
foreach (var processingReadUnit in processingReadUnits)
{
var processingProgress = new Progress<double>();
var processingProgress_old = 0.0;
var processingProgressValue_old = 0.0;

processingProgress.ProgressChanged += (sender, progressValue) =>
{
var actualProgress = progressValue - processingProgress_old;
processingProgress_old = progressValue;
totalProgress += actualProgress;
var actualProgress = progressValue - processingProgressValue_old;
processingProgressValue_old = progressValue;
totalProgress += actualProgress * processingProgressFactor;
progress.Report(totalProgress);
};

Expand Down
1 change: 0 additions & 1 deletion src/Nexus/Extensions/Sources/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public async Task ReadAsync(
double[] dataDouble;

var beginTime = ToUnixTimeStamp(begin);
var endTime = ToUnixTimeStamp(end);
var elementCount = data.Length / representation.ElementSize;

// unit time
Expand Down
2 changes: 0 additions & 2 deletions src/Nexus/Services/DataControllerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ internal class DataControllerService(
IProcessingService processingService,
ICacheService cacheService,
IOptions<DataOptions> dataOptions,
ILogger<DataControllerService> logger,
ILoggerFactory loggerFactory) : IDataControllerService
{
public const string NexusConfigurationHeaderKey = "Nexus-Configuration";
Expand All @@ -40,7 +39,6 @@ internal class DataControllerService(
private readonly IExtensionHive _extensionHive = extensionHive;
private readonly IProcessingService _processingService = processingService;
private readonly ICacheService _cacheService = cacheService;
private readonly ILogger _logger = logger;
private readonly ILoggerFactory _loggerFactory = loggerFactory;

public async Task<IDataSourceController> GetDataSourceControllerAsync(
Expand Down
4 changes: 2 additions & 2 deletions src/Nexus/Services/PipelineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Task<Guid> PutAsync(
bool TryGet(
string userId,
Guid pipelineId,
[NotNullWhen(true)] out DataSourcePipeline? token);
[NotNullWhen(true)] out DataSourcePipeline? pipeline);

Task DeleteAsync(string userId, Guid pipelineId);

Expand Down Expand Up @@ -103,7 +103,7 @@ private ConcurrentDictionary<Guid, DataSourcePipeline> GetPipelineMap(
{
return _cache.GetOrAdd(
userId,
key =>
userId =>
{
if (_databaseService.TryReadPipelineMap(userId, out var jsonString))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ public static class PropertiesExtensions
{
pathSegments = pathSegments[1..];

if (pathSegments.Length == 0)
{
if (element.ValueKind == JsonValueKind.String || element.ValueKind == JsonValueKind.Null)
return element.GetString();
}
if (
pathSegments.Length == 0 &&
(element.ValueKind == JsonValueKind.String || element.ValueKind == JsonValueKind.Null)
)
return element.GetString();

else
{
return element.GetStringValue(pathSegments);
}
}

return default;
Expand Down Expand Up @@ -74,16 +72,13 @@ public static class PropertiesExtensions
{
pathSegments = pathSegments[1..];

if (pathSegments.Length == 0)
if (pathSegments.Length == 0 && element.ValueKind == JsonValueKind.Array)
{
if (element.ValueKind == JsonValueKind.Array)
{
return element
.EnumerateArray()
.Where(current => current.ValueKind == JsonValueKind.String || current.ValueKind == JsonValueKind.Null)
.Select(current => current.GetString())
.ToArray();
}
return element
.EnumerateArray()
.Where(current => current.ValueKind == JsonValueKind.String || current.ValueKind == JsonValueKind.Null)
.Select(current => current.GetString())
.ToArray();
}

else
Expand Down Expand Up @@ -127,16 +122,11 @@ public static class PropertiesExtensions
{
pathSegments = pathSegments[1..];

if (pathSegments.Length == 0)
{
if (element.ValueKind == JsonValueKind.Number)
return element.GetInt32();
}
if (pathSegments.Length == 0 && element.ValueKind == JsonValueKind.Number)
return element.GetInt32();

else
{
return element.GetIntValue(pathSegments);
}
}

return default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ internal bool TryFind(ResourcePathParseResult parseResult, [NotNullWhen(true)] o
parameters.ContainsKey(current.Key) &&

(current.Value.GetStringValue(typePath) == "input-integer" && long.TryParse(parameters[current.Key], out var _) ||
current.Value.GetStringValue(typePath) == "select" && true /* no validation here */)));
current.Value.GetStringValue(typePath) == "select" /* no validation here */)));

if (!parametersAreOK)
return false;
Expand Down
2 changes: 0 additions & 2 deletions tests/Nexus.Tests/Services/DataControllerServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public async Task CanCreateAndInitializeDataSourceController()
default!,
default!,
Options.Create(new DataOptions()),
default!,
loggerFactory);

// Act
Expand Down Expand Up @@ -122,7 +121,6 @@ public async Task CanCreateAndInitializeDataWriterController()
default!,
default!,
Options.Create(new DataOptions()),
default!,
loggerFactory);

var actual = await dataControllerService.GetDataWriterControllerAsync(
Expand Down
1 change: 0 additions & 1 deletion tests/Nexus.Tests/Services/DataServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public async Task CanExportAsync()
var begin = new DateTime(2020, 01, 01, 0, 0, 0, DateTimeKind.Utc);
var end = new DateTime(2020, 01, 03, 0, 0, 0, DateTimeKind.Utc);
var samplePeriod = TimeSpan.FromSeconds(1);
var exportId = Guid.NewGuid();

var registration1 = new DataSourceRegistration(Type: "A", new Uri("a", UriKind.Relative), default, default);
var pipeline1 = new DataSourcePipeline([registration1]);
Expand Down

0 comments on commit 5427b04

Please sign in to comment.