/// <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; } } } }
/// <summary> /// Get a list of datapoints with their associated dimension metadata /// </summary> /// <param name="Ado"></param> /// <param name="lngIsoCode"></param> /// <param name="RlsCodeLeft"></param> /// <param name="RlsCodeRight"></param> /// <param name="spec"></param> /// <returns></returns> private List <DataItem_DTO> GetCellMetadata(ADO Ado, string lngIsoCode, int RlsCodeLeft, int RlsCodeRight, Specification spec) { Matrix_ADO mAdo = new Matrix_ADO(Ado); List <DimensionValue_DTO> dimensions = new List <DimensionValue_DTO>(); DimensionValue_DTO sVal = new DimensionValue_DTO(); sVal.dimType = DimensionType.STATISTIC; foreach (StatisticalRecordDTO_Create stat in spec.Statistic) { DimensionDetail_DTO detail = new DimensionDetail_DTO(); detail.key = stat.Code; detail.value = stat.Value; detail.dimensionValue = sVal; sVal.details.Add(detail); } dimensions.Add(sVal); DimensionValue_DTO pVal = new DimensionValue_DTO(); pVal.dimType = DimensionType.PERIOD; foreach (PeriodRecordDTO_Create per in spec.Frequency.Period) { DimensionDetail_DTO detail = new DimensionDetail_DTO(); detail.key = per.Code; detail.value = per.Value; detail.dimensionValue = pVal; pVal.details.Add(detail); } dimensions.Add(pVal); foreach (ClassificationRecordDTO_Create cls in spec.Classification) { DimensionValue_DTO cVal = new DimensionValue_DTO(); cVal.dimType = DimensionType.CLASSIFICATION; cVal.code = cls.Code; cVal.value = cls.Value; foreach (var vrb in cls.Variable) { DimensionDetail_DTO detail = new DimensionDetail_DTO(); detail.key = vrb.Code; detail.value = vrb.Value; detail.dimensionValue = cVal; cVal.details.Add(detail); } dimensions.Add(cVal); } var graph = CartesianProduct(dimensions[0].details.ToArray()); for (int i = 1; i < dimensions.Count; i++) { graph = CartesianProduct(graph.ToArray(), dimensions[i].details.ToArray()); } List <DataItem_DTO> itemList = new List <DataItem_DTO>(); //int counter = 0; foreach (var item in graph) { DataItem_DTO dto = new DataItem_DTO(); populateDataItem(ref dto, item); itemList.Add(dto); } return(itemList); }