コード例 #1
0
        public void TestWithGroupsCase()
        {
            var percentList = new List <IPercentHolder>
            {
                new Percent(decimal.Divide(100, 3), 1, "group1"),
                new Percent(decimal.Divide(200, 3), 1, "group2"),
                new Percent(decimal.Divide(100, 3), 1, "group3"),
                new Percent(decimal.Divide(100, 3), 2, "group1"),
                new Percent(0, 2, "group2"),
                new Percent(decimal.Divide(100, 6), 2, "group3"),
                new Percent(decimal.Divide(100, 3), 3, "group1"),
                new Percent(decimal.Divide(100, 3), 3, "group2"),
                new Percent(decimal.Divide(100, 9), 3, "group3"),
                new Percent(decimal.Divide(150, 9), 4, "group3"),
                new Percent(decimal.Divide(200, 9), 5, "group3"),
            };

            PercentPartitioningCorrector.Corrigate(percentList);

            Assert.IsTrue(percentList.GroupBy(item => item.Group).Select(items => items.Sum(p => Math.Round(p.DecimalValue.Value))).All(val => val == (decimal)100));
            Assert.AreEqual(33, (int)percentList.Single(p => p.SortOrder == 1 && p.Group == "group1").DecimalValue.Value);
            Assert.AreEqual(34, (int)percentList.Single(p => p.SortOrder == 2 && p.Group == "group1").DecimalValue.Value);
            Assert.AreEqual(67, (int)percentList.Single(p => p.SortOrder == 1 && p.Group == "group2").DecimalValue.Value);
            Assert.AreEqual(0, (int)percentList.Single(p => p.SortOrder == 2 && p.Group == "group2").DecimalValue.Value);
            Assert.AreEqual(17, (int)percentList.Single(p => p.SortOrder == 4 && p.Group == "group3").DecimalValue.Value);
        }
        private void CalculateTablePosForZustandsindexTypen(Belastungskategorie belastungskategorie)
        {
            tablePos[belastungskategorie.Id] = new Dictionary <FlaecheTyp, Dictionary <ZustandsindexTyp, List <TablePo> > >();
            foreach (var flaecheTyp in flaecheTypList)
            {
                tablePos[belastungskategorie.Id][flaecheTyp] = new Dictionary <ZustandsindexTyp, List <TablePo> >();
                foreach (var zustandsindexTyp in zustandsindexTypList.Where(zt => zt != ZustandsindexTyp.Unbekannt))
                {
                    var diagramPo = diagramPos[belastungskategorie.Id][flaecheTyp][zustandsindexTyp];

                    var totalFlaeche = totalZustandsabschnittFlaechenDictionary[belastungskategorie.Id][flaecheTyp];
                    var percentValue = totalFlaeche > 0
                                          ? (diagramPo.Value / totalFlaeche * 100)
                                          : (decimal?)null;

                    tablePos[belastungskategorie.Id][flaecheTyp][zustandsindexTyp] =
                        new List <TablePo>
                    {
                        CreateTablePo(percentValue, FormatHelper.ToReportNoDecimalPercentString, diagramPo, LocalizationService.GetLocalizedEnum(diagramPo.ZustandsindexTyp), diagramPo.RowSortOrder)
                    };
                }
            }

            PercentPartitioningCorrector.Corrigate(tablePos.SelectMany(ddl => ddl.Value).SelectMany(dl => dl.Value).SelectMany(l => l.Value).Cast <IPercentHolder>().ToList());
        }
コード例 #3
0
        private void CalculatePosForErfassungsPeriod <TZustandsabschnittBase, TStrassenabschnittBase>(TZustandsabschnittBase[] zustandsabschnittList, JahresInterval jahresInterval, ErfassungsPeriod erfassungsPeriod)
            where TStrassenabschnittBase : StrassenabschnittBase
            where TZustandsabschnittBase : ZustandsabschnittBase
        {
            var zustandsspiegelProJahrGrafischeDiagramPos = Enum.GetValues(typeof(ZustandsindexTyp))
                                                            .OfType <ZustandsindexTyp>()
                                                            .Where(z => z != ZustandsindexTyp.Unbekannt)
                                                            .Select(z => CreateDiagramPo(z, jahresInterval))
                                                            .ToDictionary(po => po.ZustandsindexTyp, po => po);

            decimal totalUnknowZustandsindexTypFlaeche = 0;

            decimal mittlereZustandsindexWithFlaeche = 0;
            decimal mittlererAufnahmedatumTickMultipliedWithFlaeche = 0;

            foreach (var zustandsabschnitt in zustandsabschnittList)
            {
                var zustandsindexTyp = ZustandsindexCalculator.GetTyp(zustandsabschnitt.Zustandsindex);
                zustandsspiegelProJahrGrafischeDiagramPos[zustandsindexTyp].FlaecheFahrbahn += (zustandsabschnitt.FlaecheFahrbahn ?? 0);
                mittlereZustandsindexWithFlaeche += zustandsabschnitt.Zustandsindex * (zustandsabschnitt.FlaecheFahrbahn ?? 0);

                mittlererAufnahmedatumTickMultipliedWithFlaeche += zustandsabschnitt.Aufnahmedatum.Ticks * (zustandsabschnitt.FlaecheFahrbahn ?? 0);
            }

            var currentJahr = ErfassungsPeriodService.GetCurrentErfassungsPeriod().Erfassungsjahr.Year;

            diagramPos[jahresInterval.JahrBis] = zustandsspiegelProJahrGrafischeDiagramPos.Values.ToList();

            var totalKnownZustandsindexTypFlaeche = zustandsspiegelProJahrGrafischeDiagramPos.Values.Sum(po => po.FlaecheFahrbahn);
            var totalFlaeche = totalKnownZustandsindexTypFlaeche + totalUnknowZustandsindexTypFlaeche;

            var totalStrasseFlaeche = transactionScopeProvider.Queryable <TStrassenabschnittBase>()
                                      .Where(z => z.ErfassungsPeriod == erfassungsPeriod)
                                      .Sum(g => g.Laenge * g.BreiteFahrbahn);

            var zustandsspiegelProJahrGrafischeTablePos = zustandsspiegelProJahrGrafischeDiagramPos.Values
                                                          .Select(po => CreateTablePo(jahresInterval, GetPerzent(po.FlaecheFahrbahn, totalKnownZustandsindexTypFlaeche), FormatHelper.ToReportNoDecimalPercentString, LocalizationService.GetLocalizedEnum(po.ZustandsindexTyp), (int)po.ZustandsindexTyp, currentJahr, po.ZustandsindexTyp));

            tablePos[jahresInterval.JahrBis] = zustandsspiegelProJahrGrafischeTablePos.ToList();

            PercentPartitioningCorrector.Corrigate(tablePos[jahresInterval.JahrBis].Cast <IPercentHolder>().ToList());

            var mittlererAufnahmedatum = (mittlererAufnahmedatumTickMultipliedWithFlaeche == 0 || totalFlaeche == 0) ? (decimal?)null : (decimal.Divide(mittlererAufnahmedatumTickMultipliedWithFlaeche, totalFlaeche));

            tablePos[jahresInterval.JahrBis].Add(CreateTablePo(jahresInterval, mittlererAufnahmedatum, d => FormatHelper.ToReportDateTimeString(d, "-"), reportLocalizationService.MittleresAlterDerZustandsaufnahmen, -10, currentJahr));

            var netzAnteil = GetPerzent(totalKnownZustandsindexTypFlaeche, totalStrasseFlaeche);

            tablePos[jahresInterval.JahrBis].Add(CreateTablePo(jahresInterval, netzAnteil, FormatHelper.ToReportNoDecimalPercentString, reportLocalizationService.NetzAnteil, -20, currentJahr));

            var mittlererZustandsindex = (mittlereZustandsindexWithFlaeche == 0 || totalFlaeche == 0) ? 0 : decimal.Divide(mittlereZustandsindexWithFlaeche, totalFlaeche);

            tablePos[jahresInterval.JahrBis].Add(CreateTablePo(jahresInterval, mittlererZustandsindex, FormatHelper.ToReportDecimalString, reportLocalizationService.MittlererZustandsindex, -30, currentJahr));
        }
コード例 #4
0
        public void TestSimpleCase()
        {
            var percentList = new List <IPercentHolder>
            {
                new Percent(decimal.Divide(100, 3), 1),
                new Percent(decimal.Divide(100, 3), 2),
                new Percent(decimal.Divide(100, 3), 3),
            };

            PercentPartitioningCorrector.Corrigate(percentList);

            Assert.AreEqual(percentList.Sum(p => Math.Round(p.DecimalValue.Value)), 100);
            Assert.AreEqual(34, (int)percentList.Single(p => p.SortOrder == 2).DecimalValue.Value);
        }
コード例 #5
0
        public void TestWithUnluckyBehaviorCase()
        {
            var percentList = new List <IPercentHolder>
            {
                new Percent((decimal)0.51, 1),
                new Percent((decimal)4.99, 2),
                new Percent((decimal)94.02, 3),
                new Percent((decimal)0.48, 4),
            };

            PercentPartitioningCorrector.Corrigate(percentList);

            Assert.AreEqual(percentList.Sum(p => Math.Round(p.DecimalValue.Value)), 100);
            Assert.AreEqual(1, (int)percentList.Single(p => p.SortOrder == 1).DecimalValue.Value);
            Assert.AreEqual(4, (int)percentList.Single(p => p.SortOrder == 2).DecimalValue.Value);
            Assert.AreEqual(95, (int)percentList.Single(p => p.SortOrder == 3).DecimalValue.Value);
        }
コード例 #6
0
        public void TestWithSmallAccumulationCase()
        {
            var percentList = new List <IPercentHolder>
            {
                new Percent(decimal.Divide(100, 9), 1),
                new Percent(decimal.Divide(100, 3), 2),
                new Percent(decimal.Divide(100, 9), 3),
                new Percent(decimal.Divide(100, 3), 4),
                new Percent(decimal.Divide(100, 9), 5),
            };

            PercentPartitioningCorrector.Corrigate(percentList);

            Assert.AreEqual(percentList.Sum(p => Math.Round(p.DecimalValue.Value)), 100);
            Assert.AreEqual(11, (int)percentList.Single(p => p.SortOrder == 1).DecimalValue.Value);
            Assert.AreEqual(33, (int)percentList.Single(p => p.SortOrder == 2).DecimalValue.Value);
            Assert.AreEqual(12, (int)percentList.Single(p => p.SortOrder == 3).DecimalValue.Value);
            Assert.AreEqual(33, (int)percentList.Single(p => p.SortOrder == 4).DecimalValue.Value);
            Assert.AreEqual(11, (int)percentList.Single(p => p.SortOrder == 5).DecimalValue.Value);
        }
コード例 #7
0
        public void TestHasNullCase()
        {
            var percentList = new List <IPercentHolder>
            {
                new Percent(0, 1),
                new Percent(decimal.Divide(100, 3), 2),
                new Percent((decimal)0.2, 3),
                new Percent(decimal.Divide(100, 3), 4),
                new Percent(0, 5),
                new Percent(decimal.Divide(100, 3) - (decimal)0.2, 6),
                new Percent(0, 7)
            };

            PercentPartitioningCorrector.Corrigate(percentList);

            Assert.AreEqual(percentList.Sum(p => Math.Round(p.DecimalValue.Value)), 100);
            Assert.AreEqual(1, (int)percentList.Single(p => p.SortOrder == 3).DecimalValue.Value);
            Assert.AreEqual(0, (int)percentList.Single(p => p.SortOrder == 5).DecimalValue.Value);
            Assert.AreEqual(33, (int)percentList.Single(p => p.SortOrder == 2).DecimalValue.Value);
        }