protected override async Task Context() { await base.Context(); A.CallTo(() => _jsonSerializer.Serialize(A <QualificationMapping> ._, _qualificationConfiguration.MappingFile)) .Invokes(x => _mapping = x.GetArgument <QualificationMapping>(0)); }
protected override async Task Context() { await base.Context(); _expectedOutputPath = Path.Combine(_qualificationConfiguration.OutputFolder, PROJECT_NAME); DirectoryHelper.DirectoryExists = s => string.Equals(s, _expectedOutputPath); DirectoryHelper.DeleteDirectory = (s, b) => _deletedDirectory = s; _simulationName = "S1"; _simulation = new Simulation { Name = _simulationName }; _individualSimulation = new IndividualSimulation { Name = _simulationName }; _input = new Input { Project = PROJECT_NAME, Name = _simulationName, SectionId = 2, Type = PKSimBuildingBlockType.Simulation, SectionLevel = 5 }; _expectedSimulationPath = Path.Combine(_expectedOutputPath, _simulationName); _simulationExport = new SimulationMapping { Project = PROJECT_NAME, Simulation = _simulationName, Path = _expectedSimulationPath }; _simulationExports = new[] { _simulationExport }; A.CallTo(() => _exportSimulationRunner.ExportSimulationsIn(_project, A <ExportRunOptions> ._)) .Invokes(x => _exportOptions = x.GetArgument <ExportRunOptions>(1)) .Returns(_simulationExports); _observedData = DomainHelperForSpecs.ObservedData().WithName("OBS"); _project.AddObservedData(_observedData); _projectSnapshot.Simulations = new[] { _simulation }; _expectedObservedDataXlsFullPath = Path.Combine(_qualificationConfiguration.ObservedDataFolder, $"{_observedData.Name}{Constants.Filter.XLSX_EXTENSION}"); _expectedObservedDataCsvFullPath = Path.Combine(_qualificationConfiguration.ObservedDataFolder, $"{_observedData.Name}{Constants.Filter.CSV_EXTENSION}"); _expectedInputFullPath = Path.Combine(_qualificationConfiguration.InputsFolder, PROJECT_NAME, PKSimBuildingBlockType.Simulation.ToString(), $"{_simulationName}{CoreConstants.Filter.MARKDOWN_EXTENSION}"); A.CallTo(() => _jsonSerializer.Serialize(A <QualificationMapping> ._, _qualificationConfiguration.MappingFile)) .Invokes(x => _mapping = x.GetArgument <QualificationMapping>(0)); _project.AddBuildingBlock(_individualSimulation); _qualificationConfiguration.Inputs = new[] { _input }; _qualificationConfiguration.Simulations = new[] { _simulationName, }; _runOptions.Run = true; }
protected override async Task Context() { await base.Context(); var simulation = new Simulation().WithName("Sim"); _curveChart = new CurveChart(); simulation.IndividualAnalyses = new[] { _curveChart }; _simulationPlot = new SimulationPlot { SectionId = 2, Simulation = simulation.Name }; _projectSnapshot.Simulations = new[] { simulation }; _qualificationConfiguration.SimulationPlots = new[] { _simulationPlot }; A.CallTo(() => _jsonSerializer.Serialize(A <QualificationMapping> ._, _qualificationConfiguration.MappingFile)) .Invokes(x => _mapping = x.GetArgument <QualificationMapping>(0)); }
/// <summary> /// Update /// </summary> /// <param name="contract"></param> /// <param name="cancellationToken"></param> public async Task <bool> AddQualification(QualificationContract contract, CancellationToken cancellationToken) { var checkQualification = await _dbContext.Qualifications.FirstOrDefaultAsync(x => x.CoachId == contract.CoachId && x.ServiceId == contract.ServiceId, cancellationToken); if (checkQualification != null) { _logger.LogInformation($"Qualification with {contract.CoachId} and {contract.ServiceId} is found"); return(false); } var tryGetCoach = await _dbContext.Coaches.FirstOrDefaultAsync(x => x.Id == contract.CoachId, cancellationToken); var tryGetService = await _dbContext.Services.FirstOrDefaultAsync(x => x.Id == contract.ServiceId, cancellationToken); if (tryGetService == null || tryGetCoach == null) { _logger.LogInformation($"No Coach with {contract.CoachId} or Service with {contract.ServiceId} id"); return(false); } try { var qualification = QualificationMapping.QualificationMapFromContractToModel(contract); await _dbContext.AddAsync(qualification, cancellationToken); await _dbContext.SaveChangesAsync(cancellationToken); } catch { _logger.LogInformation($"Qualification with id {contract.Id} is not found"); return(false); } return(true); }
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); }
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); }