示例#1
0
        public async Task RunBatchAsync(QualificationRunOptions runOptions)
        {
            _snapshotProjectCache.Clear();
            _logger.AddInfo(runOptions.Validate ? "Starting validation run..." : "Starting qualification run...");

            var config = await readConfigurationFrom(runOptions);

            if (config == null)
            {
                throw new QualificationRunException(UnableToLoadQualificationConfigurationFromFile(runOptions.ConfigurationFile));
            }

            var errorMessage = config.Validate().Message;

            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new QualificationRunException(errorMessage);
            }

            _logger.AddDebug($"Loading project from snapshot file '{config.SnapshotFile}'...");
            var snapshot = await snapshotProjectFromFile(config.SnapshotFile);

            //Ensures that the name of the snapshot is also the name of the project as defined in the configuration
            snapshot.Name = config.Project;
            _logger.AddDebug($"Project {snapshot.Name} loaded from snapshot file '{config.SnapshotFile}'.");

            await performBuildingBlockSwap(snapshot, config.BuildingBlocks);

            await performSimulationParameterSwap(snapshot, config.SimulationParameters);

            //Retrieve charts and validate inputs before exiting validation to ensure that we can throw error messages if an element is not available
            var plots = retrievePlotDefinitionsFrom(snapshot, config);

            validateInputs(snapshot, config);

            if (runOptions.Validate)
            {
                _logger.AddInfo($"Validation run terminated for {snapshot.Name}");
                return;
            }

            var begin   = DateTime.UtcNow;
            var project = await _snapshotTask.LoadProjectFromSnapshot(snapshot);

            _workspace.Project = project;

            var projectOutputFolder = createProjectOutputFolder(config.OutputFolder, project.Name);

            _logger.AddDebug($"Exporting project {project.Name} to '{projectOutputFolder}'", project.Name);

            var exportRunOptions = new ExportRunOptions
            {
                OutputFolder = projectOutputFolder,
                ExportMode   = SimulationExportMode.Xml | SimulationExportMode.Csv
            };

            var simulationExports = await _exportSimulationRunner.ExportSimulationsIn(project, exportRunOptions);

            var simulationMappings = simulationExports.Select(x => simulationMappingFrom(x, config)).ToArray();

            var observedDataMappings = await exportAllObservedData(project, config);

            var inputMappings = exportInputs(project, config);

            var mapping = new QualificationMapping
            {
                SimulationMappings   = simulationMappings,
                ObservedDataMappings = observedDataMappings,
                Plots  = plots,
                Inputs = inputMappings
            };

            await _jsonSerializer.Serialize(mapping, config.MappingFile);

            _logger.AddDebug($"Project mapping for '{project.Name}' exported to '{config.MappingFile}'", project.Name);

            var projectFile = Path.Combine(config.TempFolder, $"{project.Name}{CoreConstants.Filter.PROJECT_EXTENSION}");

            _workspacePersistor.SaveSession(_workspace, projectFile);
            _logger.AddDebug($"Project saved to '{projectFile}'", project.Name);

            var snapshotFile = Path.Combine(config.TempFolder, $"{project.Name}{Constants.Filter.JSON_EXTENSION}");
            await _snapshotTask.ExportModelToSnapshot(project, snapshotFile);

            _logger.AddDebug($"Project snapshot saved to '{snapshotFile}'", project.Name);

            var end       = DateTime.UtcNow;
            var timeSpent = end - begin;

            _logger.AddInfo($"Project '{project.Name}' exported for qualification in {timeSpent.ToDisplay()}", project.Name);
        }
示例#2
0
        public async Task RunBatchAsync(QualificationRunOptions runOptions)
        {
            _snapshotProjectCache.Clear();
            _logger.AddInfo(runOptions.Validate ? "Starting validation run..." : "Starting qualification run...");

            var config = await readConfigurationFrom(runOptions);

            if (config == null)
            {
                throw new QualificationRunException(UnableToLoadQualificationConfigurationFromFile(runOptions.ConfigurationFile));
            }

            var errorMessage = config.Validate().Message;

            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new QualificationRunException(errorMessage);
            }

            _logger.AddDebug($"Loading project from snapshot file '{config.SnapshotFile}'...", categoryName: config.Project);
            var snapshot = await snapshotProjectFromFile(config.SnapshotFile);

            //Ensures that the name of the snapshot is also the name of the project as defined in the configuration
            snapshot.Name = config.Project;
            _logger.AddDebug($"Project {snapshot.Name} loaded from snapshot file '{config.SnapshotFile}'.", categoryName: snapshot.Name);

            await performBuildingBlockSwap(snapshot, config.BuildingBlocks);

            await performSimulationParameterSwap(snapshot, config.SimulationParameters);

            //Retrieve charts and validate inputs before exiting validation to ensure that we can throw error messages if an element is not available
            var plots = retrievePlotDefinitionsFrom(snapshot, config);

            validateInputs(snapshot, config);

            if (runOptions.Validate)
            {
                _logger.AddInfo($"Validation run terminated for {snapshot.Name}", categoryName: snapshot.Name);
                return;
            }

            var begin   = DateTime.UtcNow;
            var project = await _snapshotTask.LoadProjectFromSnapshotAsync(snapshot, runOptions.Run);

            _workspace.Project = project;

            var projectOutputFolder = createProjectOutputFolder(config.OutputFolder, project.Name);

            _logger.AddDebug($"Exporting project {project.Name} to '{projectOutputFolder}'", project.Name);

            var exportRunOptions = new ExportRunOptions
            {
                OutputFolder = projectOutputFolder,
                //We run the output, this is for the old matlab implementation where we need xml. Otherwise, we only need pkml export
                ExportMode = runOptions.Run ? SimulationExportMode.Xml | SimulationExportMode.Csv : SimulationExportMode.Pkml,

                Simulations = config.Simulations,

                //We only want to export what is required in this case
                ExportAllSimulationsIfListIsEmpty = false
            };

            //Using absolute path for simulation folder. We need them to be relative
            var simulationMappings = await _exportSimulationRunner.ExportSimulationsIn(project, exportRunOptions);

            simulationMappings.Each(x => x.Path = relativePath(x.Path, config.OutputFolder));

            var observedDataMappings = await exportAllObservedData(project, config);

            var inputMappings = exportInputs(project, config);

            var mapping = new QualificationMapping
            {
                SimulationMappings   = simulationMappings,
                ObservedDataMappings = observedDataMappings,
                Plots  = plots,
                Inputs = inputMappings
            };

            await _jsonSerializer.Serialize(mapping, config.MappingFile);

            _logger.AddDebug($"Project mapping for '{project.Name}' exported to '{config.MappingFile}'", project.Name);

            if (runOptions.ExportProjectFiles)
            {
                var projectFile = Path.Combine(config.TempFolder, $"{project.Name}{CoreConstants.Filter.PROJECT_EXTENSION}");
                _workspacePersistor.SaveSession(_workspace, projectFile);
                _logger.AddDebug($"Project saved to '{projectFile}'", project.Name);

                var snapshotFile = Path.Combine(config.TempFolder, $"{project.Name}{Constants.Filter.JSON_EXTENSION}");
                await _snapshotTask.ExportModelToSnapshotAsync(project, snapshotFile);

                _logger.AddDebug($"Project snapshot saved to '{snapshotFile}'", project.Name);
            }

            var end       = DateTime.UtcNow;
            var timeSpent = end - begin;

            _logger.AddInfo($"Project '{project.Name}' exported for qualification in {timeSpent.ToDisplay()}", project.Name);
        }