Esempio n. 1
0
        public override Task <ModelTableFormula> MapToModel(SnapshotTableFormula snapshot, SnapshotContext snapshotContext)
        {
            var tableFormula = _formulaFactory.CreateDistributedTableFormula();

            _tableFormulaMapper.UpdateModelProperties(tableFormula, snapshot);
            tableFormula.Percentile = snapshot.Percentile;
            snapshot.DistributionMetaData.Select(modelDistributionDataFrom).Each(tableFormula.AddDistributionMetaData);
            return(Task.FromResult(tableFormula));
        }
        private DistributedTableFormula formulaFrom(DataRepository dataRepository)
        {
            var        baseGrid = dataRepository.BaseGrid;
            var        valueColumns = dataRepository.AllButBaseGrid().ToList();
            DataColumn meanColumn, deviationColumn;

            if (valueColumns.Count == 1)
            {
                meanColumn = valueColumns[0];
                //dummy deviation filled with 1 since this was not defined in the import action
                deviationColumn = new DataColumn(Constants.Distribution.DEVIATION, _dimensionRepository.NoDimension, baseGrid)
                {
                    Values = new float[baseGrid.Count].InitializeWith(1f)
                };
            }
            else
            {
                meanColumn      = valueColumns.Single(x => x.RelatedColumns.Any());
                deviationColumn = valueColumns.Single(x => !x.RelatedColumns.Any());
            }

            var formula = _formulaFactory.CreateDistributedTableFormula().WithName(dataRepository.Name);

            formula.InitializedWith(CoreConstants.Parameters.PMA, dataRepository.Name, baseGrid.Dimension, meanColumn.Dimension);
            formula.XDisplayUnit = baseGrid.Dimension.Unit(baseGrid.DataInfo.DisplayUnitName);
            formula.YDisplayUnit = meanColumn.Dimension.Unit(meanColumn.DataInfo.DisplayUnitName);

            foreach (var ageValue in baseGrid.Values)
            {
                var mean         = meanColumn.GetValue(ageValue).ToDouble();
                var pma          = ageValue.ToDouble();
                var deviation    = deviationColumn.GetValue(ageValue).ToDouble();
                var distribution = new DistributionMetaData {
                    Mean = mean, Deviation = deviation, Distribution = DistributionTypes.LogNormal
                };
                formula.AddPoint(pma, mean, distribution);
            }
            return(formula);
        }