Exemplo n.º 1
0
        public IQueryable <ITimeseriesMetadata> GetMetadata(IEnumerable <TimeseriesKey> seriesKeys, IEnumerable <string> headerList)
        {
            var hdrs       = headerList as string[] ?? headerList.ToArray();
            var seriesList = new List <ITimeseriesMetadata>();

            var command = _connection.CreateCommand();

            command.CommandText = GetMetadataQuery.Create(seriesKeys, hdrs);
            var reader = command.ExecuteReader();

            while (reader.Read())
            {
                var metadataDictionary = new Dictionary <string, string>();
                var seriesKey          = new TimeseriesKey(reader.GetString(0));

                foreach (var i in Enumerable.Range(1, reader.FieldCount - 1))
                {
                    var columnName = reader.GetName(i);
                    metadataDictionary[columnName] = reader[i].ToString();
                }
                seriesList.Add(new DMXTimeseries(SourceKey, seriesKey, metadataDictionary));
            }
            reader.Close();
            return(seriesList.AsQueryable());
        }
Exemplo n.º 2
0
        public void CanGetNullMetadataFromNullTimeseriesSource()
        {
            const string tsSource = "null:///test";
            var          tsKey    = new TimeseriesKey("seriesKey01");

            var tss    = TimeseriesSourceFactory.Factory[tsSource];
            var tsList = tss.GetMetadata(new[] { tsKey }, new[] { "header01", "header02" }).ToList();

            Assert.AreEqual(tsList.Count(), 0);
        }
Exemplo n.º 3
0
        // TODO [jc]: Create separate initializers for metadata and observations
        public NullTimeseries(TimeseriesSourceKey sourceKey, TimeseriesKey seriesKey, IEnumerable <string> headerList)
        {
            SourceKey = sourceKey;
            SeriesKey = seriesKey;

            foreach (var header in headerList)
            {
                var observationValue = new Random().NextDouble();
                _metadata.Add(header, $"{SourceKey.Key}|{SeriesKey.Key}|{header}|{observationValue}");
            }
        }
Exemplo n.º 4
0
        public IQueryable <ITimeseriesObservations> GetObservations(IEnumerable <TimeseriesKey> seriesKeys, string frequencies)
        {
            var seriesList = new Dictionary <TimeseriesKey, DMXTimeseries>();

            var command = _connection.CreateCommand();

            command.CommandText = GetObservationsQuery.Create(seriesKeys, frequencies);
            var reader = command.ExecuteReader();

            while (reader.Read())
            {
                var           seriesKey = new TimeseriesKey(reader.GetString(0));
                DMXTimeseries series;

                if (!seriesList.ContainsKey(seriesKey))
                {
                    series = new DMXTimeseries(SourceKey, seriesKey);
                    seriesList.Add(seriesKey, series);
                }
                else
                {
                    series = seriesList[seriesKey];
                }

                try
                {
                    var orowid = reader.GetInt32(1).ToString();
                    foreach (var i in Enumerable.Range(2, reader.FieldCount - 2))
                    {
                        var columnName = reader.GetName(i);


                        // TODO [jc]: Implement nullable type (Google.WellKnownTypes.Value ?)
                        if (!reader.IsDBNull(i))
                        {
                            series.Observations[$"{orowid}:{columnName}"] = reader.GetDouble(i);
                        }
                    }
                }
                catch (Exception ex)
                {
                    series.Status = new StatusInformation()
                    {
                        Code           = ex.HResult,
                        Message        = ex.Message,
                        InnerException = ex
                    };
                }
            }
            reader.Close();
            return(seriesList.Values.AsQueryable());
        }
Exemplo n.º 5
0
        public IQueryable <ITimeseriesObservations> GetObservations(IEnumerable <TimeseriesKey> seriesKeys, string frequencies)
        {
            var seriesList = new Dictionary <TimeseriesKey, ITimeseriesObservations>();

            _client = new SDMXServiceClient();
            var genericDataSet = _client.GetGenericData(GetObservationsQuery.BuildObservationQuery(DatabaseID, seriesKeys.ToTimeseriesKeyString(QuotedSplitStringOptions.Quoted)));

            var dataSet = genericDataSet.Element(Progm + "DataSet");

            if (dataSet != null)
            {
                var seriesElements = dataSet.Elements(Progg + "Series");
                foreach (var seriesElement in seriesElements)
                {
                    // string seriesKey1 = ((TimeseriesKey[])seriesKeys)[0].Key;
                    var seriesKey         = new TimeseriesKey(((TimeseriesKey[])seriesKeys)[0].Key);
                    var seriesAttributes  = seriesElement.Element(Progg + "Attributes");
                    var seriesObservation = seriesElement.Elements(Progg + "Obs");
                    ITimeseriesObservations series;
                    if (!seriesList.ContainsKey(seriesKey))
                    {
                        series = new EcOSTimeseries(SourceKey, seriesKey);
                        seriesList.Add(seriesKey, series);
                    }
                    else
                    {
                        series = seriesList[seriesKey];
                    }

                    foreach (var observation in seriesObservation)
                    {
                        var time  = observation.Element(Progg + "Time");
                        var obsEl = observation.Element(Progg + "ObsValue");
                        if (obsEl != null && time != null)
                        {
                            var obs = obsEl.Attribute("value");
                            if (obs != null)
                            {
                                series.Observations[time.Value] = Convert.ToDouble(obs.Value);
                            }
                        }
                    }
                }
            }
            return(seriesList.Values.AsQueryable());
        }
Exemplo n.º 6
0
        public IQueryable <ITimeseriesMetadata> GetMetadata(IEnumerable <TimeseriesKey> seriesKeys, IEnumerable <string> headerList)
        {
            var seriesList = new List <ITimeseriesMetadata>();

            _client = new SDMXServiceClient();
            var genericMetadata = _client.GetTimeSeriesAttributes(GetMetadataQuery.BuildMetadataQuery(DatabaseID, seriesKeys.ToTimeseriesKeyString(QuotedSplitStringOptions.Quoted)));
            var metadataSet     = genericMetadata.Element(Progm + "DataSet");

            if (metadataSet != null)
            {
                var seriesElements = metadataSet.Elements(Progg + "Series");
                foreach (var seriesElement in seriesElements)
                {
                    var seriesAttr         = seriesElement.Element(Progg + "SeriesKey");
                    var seriesAttributes   = seriesElement.Element(Progg + "Attributes");
                    var metadataDictionary = new Dictionary <string, string>();
                    //string seriesKey = ((TimeseriesKey[])seriesKeys)[0].Key;
                    var seriesKey = new TimeseriesKey(((TimeseriesKey[])seriesKeys)[0].Key);

                    foreach (var value in seriesAttr.Elements())
                    {
                        var conceptAtt = value.Attribute("concept");
                        var valueAtt   = value.Attribute("value");
                        if (headerList.Any(str => str.Contains(conceptAtt.Value)))
                        {
                            metadataDictionary[conceptAtt.Value] = valueAtt.Value;
                        }
                    }

                    foreach (var value in seriesAttributes.Elements())
                    {
                        var conceptAtt = value.Attribute("concept");
                        var valueAtt   = value.Attribute("value");
                        if (headerList.Any(str => str.Contains(conceptAtt.Value)))
                        {
                            metadataDictionary[conceptAtt.Value] = valueAtt.Value;
                        }
                    }
                    seriesList.Add(new EcOSTimeseries(SourceKey, seriesKey, metadataDictionary));
                }
            }
            return(seriesList.AsQueryable());
        }
Exemplo n.º 7
0
 internal DMXTimeseries(TimeseriesSourceKey sourceKey, TimeseriesKey seriesKey, Dictionary <string, double> observations) : this(sourceKey, seriesKey)
 {
     _observations = observations;
 }
Exemplo n.º 8
0
 internal DMXTimeseries(TimeseriesSourceKey sourceKey, TimeseriesKey seriesKey, Dictionary <string, string> metadata) : this(sourceKey, seriesKey)
 {
     _metadata = metadata;
 }
Exemplo n.º 9
0
 internal DMXTimeseries(TimeseriesSourceKey sourceKey, TimeseriesKey seriesKey)
 {
     SourceKey = sourceKey;
     SeriesKey = seriesKey;
     Status    = new StatusInformation();
 }
Exemplo n.º 10
0
 internal EcOSTimeseries(TimeseriesSourceKey sourceKey, TimeseriesKey seriesKey)
 {
     SourceKey = sourceKey;
     SeriesKey = seriesKey;
 }