Beispiel #1
0
        public IEnumerable <ScenarioResult> CalculateBRSIndicators(Run run, int?brsConfigurationTemplateId = null)
        {
            if (run.Scenarios.Count == 1)
            {
                throw new Exception("Impossible to calculate BRS Indicators for run with 1 scenario.");
            }

            if (!run.HasAllScenarioCompletedSuccessfully)
            {
                throw new Exception("Impossible to calculate BRS Indicators for not successfully completed run.");
            }

            var id = brsConfigurationTemplateId.HasValue
                ? brsConfigurationTemplateId.Value
                : run.BRSConfigurationTemplateId;

            var brsConfigurationTemplate = _brsConfigurationTemplateRepository.Get(id);

            if (brsConfigurationTemplate == null)
            {
                throw new Exception($"BRS configuration with id {id} not found");
            }

            var infoLabel = $"(RunID={run.Id}, BRSConfigurationTemplateId={run.BRSConfigurationTemplateId})";

            RaiseInfo($"BRS template {infoLabel}: {JsonConvert.SerializeObject(brsConfigurationTemplate)}");

            var scenarioResults = _scenarioResultRepository.Find(run.Scenarios.Select(x => x.Id).ToArray());

            RaiseInfo($"ScenarioResults before calculation {infoLabel}: {JsonConvert.SerializeObject(scenarioResults)}");

            var kpiPriorities = _kpiPriorityRepository.GetAll();

            return(_brsCalculator.Calculate(brsConfigurationTemplate.KPIConfigurations, scenarioResults, kpiPriorities));
        }
Beispiel #2
0
        public IHttpActionResult Get(Guid scenarioId)
        {
            var scenarioResult = _scenarioResultRepository.Find(scenarioId);

            if (scenarioResult == null)
            {
                return(NotFound());
            }
            var scenarioResultModel = _mapper.Map <ScenarioResultModel>(scenarioResult);

            // Add failures. This is a temporary solution until the frontend is
            // changed. Originally then failures were stored in the ScenarioResult document.
            // TODO: Remove Failures property from ScenarioResultModel when frontend has been changed.
            var failures = _failuresRepository.Get(scenarioId);

            if (failures != null)
            {
                var failuresList = GetFailureModels(failures.Items);
                failuresList.ForEach(item => scenarioResultModel.Failures.Add(item));
            }

            Run run = _runRepository.FindByScenarioId(scenarioId);

            scenarioResultModel.Run = new RunReference()
            {
                Id          = run.Id,
                Description = run.Description
            };
            return(Ok(scenarioResultModel));
        }
        public void Handle(Run run, Guid scenarioId)
        {
            bool cleanup = true;

            try
            {
                // Check for scenario result, shouldn't exist
                ScenarioResult scenarioResult = _scenarioResultRepository.Find(scenarioId);
                if (scenarioResult is null)
                {
                    scenarioResult = new ScenarioResult
                    {
                        Id            = scenarioId,
                        TimeCompleted = DateTime.UtcNow
                    };
                }

                // Download output files from AWS
                DownloadOutputFiles(run.Id, scenarioId, GetScenarioLocalFolder(scenarioId));

                // Process output files
                ProcessOutputFiles(run.Id, scenarioId, scenarioResult);
                cleanup = false;
            }
            catch (Exception exception)
            {
                //adding the audit event to clear the warning of 'exception declared but never used' and preserves stack trace with the 'throw'
                _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForException(0, 0, String.Format("Error handling output file for scenario ID: {0}", scenarioId), exception));
                throw;
            }
            finally
            {
                // Delete all output data if it failed
                if (cleanup)
                {
                    try
                    {
                        DeleteOutputData(scenarioId);
                    }
                    catch { };
                }
            }
        }