public void WriteSampleData(IDataStructureObject dsd, IDataflowObject dataflow, IDataWriterEngine dwe) {
			dwe.StartDataset(dataflow, dsd, null);
			
			dwe.StartSeries();
			dwe.WriteSeriesKeyValue("COUNTRY", "UK");
			dwe.WriteSeriesKeyValue("INDICATOR", "E_P");
			dwe.WriteObservation("2000", "18,22");
			dwe.WriteObservation("2000-02", "17,63");
			
			dwe.StartSeries();
			dwe.WriteSeriesKeyValue("COUNTRY", "FR");
			dwe.WriteSeriesKeyValue("INDICATOR", "E_P");
			dwe.WriteObservation("2000", "22,22");
			dwe.WriteObservation("2000-Q3", "15,63");
			
			dwe.Close();
		}
        public void writeSampleData(IDataStructureObject dsd, IDataflowObject dataflow, IDataWriterEngine dwe){
           //Step 1. Writing sample data. 
            //1)	Start the dataset
            dwe.StartDataset(dataflow, dsd, null);

            //2)	Start the dataset series
            dwe.StartSeries();

            //3)	Write dimensions
            dwe.WriteSeriesKeyValue("FREQ", "Q");
            dwe.WriteSeriesKeyValue("REF_AREA","IT");
            dwe.WriteSeriesKeyValue("ADJUSTMENT","W");
            dwe.WriteSeriesKeyValue("STS_INDICATOR","E_P");
            dwe.WriteSeriesKeyValue("STS_ACTIVITY","NS0020");
            dwe.WriteSeriesKeyValue("STS_INSTITUTION","1");
            dwe.WriteSeriesKeyValue("STS_BASE_YEAR","2000");

            //4)	Write Attribute at Series Level
            dwe.WriteAttributeValue("TIME_FORMAT", "P3M");

            //5)	Write the observations
            dwe.WriteObservation("2000-Q1", "18,22");
            dwe.WriteObservation("2000-Q2", "17,63");

            //6)	Write Attribute at Observation Level
            dwe.WriteAttributeValue("OBS_STATUS", "C");

            //7)	Repeat the steps from 2 to 6 to create another dataset series 
            dwe.StartSeries();
            dwe.WriteSeriesKeyValue("FREQ", "M");
            dwe.WriteSeriesKeyValue("REF_AREA", "SP");
            dwe.WriteSeriesKeyValue("ADJUSTMENT", "N");
            dwe.WriteSeriesKeyValue("STS_INDICATOR", "PROD");
            dwe.WriteSeriesKeyValue("STS_ACTIVITY", "NS0030");
            dwe.WriteSeriesKeyValue("STS_INSTITUTION", "1");
            dwe.WriteSeriesKeyValue("STS_BASE_YEAR", "2001");
            dwe.WriteAttributeValue("TIME_FORMAT", "P1M");
            dwe.WriteObservation("2000-01", "18,22");
            dwe.WriteObservation("2000-02", "17,63");
            dwe.WriteAttributeValue("OBS_STATUS", "S");

            //8)	Close the dataset
            dwe.Close();

        }
Example #3
0
        /// <summary>
        /// Write a TimeSeries Data in FLAT format
        /// </summary>
        /// <param name="dataWriterEngine">input structure contains data</param>
        private void WriteFlatData(IDataWriterEngine dataWriterEngine)
        {
            try
            {
                dataWriterEngine.StartSeries();
                bool AddedDatasetAttribute   = false;
                List <DataMessageObject> dmo = _tableResponse.GetNext();
                do
                {
                    if (dmo == null)
                    {
                        break;
                    }

                    //Aggiungo gli Attributi di Dataset
                    if (!AddedDatasetAttribute)
                    {
                        foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyDatasetAttribute(att)))
                        {
                            dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString());
                        }
                        AddedDatasetAttribute = true;
                    }


                    //OBSERVATION
                    DataMessageObject val  = dmo.Find(dimV => dimV.ColImpl.ConceptType == ConceptTypeEnum.Attribute && ((IAttributeConcept)dimV.ColImpl).IsValueAttribute);
                    DataMessageObject time = dmo.Find(dimT => dimT.ColImpl.ConceptType == ConceptTypeEnum.Dimension && ((IDimensionConcept)dimT.ColImpl).DimensionType == DimensionTypeEnum.Time);
                    dataWriterEngine.WriteObservation(time.Val.ToString(), val.Val.ToString());


                    foreach (DataMessageObject seriesKey in dmo.FindAll(dim => OnlySeriesKey(dim)))
                    {
                        dataWriterEngine.WriteSeriesKeyValue(seriesKey.ColImpl.ConceptObjectCode, seriesKey.Val.ToString());
                    }

                    foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlySeriesAttribute(att)))
                    {
                        dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString());
                    }
                    foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyObservationAttribute(att)))
                    {
                        dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString());
                    }

                    dmo = _tableResponse.GetNext();
                } while (dmo != null);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.ErrorWriteFlatData, ex);
            }
        }
Example #4
0
        /// <summary>
        /// Write a TimeSeries Data
        /// </summary>
        /// <param name="dataWriterEngine">input structure contains data</param>
        private void WriteTimeSeriesData(IDataWriterEngine dataWriterEngine)
        {
            //TODO: MAX - FORSE E' QUESTA LA PARTE DA MODIFICARE!!

            try
            {
                bool AddedDatasetAttribute   = false;
                List <DataMessageObject> dmo = _tableResponse.GetNext();
                do
                {
                    if (dmo == null)
                    {
                        break;
                    }

                    //Aggiungo gli Attributi di Dataset
                    if (!AddedDatasetAttribute)
                    {
                        foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyDatasetAttribute(att)))
                        {
                            dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString());
                        }
                        AddedDatasetAttribute = true;
                    }


                    //SERIE
                    if (CheckChanged(dmo))
                    {
                        dataWriterEngine.StartSeries();

                        foreach (DataMessageObject seriesKey in dmo.FindAll(dim => OnlySeriesKey(dim)))
                        {
                            dataWriterEngine.WriteSeriesKeyValue(seriesKey.ColImpl.ConceptObjectCode, seriesKey.Val.ToString());
                        }

                        foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlySeriesAttribute(att)))
                        {
                            dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString());
                        }
                    }

                    //OBSERVATION
                    DataMessageObject val = dmo.Find(dimV => dimV.ColImpl.ConceptType == ConceptTypeEnum.Attribute && ((IAttributeConcept)dimV.ColImpl).IsValueAttribute);

                    DataMessageObject ObsVal = null;
                    if (string.IsNullOrEmpty(DimensionAtObservation) || new List <string> {
                        "TIME_PERIOD", "ALLDIMENSIONS"
                    }.Contains(DimensionAtObservation.Trim().ToUpper()))
                    {
                        ObsVal = dmo.Find(dimT => dimT.ColImpl.ConceptType == ConceptTypeEnum.Dimension && ((IDimensionConcept)dimT.ColImpl).DimensionType == DimensionTypeEnum.Time);
                        dataWriterEngine.WriteObservation(ObsVal.Val.ToString(), val.Val.ToString());
                    }
                    else
                    {
                        ObsVal = dmo.Find(dimT => dimT.ColImpl.Id.Trim().ToUpper() == DimensionAtObservation.Trim().ToUpper());
                        dataWriterEngine.WriteObservation(ObsVal.ColImpl.Id, ObsVal.Val.ToString(), val.Val.ToString());
                    }

                    foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyObservationAttribute(att)))
                    {
                        if (seriesAttribute.Val.ToString() != String.Empty)
                        {
                            dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString());
                        }
                    }

                    dmo = _tableResponse.GetNext();
                } while (dmo != null);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.ErrorWriteTimeSeriesData, ex);
            }
        }
        /// <summary>
        ///     Writes the data.
        /// </summary>
        /// <param name="dataQuery">The data query.</param>
        /// <param name="dataWriter">The data writer.</param>
        private static void WriteData(IBaseDataQuery dataQuery, IDataWriterEngine dataWriter)
        {
            if (dataQuery.DataQueryDetail.EnumType == DataQueryDetailEnumType.NoData || dataQuery.DataQueryDetail.EnumType == DataQueryDetailEnumType.Full)
            {
                if (dataQuery.Dataflow.Id.Equals("TEST_GROUPS"))
                {
                    dataWriter.StartGroup("Sibling");
                    dataWriter.WriteGroupKeyValue("REF_AREA", "LU");
                    dataWriter.WriteGroupKeyValue("ADJUSTMENT", "N");
                    dataWriter.WriteGroupKeyValue("STS_INDICATOR", "PROD");
                    dataWriter.WriteGroupKeyValue("STS_ACTIVITY", "NS0030");
                    dataWriter.WriteGroupKeyValue("STS_INSTITUTION", "1");
                    dataWriter.WriteGroupKeyValue("STS_BASE_YEAR", "2000");

                    dataWriter.WriteAttributeValue("DECIMALS", "1");
                    dataWriter.WriteAttributeValue("UNIT", "UNIT");
                }
            }

            // TODO support dimension at observation != TIME_PERIOD
            dataWriter.StartSeries();
            dataWriter.WriteSeriesKeyValue("FREQ", "M");
            dataWriter.WriteSeriesKeyValue("REF_AREA", "LU");
            dataWriter.WriteSeriesKeyValue("ADJUSTMENT", "N");
            dataWriter.WriteSeriesKeyValue("STS_INDICATOR", "PROD");
            dataWriter.WriteSeriesKeyValue("STS_ACTIVITY", "NS0030");
            dataWriter.WriteSeriesKeyValue("STS_INSTITUTION", "1");
            dataWriter.WriteSeriesKeyValue("STS_BASE_YEAR", "2000");
            if (dataQuery.DataQueryDetail.EnumType == DataQueryDetailEnumType.NoData || dataQuery.DataQueryDetail.EnumType == DataQueryDetailEnumType.Full)
            {
                dataWriter.WriteAttributeValue("TIME_FORMAT", "P1M");
            }

            var startDate = new DateTime(2010, 01, 01);
            if (dataQuery.DataQueryDetail.EnumType == DataQueryDetailEnumType.Full || dataQuery.DataQueryDetail.EnumType == DataQueryDetailEnumType.DataOnly)
            {
                int firstObsCount = 5;
                if (dataQuery.FirstNObservations.HasValue)
                {
                    firstObsCount = Math.Min(firstObsCount, dataQuery.FirstNObservations.Value);
                }

                for (int i = 0; i < firstObsCount; i++)
                {
                    dataWriter.WriteObservation(startDate.AddMonths(i), "1.0", TimeFormat.GetFromEnum(TimeFormatEnumType.Month));
                    if (dataQuery.DataQueryDetail.EnumType == DataQueryDetailEnumType.Full)
                    {
                        dataWriter.WriteAttributeValue("OBS_STATUS", "A");
                    }
                }

                if (dataQuery.LastNObservations.HasValue)
                {
                    int lastObsStart = Math.Max(5 - dataQuery.LastNObservations.Value, firstObsCount);

                    for (int i = lastObsStart; i < 5; i++)
                    {
                        dataWriter.WriteObservation(startDate.AddMonths(i), "1.0", TimeFormat.GetFromEnum(TimeFormatEnumType.Month));
                        if (dataQuery.DataQueryDetail.EnumType == DataQueryDetailEnumType.Full)
                        {
                            dataWriter.WriteAttributeValue("OBS_STATUS", "A");
                        }
                    }
                }
            }
        }