Esempio n. 1
0
        /// <summary>
        /// Returns RunModels for runs
        /// </summary>
        /// <param name="runs"></param>
        /// <param name="scenarioRepository"></param>
        /// <param name="passRepository"></param>
        /// <param name="analysisGroupRepository"></param>
        /// <param name="tenantSettingsRepository"></param>
        /// <returns></returns>
        public static List <RunModel> MapToRunModels(IEnumerable <Run> runs, IScenarioRepository scenarioRepository,
                                                     IPassRepository passRepository, IAnalysisGroupRepository analysisGroupRepository,
                                                     ITenantSettingsRepository tenantSettingsRepository, IMapper mapper)
        {
            // Get scenarios for all runs
            var scenarios = scenarioRepository.FindByIds(runs.SelectMany(r => r.Scenarios).Select(s => s.Id).Distinct()).ToList();

            // Get passes for all runs
            var passes = passRepository.FindByIds(scenarios.SelectMany(s => s.Passes).Select(p => p.Id).Distinct()).ToList();

            var analysisGroupIds = runs.SelectMany(x => x.AnalysisGroupTargets.Select(t => t.AnalysisGroupId)).ToArray();
            var analysisGroups   = analysisGroupIds.Any()
                ? analysisGroupRepository.GetByIds(analysisGroupIds).ToDictionary(x => x.Id)
                : new Dictionary <int, AnalysisGroupNameModel>();

            // Get default ScenarioId
            var defaultScenarioId = tenantSettingsRepository.Get().DefaultScenarioId;

            List <RunModel> runModels = new List <RunModel>();

            foreach (var run in runs)
            {
                var runModel = mapper.Map <RunModel>(Tuple.Create(run, scenarios, passes, analysisGroups, defaultScenarioId));
                runModels.Add(runModel);
            }
            return(runModels);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns RunModel with BasicData for run
        /// </summary>
        /// <param name="run"></param>
        /// <param name="scenarioRepository"></param>
        /// <returns></returns>
        public static RunModel MapToRunModel(Run run, IScenarioRepository scenarioRepository, IMapper mapper)
        {
            // Get scenarios for run
            var scenarios = scenarioRepository.FindByIds(run.Scenarios.Select(s => s.Id)).ToList();

            var runModel = mapper.Map <RunModel>(Tuple.Create(run, scenarios));

            return(runModel);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns RunModel for run
        /// </summary>
        /// <param name="run"></param>
        /// <param name="scenarioRepository"></param>
        /// <param name="passRepository"></param>
        /// <param name="tenantSettingsRepository"></param>
        /// <param name="allCampaigns"></param>
        /// <param name="functionalAreaRepository"></param>
        /// <returns></returns>
        public static RunModel MapToRunModel(Run run, IScenarioRepository scenarioRepository, IPassRepository passRepository,
                                             ITenantSettingsRepository tenantSettingsRepository, IMapper mapper,
                                             IAnalysisGroupRepository analysisGroupRepository,
                                             IFunctionalAreaRepository functionalAreaRepository = null,
                                             IScenarioCampaignMetricRepository scenarioCampaignMetricRepository = null,
                                             List <CampaignWithProductFlatModel> allCampaigns = null,
                                             List <Pass> passesFromDb = null, List <Scenario> scenariosFromDb = null)
        {
            // Get scenarios for run
            var scenarios = scenariosFromDb ?? scenarioRepository.FindByIds(run.Scenarios.Select(s => s.Id)).ToList();

            // Get passes for run
            var passes = passesFromDb ?? passRepository.FindByIds(scenarios.SelectMany(s => s.Passes).Select(p => p.Id).Distinct()).ToList();

            var analysisGroups = run.AnalysisGroupTargets.Any()
                ? analysisGroupRepository.GetByIds(run.AnalysisGroupTargets.Select(x => x.AnalysisGroupId).ToArray()).ToDictionary(x => x.Id)
                : new Dictionary <int, AnalysisGroupNameModel>();

            // Get default ScenarioId
            var defaultScenarioId = tenantSettingsRepository.GetDefaultScenarioId();

            if (run.RunStatus == RunStatus.NotStarted && allCampaigns != null && allCampaigns.Any())
            {
                // Since the run has not already started amend Run Scenarios
                // with CampaignPassPriorities for new Campaigns and remove
                // CampaignPassPriorities of deleted Campaigns
                CampaignPassPrioritiesServiceMapper.AmendCampaignPassPriorities(
                    scenarios,
                    passes,
                    allCampaigns,
                    passRepository,
                    mapper);
            }

            var runModel = mapper.Map <RunModel>(Tuple.Create(run, scenarios, passes, analysisGroups, defaultScenarioId));

            if (run.RunStatus == RunStatus.Complete)
            {
                ApplyFunctionalAreaFaultTypesToRunModel(runModel, run, functionalAreaRepository);
            }

            if (scenarioCampaignMetricRepository != null)
            {
                runModel.Scenarios.ForEach(s => ApplyKPIsToScenarioCampaigns(s, scenarioCampaignMetricRepository));
            }

            return(runModel);
        }