Пример #1
0
        public IEnumerable <ScenarioResult> CalculateBRSIndicatorsAfterRunCompleted(Run run)
        {
            if (run.Scenarios.Count > 1 && run.HasAllScenarioCompletedSuccessfully)
            {
                var infoLabel = $"(RunID={run.Id}, BRSConfigurationTemplateId={run.BRSConfigurationTemplateId})";

                RaiseInfo($"Starting calculation of BRS Indicator {infoLabel}. Scenarios info: {run.Scenarios.Select(x => new { ScenarioId = x.Id, x.Status }) }");
                var scenarioResults = CalculateBRSIndicators(run);
                RaiseInfo($"Scenario results after calculation {infoLabel}: {JsonConvert.SerializeObject(scenarioResults)}");
                _scenarioResultRepository.UpdateRange(scenarioResults);
                _scenarioResultRepository.SaveChanges();
                RaiseInfo($"Finished calculation of BRS Indicator {infoLabel}");

                return(scenarioResults);
            }

            return(null);
        }
Пример #2
0
        public IHttpActionResult PostCalculateAndSave(Guid runId, int?brsConfigurationTemplateId = null)
        {
            var run = _runRepository.Find(runId);

            if (run == null)
            {
                return(NotFound());
            }

            var scenarioResults = _brsManager.CalculateBRSIndicators(run, brsConfigurationTemplateId);

            _scenarioResultRepository.UpdateRange(scenarioResults);
            if (brsConfigurationTemplateId.HasValue)
            {
                run.BRSConfigurationTemplateId = brsConfigurationTemplateId.Value;
                _runRepository.Update(run);
            }
            _scenarioResultRepository.SaveChanges();

            return(Ok(_mapper.Map <List <BRSIndicatorValueForScenarioResultModel> >(scenarioResults)));
        }
Пример #3
0
        /// <summary>
        /// Processes files. For each file we pass it to a file processor which
        /// performs some action on it.
        /// </summary>
        /// <param name="runId">RunID</param>
        /// <param name="scenarioId">ScenarioId</param>
        /// <param name="scenarioResult"></param>
        private void ProcessOutputFiles(Guid runId, Guid scenarioId, ScenarioResult scenarioResult)
        {
            _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForGameplanPipelineStart(0, 0, PipelineEventIDs.STARTED_EXPORTING_DATA_TO_DATABASE, runId, scenarioId, null, null));
            _pipelineAuditEventRepository.Add(PipelineEventHelper.CreatePipelineAuditEvent(AuditEventTypes.GamePlanRun,
                                                                                           PipelineEventIDs.STARTED_EXPORTING_DATA_TO_DATABASE, runId, scenarioId, null));

            string scenarioLocalFolder      = GetScenarioLocalFolder(scenarioId);
            var    dataProcessingExceptions = new List <Exception>();

            using (var kpiCalculationScope = _kpiCalculationScopeFactory.CreateCalculationScope(runId, scenarioId))
            {
                var kpiCalculationContext = kpiCalculationScope.Resolve <IKPICalculationContext>();
                var kpiCalculationManager = kpiCalculationScope.Resolve <IKPICalculationManager>();

                foreach (var dataProcessingAction in _dataProcessingActions)
                {
                    try
                    {
                        dataProcessingAction(kpiCalculationScope, _featureManager, _auditEventRepository, scenarioLocalFolder);
                    }
                    catch (Exception e)
                    {
                        _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForException(0, 0,
                                                                                                    $"Error processing: {dataProcessingAction.Method.GetGenericArguments().First().Name}. ScenarioId: {scenarioId}", e));

                        dataProcessingExceptions.Add(e);
                    }
                }

                if (_includeScenarioPerformanceMeasurementKPIs)
                {
                    kpiCalculationContext.SetDefaultKpiDemos();
                }

                _scenarioCampaignMetricsProcessor.ProcessScenarioCampaignMetrics(runId, scenarioId, kpiCalculationContext.Recommendations);

                scenarioResult.Metrics = kpiCalculationManager.CalculateKPIs(runId, scenarioId);
                scenarioResult.AnalysisGroupMetrics = kpiCalculationManager.CalculateAnalysisGroupKPIs(runId);

                _scenarioResultRepository.Add(scenarioResult);
                _scenarioResultRepository.SaveChanges();
            }

            // Exceptions handling
            if (dataProcessingExceptions.Count == 1)
            {
                _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForGameplanPipelineEnd(0, 0,
                                                                                                      PipelineEventIDs.FINISHED_EXPORTING_DATA_TO_DATABASE, runId, scenarioId, null, null,
                                                                                                      dataProcessingExceptions[0].Message, dataProcessingExceptions[0]));

                throw dataProcessingExceptions[0];
            }
            else if (dataProcessingExceptions.Count > 1)
            {
                _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForGameplanPipelineEnd(0, 0,
                                                                                                      PipelineEventIDs.FINISHED_EXPORTING_DATA_TO_DATABASE, runId, scenarioId, null, null,
                                                                                                      dataProcessingExceptions[0].Message, dataProcessingExceptions[0]));

                throw new AggregateException(dataProcessingExceptions);
            }

            _auditEventRepository.Insert(AuditEventFactory.CreateAuditEventForGameplanPipelineEnd(0, 0,
                                                                                                  PipelineEventIDs.FINISHED_EXPORTING_DATA_TO_DATABASE, runId, scenarioId, null,
                                                                                                  "Import has been finished", null, null));

            _pipelineAuditEventRepository.Add(PipelineEventHelper.CreatePipelineAuditEvent(AuditEventTypes.GamePlanRun,
                                                                                           PipelineEventIDs.FINISHED_EXPORTING_DATA_TO_DATABASE, runId, scenarioId, null));

            _pipelineAuditEventRepository.SaveChanges();
        }