// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using Ringtoets.AssemblyTool.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Exceptions;
using Ringtoets.Integration.IO.Assembly;
using Ringtoets.Integration.IO.Helpers;
using Ringtoets.MacroStabilityInwards.Data;
namespace Ringtoets.Integration.IO.Factories
{
///
/// Factory to create instances of
/// with assembly results for macro stability inwards.
///
public static class ExportableMacroStabilityInwardsFailureMechanismFactory
{
private const ExportableFailureMechanismGroup failureMechanismGroup = ExportableFailureMechanismGroup.Group2;
private const ExportableFailureMechanismType failureMechanismCode = ExportableFailureMechanismType.STBI;
private const ExportableAssemblyMethod failureMechanismAssemblyMethod = ExportableAssemblyMethod.WBI1B1;
///
/// Creates an
/// with assembly results based on the input parameters.
///
/// The to create an
/// for.
/// The assessment section the failure mechanism belongs to.
/// An with assembly results.
/// Thrown when any parameter is null.
/// Thrown when assembly results cannot be created.
public static ExportableFailureMechanism CreateExportableFailureMechanism(
MacroStabilityInwardsFailureMechanism failureMechanism,
IAssessmentSection assessmentSection)
{
if (failureMechanism == null)
{
throw new ArgumentNullException(nameof(failureMechanism));
}
if (assessmentSection == null)
{
throw new ArgumentNullException(nameof(assessmentSection));
}
if (!failureMechanism.IsRelevant)
{
return ExportableFailureMechanismFactory.CreateDefaultExportableFailureMechanismWithProbability(assessmentSection,
failureMechanismCode,
failureMechanismGroup,
failureMechanismAssemblyMethod);
}
FailureMechanismAssembly failureMechanismAssembly = MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection, false);
return new ExportableFailureMechanism(
new ExportableFailureMechanismAssemblyResultWithProbability(failureMechanismAssemblyMethod,
failureMechanismAssembly.Group,
failureMechanismAssembly.Probability),
CreateExportableFailureMechanismSectionResults(failureMechanism, assessmentSection),
failureMechanismCode,
failureMechanismGroup);
}
///
/// Creates a collection of
/// with assembly results based on .
///
/// The to create a collection
/// of for.
/// The assessment section the failure mechanism belongs to.
/// A collection of .
/// Thrown when assembly results cannot be created.
private static IEnumerable CreateExportableFailureMechanismSectionResults(
MacroStabilityInwardsFailureMechanism failureMechanism,
IAssessmentSection assessmentSection)
{
IDictionary failureMechanismSectionsLookup =
ExportableFailureMechanismSectionHelper.CreateFailureMechanismSectionResultLookup(failureMechanism.SectionResults);
IEnumerable macroStabilityInwardsCalculationScenarios =
failureMechanism.Calculations.Cast();
var exportableResults = new List();
foreach (KeyValuePair failureMechanismSectionPair in failureMechanismSectionsLookup)
{
MacroStabilityInwardsFailureMechanismSectionResult failureMechanismSectionResult = failureMechanismSectionPair.Key;
FailureMechanismSectionAssembly simpleAssembly =
MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment(failureMechanismSectionResult);
FailureMechanismSectionAssembly detailedAssembly =
MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment(failureMechanismSectionResult,
macroStabilityInwardsCalculationScenarios,
failureMechanism,
assessmentSection);
FailureMechanismSectionAssembly tailorMadeAssembly =
MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(failureMechanismSectionResult,
failureMechanism,
assessmentSection);
FailureMechanismSectionAssembly combinedAssembly =
MacroStabilityInwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment(failureMechanismSectionResult,
macroStabilityInwardsCalculationScenarios,
failureMechanism,
assessmentSection);
exportableResults.Add(
new ExportableAggregatedFailureMechanismSectionAssemblyResultWithProbability(
failureMechanismSectionPair.Value,
ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(simpleAssembly, ExportableAssemblyMethod.WBI0E1),
ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(detailedAssembly, ExportableAssemblyMethod.WBI0G5),
ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(tailorMadeAssembly, ExportableAssemblyMethod.WBI0T5),
ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(combinedAssembly, ExportableAssemblyMethod.WBI0A1)));
}
return exportableResults;
}
}
}