예제 #1
0
        internal Role UpdateRoleFromMetadata(ADO theAdo, CubeQuery_DTO dto)
        {
            Cube_ADO cAdo = new Cube_ADO(theAdo);

            dto.Role = new Role();
            Dictionary <string, string> roleDictionary;

            if (dto.jStatQueryExtension.extension.RlsCode == 0)
            {
                roleDictionary = cAdo.ReadDimensionRoles(Utility.GetCustomConfig("APP_CSV_STATISTIC"), dto.jStatQueryExtension.extension.Matrix);
            }
            else
            {
                roleDictionary = cAdo.ReadDimensionRoles(Utility.GetCustomConfig("APP_CSV_STATISTIC"), null, dto.jStatQueryExtension.extension.RlsCode);
            }

            if (roleDictionary.ContainsKey("time"))
            {
                dto.Role.Time = new List <string>();
                dto.Role.Time.Add(roleDictionary["time"]);
            }
            if (roleDictionary.ContainsKey("metric"))
            {
                dto.Role.Metric = new List <string>();
                dto.Role.Metric.Add(roleDictionary["metric"]);
            }

            return(dto.Role);
        }
예제 #2
0
        internal List <dynamic> ReadCollection(string LngIsoCode, string SbjCode, string PrcCode)
        {
            Cube_ADO cAdo = new Cube_ADO(ado);

            if (Int32.TryParse(SbjCode, out int sbjInt))
            {
                return(cAdo.ReadCollection(LngIsoCode, default, sbjInt, PrcCode));
예제 #3
0
        /// <summary>
        /// Execute
        /// </summary>
        /// <param name="theAdo"></param>
        /// <param name="theCubeDTO"></param>
        /// <param name="theReleaseDto"></param>
        /// <param name="theResponse"></param>
        /// <returns></returns>
        static internal bool ExecuteReadMetadata(ADO theAdo, Cube_DTO_Read theCubeDTO, Release_DTO theReleaseDto, JSONRPC_Output theResponse)
        {
            var ado = new Cube_ADO(theAdo);

            // The matrix constructor will load all the metadata from the db when instances specification
            var theMatrix = new Matrix(theAdo, theReleaseDto, theCubeDTO.language).ApplySearchCriteria(theCubeDTO);

            theMatrix.FormatType    = theCubeDTO.Format.FrmType;
            theMatrix.FormatVersion = theCubeDTO.Format.FrmVersion;
            if (theMatrix == null)
            {
                theResponse.data = null;
                return(true);
            }

            var jsonStat = theMatrix.GetJsonStatObject();

            theResponse.data = new JRaw(Serialize.ToJson(jsonStat));

            if (theReleaseDto.RlsLiveDatetimeTo != null)
            {
                MemCacheD.Store_BSO <dynamic>("PxStat.Data", "Cube_API", "ReadMetadata", theCubeDTO, theResponse.data, theReleaseDto.RlsLiveDatetimeTo, Resources.Constants.C_CAS_DATA_CUBE_READ_METADATA + theMatrix.Code);
            }
            else
            {
                MemCacheD.Store_BSO <dynamic>("PxStat.Data", "Cube_API", "ReadMetadata", theCubeDTO, theResponse.data, new DateTime(), Resources.Constants.C_CAS_DATA_CUBE_READ_METADATA + theMatrix.Code);
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// Get the collection with metadata
        /// </summary>
        /// <param name="theAdo"></param>
        /// <param name="theCubeDTO"></param>
        /// <param name="theResponse"></param>
        /// <returns></returns>
        internal dynamic ExecuteReadCollection(ADO theAdo, Cube_DTO_ReadCollection DTO)
        {
            var ado = new Cube_ADO(theAdo);

            var dbData = ado.ReadCollectionMetadata(DTO.language, DTO.datefrom, DTO.product);


            List <dynamic> jsonStatCollection = new List <dynamic>();

            //Get a list of individual matrix data entities
            List <dynamic> releases = getReleases(dbData);


            var theJsonStatCollection = new JsonStatCollection();

            theJsonStatCollection.Link      = new JsonStatCollectionLink();
            theJsonStatCollection.Link.Item = new List <Item>();

            List <Format_DTO_Read> formats = new List <Format_DTO_Read>();

            using (Format_BSO format = new Format_BSO(new ADO("defaultConnection")))
            {
                formats = format.Read(new Format_DTO_Read()
                {
                    FrmDirection = Utility.GetCustomConfig("APP_FORMAT_DOWNLOAD_NAME")
                });
            };

            //For each of these, get a list of statistics and a list of classifications
            //Then get the JSON-stat for that metadata and add to jsonStatCollection
            foreach (var rls in releases)
            {
                List <dynamic> thisReleaseMetadata = dbData.Where(x => x.RlsCode == rls.RlsCode).Where(x => x.LngIsoCode == rls.LngIsoCode).ToList <dynamic>();

                List <dynamic> stats           = getStatistics(thisReleaseMetadata);
                List <dynamic> classifications = getClassifications(thisReleaseMetadata);
                List <dynamic> periods         = getPeriods(thisReleaseMetadata);
                theJsonStatCollection.Link.Item.Add(GetJsonStatRelease(thisReleaseMetadata, stats, classifications, periods, formats));
            }

            //Get the minimum next release date. The cache can only live until then.
            //If there's no next release date then the cache will live for the maximum configured amount.

            DateTime minDateItem = default;


            dynamic minimum = null;

            if (dbData != null)
            {
                minimum     = dbData.Where(x => x.RlsLiveDatetimeFrom > DateTime.Now).Min(x => x.RlsLiveDatetimeFrom);
                minDateItem = minimum ?? default(DateTime);
            }

            if (minDateItem < DateTime.Now)
            {
                minDateItem = default(DateTime);
            }

            var result = new JRaw(Serialize.ToJson(theJsonStatCollection));

            MemCacheD.Store_BSO <dynamic>("PxStat.Data", "Cube_API", "ReadCollection", DTO, result, minDateItem, Constants.C_CAS_DATA_CUBE_READ_COLLECTION);


            // return the formatted data. This is an array of JSON-stat objects.
            return(result);
        }
예제 #5
0
        internal List <dynamic> ReadCollection(string LngIsoCode, string PrcCode)
        {
            Cube_ADO cAdo = new Cube_ADO(ado);

            return(cAdo.ReadCollection(LngIsoCode, default(DateTime), PrcCode));
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
0
        internal static bool ExecuteReadDataset(ADO theAdo, CubeQuery_DTO theDto, Release_DTO releaseDto, JSONRPC_Output theResponse, string requestLanguage, string culture = null)
        {
            var theMatrix = new Matrix(theAdo, releaseDto, theDto.jStatQueryExtension.extension.Language.Code).ApplySearchCriteria(theDto);

            if (theMatrix == null)
            {
                theResponse.data = null;
                return(true);
            }

            var matrix = new Cube_ADO(theAdo).ReadCubeData(theMatrix);

            if (matrix == null)
            {
                theResponse.data = null;
                return(true);
            }

            CultureInfo readCulture;

            if (culture == null)
            {
                readCulture = CultureInfo.CurrentCulture;
            }
            else
            {
                readCulture = CultureInfo.CreateSpecificCulture(culture);
            };


            switch (theDto.jStatQueryExtension.extension.Format.Type)
            {
            case DatasetFormat.JsonStat:
                matrix.FormatType    = theDto.jStatQueryExtension.extension.Format.Type;
                matrix.FormatVersion = theDto.jStatQueryExtension.extension.Format.Version;

                if (theDto.jStatQueryExtension.extension.Format.Version == "1.0")
                {
                    var jsonStat = matrix.GetJsonStatV1Object(true, null);
                    theResponse.data = new JRaw(SerializeJsonStatV1.ToJson(jsonStat));
                }
                else
                {
                    var jsonStat = matrix.GetJsonStatObject(false, true, null, readCulture);
                    theResponse.data = new JRaw(Serialize.ToJson(jsonStat));
                }
                break;

            case DatasetFormat.Csv:
                theResponse.data = matrix.GetCsvObject(requestLanguage, false, readCulture);
                break;

            case DatasetFormat.Px:
                theResponse.data = matrix.GetPxObject().ToString();
                break;

            case DatasetFormat.Xlsx:
                theResponse.data = matrix.GetXlsxObject(requestLanguage, CultureInfo.CurrentCulture);
                break;

            case DatasetFormat.Sdmx:
                theResponse.data = matrix.GetSdmx(theDto.jStatQueryExtension.extension.Language.Code);
                break;
            }

            if (releaseDto.RlsLiveDatetimeTo != default(DateTime))
            {
                MemCacheD.Store_BSO <dynamic>("PxStat.Data", "Cube_API", "ReadDataset", theDto, theResponse.data, releaseDto.RlsLiveDatetimeTo, Resources.Constants.C_CAS_DATA_CUBE_READ_DATASET + matrix.Code);
            }
            else
            {
                MemCacheD.Store_BSO <dynamic>("PxStat.Data", "Cube_API", "ReadDataset", theDto, theResponse.data, new DateTime(), Resources.Constants.C_CAS_DATA_CUBE_READ_DATASET + matrix.Code);
            }
            return(true);
        }
예제 #9
0
        internal static bool ExecuteReadDataset(ADO theAdo, CubeQuery_DTO theDto, Release_DTO releaseDto, JSONRPC_Output theResponse, string requestLanguage, string culture = null, bool defaultPivot = false)
        {
            var theMatrix = new Matrix(theAdo, releaseDto, theDto.jStatQueryExtension.extension.Language.Code).ApplySearchCriteria(theDto);

            if (theMatrix == null)
            {
                theResponse.data = null;
                return(true);
            }

            if (theDto.jStatQueryExtension.extension.Format.Type.Equals(Resources.Constants.C_SYSTEM_XLSX_NAME))
            {
                int dataSize = theMatrix.MainSpec.GetDataSize();
                int maxSize  = Configuration_BSO.GetCustomConfig(ConfigType.global, "dataset.download.threshold.xlsx");
                if (dataSize > maxSize)
                {
                    theResponse.error = String.Format(Label.Get("error.dataset.limit", requestLanguage), dataSize, Resources.Constants.C_SYSTEM_XLSX_NAME, maxSize);
                    return(false);
                }
            }
            else if (theDto.jStatQueryExtension.extension.Format.Type.Equals(Resources.Constants.C_SYSTEM_CSV_NAME))
            {
                int dataSize = theMatrix.MainSpec.GetDataSize();
                int maxSize  = Configuration_BSO.GetCustomConfig(ConfigType.global, "dataset.download.threshold.csv");
                if (dataSize > maxSize)
                {
                    theResponse.error = String.Format(Label.Get("error.dataset.limit", requestLanguage), dataSize, Resources.Constants.C_SYSTEM_CSV_NAME, maxSize);
                    return(false);
                }
            }


            var matrix = new Cube_ADO(theAdo).ReadCubeData(theMatrix);

            if (matrix == null)
            {
                theResponse.data = null;
                return(true);
            }


            if (!string.IsNullOrEmpty(theDto.jStatQueryExtension.extension.Pivot))
            {
                if (theMatrix.MainSpec.Classification.Where(x => x.Code == theDto.jStatQueryExtension.extension.Pivot).Count() == 0 &&
                    Utility.GetCustomConfig("APP_CSV_STATISTIC") != theDto.jStatQueryExtension.extension.Pivot &&
                    theMatrix.MainSpec.Frequency.Code != theDto.jStatQueryExtension.extension.Pivot)
                {
                    theResponse.error = Label.Get("error.validation", theDto.jStatQueryExtension.extension.Language.Code);
                    return(false);
                }
            }
            else
            {
                theDto.jStatQueryExtension.extension.Pivot = null;
            }

            CultureInfo readCulture;

            if (culture == null)
            {
                readCulture = CultureInfo.CurrentCulture;
            }
            else
            {
                readCulture = CultureInfo.CreateSpecificCulture(culture);
            };

            if (theDto.jStatQueryExtension.extension.Pivot == null && defaultPivot && theDto.jStatQueryExtension.extension.Format.Type == DatasetFormat.Csv)
            {
                theDto.jStatQueryExtension.extension.Pivot = matrix.MainSpec.Frequency.Code;
            }


            switch (theDto.jStatQueryExtension.extension.Format.Type)
            {
            case DatasetFormat.JsonStat:
                matrix.FormatType    = theDto.jStatQueryExtension.extension.Format.Type;
                matrix.FormatVersion = theDto.jStatQueryExtension.extension.Format.Version;

                if (theDto.jStatQueryExtension.extension.Format.Version == "1.0")
                {
                    var jsonStat = matrix.GetJsonStatV1Object(true, null);
                    theResponse.data = new JRaw(SerializeJsonStatV1.ToJson(jsonStat));
                }
                else if (theDto.jStatQueryExtension.extension.Format.Version == "1.1")
                {
                    var jsonStat = matrix.GetJsonStatV1_1Object(false, true, null, readCulture);
                    theResponse.data = new JRaw(SerializeJsonStatV1_1.ToJson(jsonStat));
                }
                else
                {
                    var jsonStat = matrix.GetJsonStatObject(false, true, null, readCulture);
                    theResponse.data = new JRaw(Serialize.ToJson(jsonStat));
                }
                break;

            case DatasetFormat.Csv:
                theResponse.data = matrix.GetCsvObject(requestLanguage, false, readCulture, theDto.jStatQueryExtension.extension.Pivot, theDto.jStatQueryExtension.extension.Codes == null ? true : (bool)theDto.jStatQueryExtension.extension.Codes);
                break;

            case DatasetFormat.Px:
                theResponse.data = matrix.GetPxObject();
                break;

            case DatasetFormat.Xlsx:
                theResponse.data = matrix.GetXlsxObject(requestLanguage, CultureInfo.CurrentCulture, theDto.jStatQueryExtension.extension.Pivot, theDto.jStatQueryExtension.extension.Codes == null ? true : (bool)theDto.jStatQueryExtension.extension.Codes);
                break;

            case DatasetFormat.Sdmx:
                theResponse.data = matrix.GetSdmx(theDto.jStatQueryExtension.extension.Language.Code);
                break;
            }

            if (releaseDto.RlsLiveDatetimeTo != default(DateTime))
            {
                MemCacheD.Store_BSO <dynamic>("PxStat.Data", "Cube_API", "ReadDataset", theDto, theResponse.data, releaseDto.RlsLiveDatetimeTo, Resources.Constants.C_CAS_DATA_CUBE_READ_DATASET + matrix.Code);
            }
            else
            {
                MemCacheD.Store_BSO <dynamic>("PxStat.Data", "Cube_API", "ReadDataset", theDto, theResponse.data, new DateTime(), Resources.Constants.C_CAS_DATA_CUBE_READ_DATASET + matrix.Code);
            }
            return(true);
        }