public static List <AggregationInstruction> ComputeInstructions(AggregationSetup setup, DatabaseManagerState state, ILogger logger) { var projectIds = setup.Aggregations .Select(aggregation => aggregation.ProjectId) .Distinct().ToList(); return(projectIds.Select(projectId => { var container = state.Database.ProjectContainers.FirstOrDefault(container => container.Id == projectId); if (container is null) { return null; } var dataReaderRegistrations = container .Project .Channels .SelectMany(channel => channel.Datasets.Select(dataset => dataset.Registration)) .Distinct() .Where(registration => registration != state.AggregationRegistration) .ToList(); return new AggregationInstruction(container, dataReaderRegistrations.ToDictionary(registration => registration, registration => { // find aggregations for project ID var potentialAggregations = setup.Aggregations .Where(parameters => parameters.ProjectId == container.Project.Id) .ToList(); // create channel to aggregations map var aggregationChannels = container.Project.Channels // find all channels for current reader registration .Where(channel => channel.Datasets.Any(dataset => dataset.Registration == registration)) // find all aggregations for current channel .Select(channel => { var channelMeta = container.ProjectMeta.Channels .First(current => current.Id == channel.Id); return new AggregationChannel() { Channel = channel, Aggregations = potentialAggregations.Where(current => AggregationService.ApplyAggregationFilter(channel, channelMeta, current.Filters, logger)).ToList() }; }) // take all channels with aggregations .Where(aggregationChannel => aggregationChannel.Aggregations.Any()); return aggregationChannels.ToList(); })); }).Where(instruction => instruction != null).ToList()); }
public JobEditor(DatabaseManager databaseManager) { _state = databaseManager.State; this.Update(); }