示例#1
0
        /// <summary>
        /// For Add and Delete - mark items that have been amended
        /// </summary>
        /// <param name="dataItems"></param>
        /// <param name="theSpec"></param>
        /// <returns></returns>
        internal List <DataItem_DTO> GetFlaggedItemsAddDelete(List <DataItem_DTO> dataItems, Specification theSpec, Matrix theMatrixData)
        {
            int    counter      = 0;
            string confidential = Configuration_BSO.GetCustomConfig(ConfigType.server, "px.confidential-value");

            //Now mark any ADDED datapoint
            foreach (DataItem_DTO dataItem in dataItems)
            {
                dataItem.dataValue = theMatrixData.Cells.ElementAt(counter).TdtValue.Equals(DBNull.Value) ? confidential : theMatrixData.Cells.ElementAt(counter).TdtValue;


                counter++;
                //if a new classification was added then we must mark everything as amended
                if (theSpec.Classification.Count > 0)
                {
                    foreach (ClassificationRecordDTO_Create cls in dataItem.classifications)
                    {
                        //cls will have just one variable - is that a new variable? If so, then flag the data point
                        ClassificationRecordDTO_Create specCls = theSpec.Classification.Where(x => x.Code == cls.Code).FirstOrDefault();
                        if (specCls != null && specCls.Variable.Where(x => x.Code == cls.Variable.FirstOrDefault().Code).Count() > 0)
                        {
                            dataItem.wasAmendment = true;

                            //the datapoint has been marked as amended, we can now just go straight to the next data point the the foreach loop
                            continue;
                        }
                    }
                }
                //If the datapoint has a new statistic then we mark the datapoint as amended
                if (theSpec.Statistic.Count > 0)
                {
                    if (theSpec.Statistic.Where(x => x.Code == dataItem.statistic.Code).Count() > 0)
                    {
                        dataItem.wasAmendment = true;
                        //we're in a foreach loop, so there's no point in checking the period - the datapoint is already marked and we move on to the next data point

                        continue;
                    }
                }

                //If the datapoint has a new period then we mark the datapoint as amended
                if (theSpec.Frequency.Period.Count > 0)
                {
                    if (theSpec.Frequency.Period.Where(x => x.Code == dataItem.period.Code).Count() > 0)
                    {
                        dataItem.wasAmendment = true;
                    }
                }
            }

            return(dataItems);
        }
示例#2
0
 private void UpdateExistingSpec(Matrix.Specification theSpec, BuildUpdate_DTO dto)
 {
     if (dto.Map != null)
     {
         foreach (var map in dto.Map)
         {
             ClassificationRecordDTO_Create cls = theSpec.Classification.Where(x => x.Code == map.Key).FirstOrDefault();
             if (cls != null)
             {
                 cls.GeoFlag = map.Value != null;
                 cls.GeoUrl  = map.Value;
             }
         }
     }
 }
示例#3
0
        /// <summary>
        /// Creates a Classfication record in the database
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="matrixId"></param>
        /// <returns></returns>
        internal int CreateClassificationRecord(ClassificationRecordDTO_Create dto, int matrixId)
        {
            var inputParams = new List <ADO_inputParams>()
            {
                new ADO_inputParams()
                {
                    name = "@ClsMtrId", value = matrixId
                },
                new ADO_inputParams()
                {
                    name = "@ClsValue", value = dto.Value
                },
                new ADO_inputParams()
                {
                    name = "@ClsCode", value = dto.Code
                },
                new ADO_inputParams()
                {
                    name = "@ClsGeoFlag", value = dto.GeoFlag
                }
            };

            if (!string.IsNullOrEmpty(dto.GeoUrl))
            {
                inputParams.Add(new ADO_inputParams()
                {
                    name = "@ClsGeoUrl", value = dto.GeoUrl
                });
            }

            var returnParam = new ADO_returnParam()
            {
                name = "@ReturnVal", value = 0
            };

            ado.ExecuteNonQueryProcedure("Data_Classification_Create", inputParams, ref returnParam);

            return((int)returnParam.value);
        }
示例#4
0
        /// <summary>
        /// Recursive function to package the graph of dimensions into a list of DataItem_DTO
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="item"></param>
        private void populateDataItem(ref DataItem_DTO dto, object[] item)
        {
            foreach (var subItem in item)
            {
                if (subItem.GetType().IsArray)
                {
                    populateDataItem(ref dto, (object[])subItem);
                }
                else
                {
                    var v = (DimensionDetail_DTO)subItem;
                    switch (v.dimensionValue.dimType)
                    {
                    case DimensionType.STATISTIC:
                        dto.statistic.Code  = v.key;
                        dto.statistic.Value = v.value;
                        break;

                    case DimensionType.PERIOD:
                        dto.period.Code  = v.key;
                        dto.period.Value = v.value;
                        break;

                    case DimensionType.CLASSIFICATION:
                        var cls = new ClassificationRecordDTO_Create();
                        cls.Code  = v.dimensionValue.code;
                        cls.Value = v.dimensionValue.value;
                        var vrb = new VariableRecordDTO_Create();
                        vrb.Code     = v.key;
                        vrb.Value    = v.value;
                        cls.Variable = new List <VariableRecordDTO_Create>();
                        cls.Variable.Add(vrb);
                        dto.classifications.Add(cls);
                        break;
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameters"></param>
        public BuildUpdate_DTO(dynamic parameters)
        {
            if (parameters.MtrInput != null)
            {
                this.MtrInput = Utility.DecodeBase64ToUTF8((string)parameters["MtrInput"]);
            }
            if (parameters.Data != null)
            {
                PxData = new PxData_DTO(parameters);
            }

            if (parameters.LngIsoCode != null)
            {
                LngIsoCode = parameters.LngIsoCode;
            }
            else
            {
                LngIsoCode = Configuration_BSO.GetCustomConfig(ConfigType.global, "language.iso.code");
            }
            Periods = new List <PeriodRecordDTO_Create>();

            if (parameters.MtrCode != null)
            {
                MtrCode = parameters.MtrCode;
            }
            if (parameters.CprCode != null)
            {
                CprCode = parameters.CprCode;
            }
            if (parameters.FrqCodeTimeval != null)
            {
                FrqCodeTimeval = parameters.FrqCodeTimeval;
            }
            if (parameters.FrqValueTimeval != null)
            {
                FrqValueTimeval = parameters.FrqValueTimeval;
            }
            if (parameters.MtrOfficialFlag != null)
            {
                MtrOfficialFlag = parameters.MtrOfficialFlag;
            }

            Format = new Format_DTO_Read();
            if (parameters.FrmType != null && parameters.FrmVersion != null)
            {
                Format.FrmType      = parameters.FrmType;
                Format.FrmVersion   = parameters.FrmVersion;
                Format.FrmDirection = Format_DTO_Read.FormatDirection.UPLOAD.ToString();
            }


            if (parameters.Signature != null)
            {
                this.Signature = parameters.Signature;
            }

            if (parameters.Labels != null)
            {
                this.Labels = parameters.Labels;
            }
            else
            {
                this.Labels = true;
            }


            if (parameters.Elimination != null)
            {
                Elimination = JsonConvert.DeserializeObject <Dictionary <string, string> >(parameters.Elimination.ToString());
            }

            if (parameters.Dimension != null)
            {
                Dimension = new List <Dimension_DTO>();
                foreach (var dim in parameters.Dimension)
                {
                    Dimension_DTO dimension = new Dimension_DTO();
                    if (dim.Frequency != null)
                    {
                        dimension.Frequency = new FrequencyRecordDTO_Create();
                        if (dim.Frequency.Period != null)
                        {
                            dimension.Frequency.Period = new List <Data.PeriodRecordDTO_Create>();
                            foreach (var per in dim.Frequency.Period)
                            {
                                PeriodRecordDTO_Create period = new PeriodRecordDTO_Create();
                                if (per.PrdCode != null)
                                {
                                    period.Code = per.PrdCode;
                                }
                                if (per.PrdValue != null)
                                {
                                    period.Value = per.PrdValue;
                                }
                                if (Periods.Where(x => x.Code.Equals(period.Code)).FirstOrDefault() == null)
                                {
                                    Periods.Add(period);
                                }
                                dimension.Frequency.Period.Add(period);
                            }
                        }
                        if (dim.Frequency.FrqValue != null)
                        {
                            dimension.Frequency.Value = dim.Frequency.FrqValue;
                        }
                    }
                    if (dim.Classification != null)
                    {
                        dimension.Classifications = new List <ClassificationRecordDTO_Create>();
                        foreach (var cls in dim.Classification)
                        {
                            ClassificationRecordDTO_Create classification = new ClassificationRecordDTO_Create();
                            if (cls.ClsCode != null)
                            {
                                classification.Code = cls.ClsCode;
                            }

                            dimension.Classifications.Add(classification);
                        }
                    }
                    if (dim.LngIsoCode != null)
                    {
                        dimension.LngIsoCode = dim.LngIsoCode;
                    }
                    if (dim.MtrTitle != null)
                    {
                        dimension.MtrTitle = dim.Dimension;
                    }
                    if (dim.FrqValue != null)
                    {
                        dimension.FrqValue = dim.FrqValue;
                    }
                    if (dim.MtrNote != null)
                    {
                        dimension.MtrNote = dim.MtrNote;
                    }
                    if (dim.StatisticLabel != null)
                    {
                        dimension.StatisticLabel = dim.StatisticLabel;
                    }
                    if (dim.MtrTitle != null)
                    {
                        dimension.MtrTitle = dim.MtrTitle;
                    }

                    Dimension.Add(dimension);
                }
            }

            if (parameters.Map != null)
            {
                Map = JsonConvert.DeserializeObject <Dictionary <string, string> >(parameters.Map.ToString());
            }
        }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dim"></param>
        public Dimension_DTO(dynamic dim)
        {
            if (dim.FrqCode != null)
            {
                this.FrqCode = dim.FrqCode;
            }
            if (dim.FrqValue != null)
            {
                this.FrqValue = dim.FrqValue;
            }

            if (dim.Frequency != null)
            {
                Frequency = new FrequencyRecordDTO_Create();
                if (dim.Frequency.FrqCode != null)
                {
                    this.FrqCode   = dim.Frequency.FrqCode;
                    Frequency.Code = dim.Frequency.FrqCode;
                }
                if (dim.Frequency.FrqValue != null)
                {
                    this.FrqValue   = dim.Frequency.FrqValue;
                    Frequency.Value = dim.Frequency.FrqValue;
                }
                if (dim.Frequency.Period != null)
                {
                    Frequency.Period = new List <PeriodRecordDTO_Create>();
                    foreach (dynamic per in dim.Frequency.Period)
                    {
                        PeriodRecordDTO_Create prd = new PeriodRecordDTO_Create();
                        if (per.PrdCode != null)
                        {
                            prd.Code = per.PrdCode;
                        }
                        if (per.PrdValue != null)
                        {
                            prd.Value = prd.Code;
                        }
                        Frequency.Period.Add(prd);
                    }
                }
            }

            //Sometimes Period as a collection of periods may exist at the top level - e.g. PxFileBuild_API.Update
            if (dim.Period != null)
            {
                Periods = new List <PeriodRecordDTO_Create>();
                foreach (dynamic per in dim.Period)
                {
                    PeriodRecordDTO_Create prd = new PeriodRecordDTO_Create();
                    if (per.PrdCode != null)
                    {
                        prd.Code = per.PrdCode;
                    }
                    if (per.PrdValue != null)
                    {
                        prd.Value = prd.Code;
                    }
                    Periods.Add(prd);
                }
            }

            if (dim.StatisticLabel != null)
            {
                this.StatisticLabel = dim.StatisticLabel;
            }

            if (dim.CprValue != null)
            {
                this.CprValue = dim.CprValue;
            }

            if (dim.LngIsoCode != null)
            {
                this.LngIsoCode = dim.LngIsoCode;
            }

            if (dim.MtrNote != null)
            {
                this.MtrNote = dim.MtrNote;
            }

            if (dim.MtrTitle != null)
            {
                this.MtrTitle = dim.MtrTitle;
            }


            if (dim.Classification != null)
            {
                this.Classifications = new List <ClassificationRecordDTO_Create>();
                foreach (var pCls in dim.Classification)
                {
                    ClassificationRecordDTO_Create cls = new ClassificationRecordDTO_Create(pCls);


                    this.Classifications.Add(cls);
                }
            }
        }
示例#7
0
        /// <summary>
        /// Compare Releases and find data points that have changed
        /// </summary>
        /// <param name="Ado"></param>
        /// <param name="dtoRight"></param>
        /// <param name="dtoLeft"></param>
        /// <returns></returns>
        internal Matrix CompareAmendment(ADO Ado, Compare_DTO_Read dtoRight, Compare_DTO_Read dtoLeft)
        {
            bool totalChange = false;


            Release_DTO lDto = new Release_DTO();
            Release_DTO rDto = new Release_DTO();

            lDto.RlsCode = dtoLeft.RlsCode;
            rDto.RlsCode = dtoRight.RlsCode;

            Matrix leftMatrix  = new Matrix(Ado, lDto, dtoLeft.LngIsoCode);
            Matrix rightMatrix = new Matrix(Ado, rDto, dtoRight.LngIsoCode);


            Specification spec = new Data.Matrix.Specification();

            spec.Statistic        = leftMatrix.MainSpec.Statistic.Intersect(rightMatrix.MainSpec.Statistic).ToList <StatisticalRecordDTO_Create>();
            spec.Frequency        = new FrequencyRecordDTO_Create();
            spec.Frequency.Code   = rightMatrix.MainSpec.Frequency.Code;
            spec.Frequency.Value  = rightMatrix.MainSpec.Frequency.Value;
            spec.Frequency.Period = new List <PeriodRecordDTO_Create>();
            spec.Frequency.Period = leftMatrix.MainSpec.Frequency.Period.Intersect(rightMatrix.MainSpec.Frequency.Period).ToList <PeriodRecordDTO_Create>();



            //We now get the added variables. Note that this only applies where the classifications themselves have not been added
            //Classifications will contain (1) Brand new classifications, (2) classifications that have had variables added to them
            List <ClassificationRecordDTO_Create> intersectCls = leftMatrix.MainSpec.Classification.Intersect(rightMatrix.MainSpec.Classification).ToList <ClassificationRecordDTO_Create>();

            //if there are different classifications in each matrix (something added or deleted) then return all false for amendments
            if (intersectCls != null)
            {
                if (intersectCls.Count != leftMatrix.MainSpec.Classification.Count || intersectCls.Count != rightMatrix.MainSpec.Classification.Count)
                {
                    totalChange = true;
                }
            }
            else
            {
                totalChange = true;
            }

            spec.Classification = new List <ClassificationRecordDTO_Create>();

            foreach (ClassificationRecordDTO_Create cls in intersectCls)
            {
                ClassificationRecordDTO_Create  otherCls = rightMatrix.MainSpec.Classification.Where(x => x.Equals(cls)).FirstOrDefault();//lefttoright
                List <VariableRecordDTO_Create> newVars  = cls.Variable.Intersect(otherCls.Variable).ToList <VariableRecordDTO_Create>();

                if (newVars.Count > 0)
                {
                    cls.Variable = newVars;
                    spec.Classification.Add(cls);
                }
                if (newVars.Count == 0)
                {
                    totalChange = true;
                }
            }

            //If there are no periods or statistics in common then everything has changed and this is flagged
            if (spec.Frequency.Period.Count == 0 || spec.Statistic.Count == 0)
            {
                totalChange = true;
            }

            leftMatrix.MainSpec = spec;

            //If there are no periods in common then nothing could have been amended - prepare for a graceful exit
            if (spec.Frequency.Period.Count > 0)
            {
                rightMatrix.MainSpec = spec;
            }

            //Get the matrix based on a database read of the DTO RlsCode
            Matrix_ADO mAdo = new Matrix_ADO(Ado);


            //Get the data for leftMatrix
            //Get the data for rightMatrix
            //Compare and flag where they're not equal
            //return the matrix

            leftMatrix.TimeFilterWasApplied  = true;
            rightMatrix.TimeFilterWasApplied = true;
            leftMatrix.StatFilterWasApplied  = true;
            rightMatrix.StatFilterWasApplied = true;
            foreach (var cls in leftMatrix.MainSpec.Classification)
            {
                cls.ClassificationFilterWasApplied = true;
            }

            if (!totalChange)
            {
                leftMatrix = new Cube_ADO(Ado).ReadCubeData(leftMatrix);
            }

            rightMatrix = new Cube_ADO(Ado).ReadCubeData(rightMatrix);



            int counter = 0;

            foreach (var cell in rightMatrix.Cells)
            {
                //If there are no periods in common then nothing could have been amended.
                //Similarly, if there was a difference in the number of classifications
                if (totalChange)
                {
                    cell.WasAmendment = false;
                }
                else
                {
                    if (cell.TdtValue.Equals(DBNull.Value))
                    {
                        cell.TdtValue = Configuration_BSO.GetCustomConfig("px.confidential-value");
                    }
                    if (leftMatrix.Cells.ElementAt(counter).TdtValue.Equals(DBNull.Value))
                    {
                        leftMatrix.Cells.ElementAt(counter).TdtValue = Configuration_BSO.GetCustomConfig("px.confidential-value");
                    }

                    if (cell.TdtValue != leftMatrix.Cells.ElementAt(counter).TdtValue)
                    {
                        cell.WasAmendment = true;
                    }
                    else
                    {
                        cell.WasAmendment = false;
                    }
                }

                counter++;
            }



            return(rightMatrix);
        }
示例#8
0
        /// <summary>
        /// Compare Releases and find data points that have either been added or deleted
        /// </summary>
        /// <param name="Ado"></param>
        /// <param name="dtoRight"></param>
        /// <param name="dtoLeft"></param>
        /// <returns></returns>
        internal Matrix CompareAddDelete(ADO Ado, Compare_DTO_Read dtoRight, Compare_DTO_Read dtoLeft)
        {
            Release_DTO lDto = new Release_DTO();
            Release_DTO rDto = new Release_DTO();

            lDto.RlsCode = dtoLeft.RlsCode;
            rDto.RlsCode = dtoRight.RlsCode;


            Matrix leftMatrix  = new Matrix(Ado, lDto, dtoLeft.LngIsoCode);
            Matrix rightMatrix = new Matrix(Ado, rDto, dtoRight.LngIsoCode);


            Specification spec = new Specification();


            spec.Classification = leftMatrix.MainSpec.Classification.Except(rightMatrix.MainSpec.Classification).ToList <ClassificationRecordDTO_Create>();

            bool test = leftMatrix.MainSpec.Statistic.Equals(rightMatrix.MainSpec.Statistic);

            spec.Statistic = leftMatrix.MainSpec.Statistic.Except(rightMatrix.MainSpec.Statistic).ToList <StatisticalRecordDTO_Create>();


            spec.Frequency        = new FrequencyRecordDTO_Create();
            spec.Frequency.Period = new List <PeriodRecordDTO_Create>();
            spec.Frequency.Period = leftMatrix.MainSpec.Frequency.Period.Except(rightMatrix.MainSpec.Frequency.Period).ToList <PeriodRecordDTO_Create>();



            //Classifications will contain (1) Brand new classifications, (2) classifications that have had variables added to them
            List <ClassificationRecordDTO_Create> intersectCls = leftMatrix.MainSpec.Classification.Intersect(rightMatrix.MainSpec.Classification).ToList <ClassificationRecordDTO_Create>();

            foreach (ClassificationRecordDTO_Create cls in intersectCls)
            {
                ClassificationRecordDTO_Create  otherCls = rightMatrix.MainSpec.Classification.Where(x => x.Equals(cls)).FirstOrDefault();
                List <VariableRecordDTO_Create> newVars  = cls.Variable.Except(otherCls.Variable).ToList <VariableRecordDTO_Create>();

                ClassificationRecordDTO_Create newCls = new ClassificationRecordDTO_Create();
                newCls.Code     = cls.Code;
                newCls.Value    = cls.Value;
                newCls.Variable = new List <VariableRecordDTO_Create>();

                if (newVars.Count > 0)
                {
                    newCls.Variable = newVars;
                    spec.Classification.Add(newCls);
                }
            }
            leftMatrix.TimeFilterWasApplied = true;

            leftMatrix.StatFilterWasApplied = true;
            foreach (var cls in leftMatrix.MainSpec.Classification)
            {
                cls.ClassificationFilterWasApplied = true;
            }


            //Get the matrix based on a database read of the DTO RlsCode
            Matrix_ADO mAdo = new Matrix_ADO(Ado);


            //Get the metadata for the left matrix as a list of DataItem_DTO
            List <DataItem_DTO> resDataLeft = GetCellMetadata(Ado, dtoLeft.LngIsoCode, dtoLeft.RlsCode, dtoRight.RlsCode, leftMatrix.MainSpec);

            //Get the data for the added-to or deleted-from matrix
            leftMatrix = new Cube_ADO(Ado).ReadCubeData(leftMatrix);

            //Get the WasAmendment flag set on the list of items. This is calculated by referring to the extra dimensions in spec
            resDataLeft = GetFlaggedItemsAddDelete(resDataLeft, spec, leftMatrix);


            //This is the final result of Add/Delete
            leftMatrix = GetFlaggedMatrix(leftMatrix, resDataLeft);

            return(leftMatrix);
        }