Exemplo n.º 1
0
        /// <summary>
        /// calculate coefficients for a specific measureset/measure/month and change the state of the dossiers
        /// </summary>
        private void CalculateCoefficients(int fpiId)
        {
            var fpi      = Get(fpiId);
            var dossiers = dossierRepo.GetBy(fpi.MeasuresetId, fpi.MeasureId, fpi.Month, (int)DossierStates.HasIndicators).ToArray();

            if (dossiers.Count() == 0)
            {
                return;
            }
            var measure = u.Get <Measure>(fpi.MeasureId);

            using (var t = new TransactionScope())
            {
                if (!measure.NoContest)
                {
                    var indicatorValues   = ivr.GetBy(fpi.Id).ToArray();
                    var coefficients      = u.GetWhere <Coefficient>(new { dossiers.First().FieldsetId }).ToList();
                    var coefficientValues = ecoCalc.CalculateCoefficientValues(indicatorValues, dossiers, coefficients);
                    coefficientValues.All(o => u.InsertNoIdentity(o) == 1);
                }

                dossiers.All(o => dossierRepo.ChangeState(o.Id, DossierStates.HasCoefficients) == 1);
                t.Complete();
            }
        }
Exemplo n.º 2
0
        public void ShouldCalculateCoefficientsValues()
        {
            var cvs = c.CalculateCoefficientValues(
                new[] {
                new IndicatorValue {
                    DossierId = 1, IndicatorId = 11, Value = 3
                },
                new IndicatorValue {
                    DossierId = 1, IndicatorId = 12, Value = 4
                },
                new IndicatorValue {
                    DossierId = 1, IndicatorId = 13, Value = 5
                },
                new IndicatorValue {
                    DossierId = 2, IndicatorId = 11, Value = 1
                },
                new IndicatorValue {
                    DossierId = 2, IndicatorId = 12, Value = 2
                },
                new IndicatorValue {
                    DossierId = 2, IndicatorId = 13, Value = 3
                },
            },
                new[] {
                new Dossier {
                    Id = 1
                },
                new Dossier {
                    Id = 2
                },
            },
                new[] {
                new Coefficient {
                    Id = 1, Formula = "suma(i11)+i12+i13"
                },
                new Coefficient {
                    Id = 2, Formula = "suma(i13)-i13"
                },
            });

            cvs.Count().ShouldEqual(4);
            cvs.Where(o => o.CoefficientId == 1 && o.DossierId == 1).Single().Value.ShouldEqual(13);
            cvs.Where(o => o.CoefficientId == 2 && o.DossierId == 1).Single().Value.ShouldEqual(3);
            cvs.Where(o => o.CoefficientId == 1 && o.DossierId == 2).Single().Value.ShouldEqual(9);
            cvs.Where(o => o.CoefficientId == 2 && o.DossierId == 2).Single().Value.ShouldEqual(5);
        }