Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Factories/RingtoetsStackChartDataFactory.cs =================================================================== diff -u -r65a84aed979055e2b6930528f392b2cac5f4405b -r3748f21da69e2c5a0f5d59168ed1d00807bedf00 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Factories/RingtoetsStackChartDataFactory.cs (.../RingtoetsStackChartDataFactory.cs) (revision 65a84aed979055e2b6930528f392b2cac5f4405b) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Factories/RingtoetsStackChartDataFactory.cs (.../RingtoetsStackChartDataFactory.cs) (revision 3748f21da69e2c5a0f5d59168ed1d00807bedf00) @@ -21,9 +21,11 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using Core.Components.Stack.Data; using Ringtoets.Common.Data.Hydraulics.IllustrationPoints; +using Ringtoets.Common.Forms.Properties; namespace Ringtoets.Common.Forms.Factories { @@ -32,6 +34,8 @@ /// public static class RingtoetsStackChartDataFactory { + private const double minAlphaSquared = 0.01; + /// /// Creates a new . /// @@ -78,5 +82,107 @@ stackChartData.AddColumn(columnName); } } + + /// + /// Creates the rows for the given . + /// + /// The data to create the rows from. + /// The stack chart data to create the rows for. + /// Thrown when any parameter is null. + public static void CreateRows(GeneralResult generalResult, StackChartData stackChartData) + { + if (generalResult == null) + { + throw new ArgumentNullException(nameof(generalResult)); + } + if (stackChartData == null) + { + throw new ArgumentNullException(nameof(stackChartData)); + } + + var stochastValues = new List>(); + + foreach (WindDirectionClosingSituationIllustrationPoint illustrationPoint in generalResult.WindDirectionClosingSituationIllustrationPoints) + { + stochastValues.AddRange(illustrationPoint.IllustrationPoint.Stochasts + .Select(illustrationPointStochast => + new Tuple(illustrationPointStochast.Name, + Math.Pow(illustrationPointStochast.Alpha, 2)))); + } + + IDictionary> stochasts = CreateStochastsLookup(stochastValues); + + CreateRowsForStochasts(stackChartData, stochasts); + } + + private static IDictionary> CreateStochastsLookup(List> stochastValues) + { + IDictionary> lookup = new Dictionary>(); + + foreach (Tuple stochastValue in stochastValues) + { + if (!lookup.ContainsKey(stochastValue.Item1)) + { + lookup.Add(stochastValue.Item1, new List()); + } + + lookup[stochastValue.Item1].Add(stochastValue.Item2); + } + return lookup; + } + + private static void CreateRowsForStochasts(StackChartData stackChartData, IDictionary> stochasts) + { + IDictionary> significantStochasts = new Dictionary>(); + IDictionary> remainingStochasts = new Dictionary>(); + + foreach (KeyValuePair> stochast in stochasts) + { + if (!StochastIsSignificant(stochast)) + { + significantStochasts.Add(stochast); + } + else + { + remainingStochasts.Add(stochast); + } + } + + foreach (KeyValuePair> significantStochast in significantStochasts) + { + stackChartData.AddRow(significantStochast.Key, significantStochast.Value.ToArray()); + } + + if (remainingStochasts.Any()) + { + stackChartData.AddRow(Resources.RingtoetsStackChartDataFactory_RemainingRow_DisplayName, + CreateRemainingRow(remainingStochasts), + Color.Gray); + } + } + + private static bool StochastIsSignificant(KeyValuePair> stochast) + { + return stochast.Value.Any(v => v < minAlphaSquared); + } + + private static double[] CreateRemainingRow(IDictionary> stochasts) + { + var values = new double[stochasts.First().Value.Count]; + var index = 0; + + foreach (KeyValuePair> stochast in stochasts) + { + foreach (double value in stochast.Value) + { + values[index] += value; + index++; + } + + index = 0; + } + + return values; + } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -rc5ac6656bddb53b9a1ec2edd5ca2f19c5b7d8e80 -r3748f21da69e2c5a0f5d59168ed1d00807bedf00 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision c5ac6656bddb53b9a1ec2edd5ca2f19c5b7d8e80) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 3748f21da69e2c5a0f5d59168ed1d00807bedf00) @@ -2068,6 +2068,15 @@ } /// + /// Looks up a localized string similar to Overig. + /// + public static string RingtoetsStackChartDataFactory_RemainingRow_DisplayName { + get { + return ResourceManager.GetString("RingtoetsStackChartDataFactory_RemainingRow_DisplayName", resourceCulture); + } + } + + /// /// Looks up a localized string similar to -. /// public static string RoundedRouble_No_result_dash { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx =================================================================== diff -u -rc5ac6656bddb53b9a1ec2edd5ca2f19c5b7d8e80 -r3748f21da69e2c5a0f5d59168ed1d00807bedf00 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision c5ac6656bddb53b9a1ec2edd5ca2f19c5b7d8e80) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 3748f21da69e2c5a0f5d59168ed1d00807bedf00) @@ -1041,4 +1041,7 @@ Windrichting + + Overig + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/IllustrationPointsChartControl.cs =================================================================== diff -u -r095b567e3a7a0e61dd92b0e68fc6f5db883ebcdd -r3748f21da69e2c5a0f5d59168ed1d00807bedf00 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/IllustrationPointsChartControl.cs (.../IllustrationPointsChartControl.cs) (revision 095b567e3a7a0e61dd92b0e68fc6f5db883ebcdd) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/IllustrationPointsChartControl.cs (.../IllustrationPointsChartControl.cs) (revision 3748f21da69e2c5a0f5d59168ed1d00807bedf00) @@ -25,6 +25,7 @@ using System.Windows.Forms; using Core.Components.Stack.Data; using Ringtoets.Common.Data.Hydraulics.IllustrationPoints; +using Ringtoets.Common.Forms.Factories; namespace Ringtoets.Common.Forms.Views { @@ -35,12 +36,16 @@ { private GeneralResult data; + private StackChartData chartData; + /// /// Creates a new instance of . /// public IllustrationPointsChartControl() { InitializeComponent(); + + chartData = RingtoetsStackChartDataFactory.Create(); } /// @@ -58,86 +63,17 @@ if (data != null) { - CreateColumns(); + SetChartData(); } } } - private void CreateColumns() + private void SetChartData() { - var chartData = new StackChartData(); + RingtoetsStackChartDataFactory.CreateColumns(data, chartData); + RingtoetsStackChartDataFactory.CreateRows(data, chartData); - var stochastValues = new List(); - - foreach (WindDirectionClosingSituationIllustrationPoint illustrationPoint in data.WindDirectionClosingSituationIllustrationPoints) - { - chartData.AddColumn($"{illustrationPoint.WindDirection.Name}"); - - stochastValues.AddRange(illustrationPoint.IllustrationPoint.Stochasts - .Select(illustrationPointStochast => - new TempIllustrationPoint - { - Name = illustrationPointStochast.Name, - AlphaSquared = Math.Pow(illustrationPointStochast.Alpha, 2) - })); - } - - IDictionary> lookup = new Dictionary>(); - - foreach (TempIllustrationPoint stochastValue in stochastValues) - { - if (!lookup.ContainsKey(stochastValue.Name)) - { - lookup.Add(stochastValue.Name, new List()); - } - - lookup[stochastValue.Name].Add(stochastValue.AlphaSquared); - } - - IDictionary> plotDirectly= new Dictionary>(); - - foreach (KeyValuePair> lookupValue in lookup) - { - if(!lookupValue.Value.Any(v => v < 0.01)) - { - plotDirectly.Add(lookupValue); - } - } - - foreach (KeyValuePair> pair in plotDirectly) - { - chartData.AddRow(pair.Key, pair.Value.ToArray()); - } - - Dictionary> otherLookup = lookup.Except(plotDirectly).ToDictionary(l => l.Key, l => l.Value); - - if (otherLookup.Any()) - { - var values = new double[chartData.Columns.Count()]; - int index = 0; - - foreach (KeyValuePair> keyValuePair in otherLookup) - { - foreach (double value in keyValuePair.Value) - { - values[index] += value; - index++; - } - - index = 0; - } - - chartData.AddRow("Overig", values); - } - stackChartControl.Data = chartData; } - - private class TempIllustrationPoint - { - public string Name { get; set; } - - public double AlphaSquared { get; set; } - } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Factories/RingtoetsStackChartDataFactoryTest.cs =================================================================== diff -u -r65a84aed979055e2b6930528f392b2cac5f4405b -r3748f21da69e2c5a0f5d59168ed1d00807bedf00 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Factories/RingtoetsStackChartDataFactoryTest.cs (.../RingtoetsStackChartDataFactoryTest.cs) (revision 65a84aed979055e2b6930528f392b2cac5f4405b) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Factories/RingtoetsStackChartDataFactoryTest.cs (.../RingtoetsStackChartDataFactoryTest.cs) (revision 3748f21da69e2c5a0f5d59168ed1d00807bedf00) @@ -20,7 +20,9 @@ // All rights reserved. using System; +using System.Drawing; using System.Linq; +using Core.Common.TestUtil; using Core.Components.Stack.Data; using NUnit.Framework; using Ringtoets.Common.Data.Hydraulics.IllustrationPoints; @@ -76,13 +78,13 @@ new[] { new WindDirectionClosingSituationIllustrationPoint( - new TestWindDirection(), "General", + new TestWindDirection(), "Regular", new TestIllustrationPoint()), new WindDirectionClosingSituationIllustrationPoint( - new TestWindDirection(), "General", + new TestWindDirection(), "Regular", new TestIllustrationPoint()), new WindDirectionClosingSituationIllustrationPoint( - new TestWindDirection(), "General", + new TestWindDirection(), "Regular", new TestIllustrationPoint()) }); @@ -127,5 +129,107 @@ Assert.AreEqual("SSE (Closed)", columns[1]); Assert.AreEqual("SSE (Open)", columns[2]); } + + [Test] + public void CreateRows_GeneralResultNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => RingtoetsStackChartDataFactory.CreateRows(null, new StackChartData()); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("generalResult", exception.ParamName); + } + + [Test] + public void CreateRows_StackChartDataNull_ThrowArgumentNullException() + { + // Call + TestDelegate test = () => RingtoetsStackChartDataFactory.CreateRows(new TestGeneralResult(), null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("stackChartData", exception.ParamName); + } + + [Test] + public void CreateRows_WithAllData_RowsAddedToStackChartData() + { + var stackChartData = new StackChartData(); + var generalResult = new GeneralResult( + new TestWindDirection(), + Enumerable.Empty(), + new[] + { + new WindDirectionClosingSituationIllustrationPoint( + new TestWindDirection(), "Regular", + new IllustrationPoint("Punt 1", + new[] + { + new RealizedStochast("Stochast 1", 1, -0.9, 3), + new RealizedStochast("Stochast 2", 1, -0.43589, 3), + new RealizedStochast("Stochast 3", 1, -0.01, 3), + new RealizedStochast("Stochast 4", 1, -0.01, 3) + }, + Enumerable.Empty(), 1)), + new WindDirectionClosingSituationIllustrationPoint( + new TestWindDirection(), "Regular", + new IllustrationPoint("Punt 2", + new[] + { + new RealizedStochast("Stochast 1", 1, -0.43589, 3), + new RealizedStochast("Stochast 2", 1, -0.9, 3), + new RealizedStochast("Stochast 3", 1, -0.02, 3), + new RealizedStochast("Stochast 4", 1, -0.02, 3) + }, + Enumerable.Empty(), 1)), + new WindDirectionClosingSituationIllustrationPoint( + new TestWindDirection(), "Regular", + new IllustrationPoint("Punt 3", + new[] + { + new RealizedStochast("Stochast 1", 1, -0.43589, 3), + new RealizedStochast("Stochast 2", 1, -0.9, 3), + new RealizedStochast("Stochast 3", 1, -0.03, 3), + new RealizedStochast("Stochast 4", 1, -0.03, 3) + }, + Enumerable.Empty(), 1)) + }); + + RingtoetsStackChartDataFactory.CreateColumns(generalResult, stackChartData); + + // Call + RingtoetsStackChartDataFactory.CreateRows(generalResult, stackChartData); + + // Assert + RowChartData[] rows = stackChartData.Rows.ToArray(); + + Assert.AreEqual(3, rows.Length); + + Assert.AreEqual("Stochast 1", rows[0].Name); + CollectionAssert.AreEqual(new[] + { + 0.81, + 0.19, + 0.19 + }, rows[0].Values, new DoubleWithToleranceComparer(1e-6)); + Assert.IsNull(rows[0].Color); + Assert.AreEqual("Stochast 2", rows[1].Name); + CollectionAssert.AreEqual(new[] + { + 0.19, + 0.81, + 0.81 + }, rows[1].Values, new DoubleWithToleranceComparer(1e-6)); + Assert.IsNull(rows[1].Color); + Assert.AreEqual("Overig", rows[2].Name); + CollectionAssert.AreEqual(new[] + { + 0.0002, + 0.0008, + 0.0018 + }, rows[2].Values, new DoubleWithToleranceComparer(1e-6)); + Assert.AreEqual(Color.Gray, rows[2].Color); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsChartControlTest.cs =================================================================== diff -u -r65a84aed979055e2b6930528f392b2cac5f4405b -r3748f21da69e2c5a0f5d59168ed1d00807bedf00 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsChartControlTest.cs (.../IllustrationPointsChartControlTest.cs) (revision 65a84aed979055e2b6930528f392b2cac5f4405b) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Views/IllustrationPointsChartControlTest.cs (.../IllustrationPointsChartControlTest.cs) (revision 3748f21da69e2c5a0f5d59168ed1d00807bedf00) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Drawing; using System.Linq; using System.Windows.Forms; using Core.Common.TestUtil; @@ -75,20 +76,23 @@ 0.19, 0.19 }, rows[0].Values, new DoubleWithToleranceComparer(1e-6)); + Assert.IsNull(rows[0].Color); Assert.AreEqual("Stochast 2", rows[1].Name); CollectionAssert.AreEqual(new[] { 0.19, 0.81, 0.81 }, rows[1].Values, new DoubleWithToleranceComparer(1e-6)); + Assert.IsNull(rows[1].Color); Assert.AreEqual("Overig", rows[2].Name); CollectionAssert.AreEqual(new[] { 0.0002, 0.0008, 0.0018 }, rows[2].Values, new DoubleWithToleranceComparer(1e-6)); + Assert.AreEqual(Color.Gray, rows[2].Color); } private static GeneralResult GetGerenalResult()