Esempio n. 1
0
        /// <summary>
        /// Gets the time series.
        /// </summary>
        /// <returns>The time series.</returns>
        ///
        public CTimeSeries GetTimeSeries(CTimeSeriesRequest Request)
        {
            var Result = QueryTimeSeries(Request.GetURL());

            var Json = Result.Result;

            //Console.WriteLine(Json);

            CTimeSeriesFromJson Deserialized = null;

            if (Json != null)
            {
                // Remove some text to make it easier for the JSON parser.

                Json = Json.Replace("{\"dataset_data\":", "");

                Json = Json.Remove(Json.Length - 1);

                Deserialized = JsonConvert.DeserializeObject <CTimeSeriesFromJson>(Json);
            }

            if (Deserialized == null)
            {
                return(new CTimeSeries(Request));
            }
            else
            {
                return(SCTimeSeriesUtilities.ConvertToTimeSeries(Deserialized, Request));
            }
        }
        internal static CTimeSeries ConvertToTimeSeries(CTimeSeriesFromJson FromJson, CTimeSeriesRequest Request)
        {
            CTimeSeries Result = new CTimeSeries(Request);

            // Setup the meta data if any.
            Result.Meta = ConvertToMeta(FromJson);

            // Handle the data
            // We create a CTimeSeriesData object foreach list.
            foreach (var TheList in FromJson.data)
            {
                //SCListUtilities.Print<string>(TheList);

                Result.Data.Add(SCTimeSeriesUtilities.ParseFromStringList(TheList));
            }

            return(Result);
        }
        internal static CTimeSeriesMeta ConvertToMeta(CTimeSeriesFromJson FromJson)
        {
            CTimeSeriesMeta Result = new CTimeSeriesMeta();

            Result.Name        = FromJson.name;
            Result.Description = FromJson.description;
            Result.ColumnNames = FromJson.column_names;
            Result.Frequency   = FromJson.frequency;
            Result.Type        = FromJson.type;

            Result.RefreshedAt         = FromJson.refreshed_at;
            Result.NewestAvailableDate = FromJson.newest_available_date;
            Result.OldestAvailableDate = FromJson.oldest_available_date;

            if (FromJson.premium != null)
            {
                Result.IsPremium = (FromJson.premium.Trim().ToLower() == "true");
            }

            return(Result);
        }