Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }