Пример #1
0
        public DataSet ReadData(DataRequest request)
        {
            DataQuerySchema querySchema = QuandlQueryParamGroup.QueryParamGroup;
            Parser parser = QuandlQueryParser.Parser;

            IQuerySerializer<Dictionary<string, object>> objectMapSerializer = new QuandlQueryObjectMapSerializer();

            IQuery convertedQuery = objectMapSerializer.Deserialize(request.Query.Parameters);
            string url = convertedQuery.ToUrl();

            string results = null;

            using (QueryClient client = new QueryClient())
            {
                results = client.DownloadString(url);
            }

            // TODO: Move
            DataHeader dataHeader = STOCK_DATA_HEADER;

            // TODO: Should be dependent on data paramters passed in
            List<DataRecord> dataRecords = new List<DataRecord>();

            // TODO: Cleanup
            string[] lines = results.Split(new char[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);

            foreach(string line in lines)
            {
                // TODO: Refactor and generalize

                string[] parts = line.Split(new char[] {','}, StringSplitOptions.None);

                object datePart = parser.Parse(parts[0], CommonTypes.DateTime);
                object pricePart = parser.Parse(parts[1], CommonTypes.Double);

                DataRecord record = new DataRecord(datePart, pricePart);

                dataRecords.Add(record);
            }

            return new DataSet(dataHeader, dataRecords);
        }
Пример #2
0
 public DataSet ReadDataSet(string provider, string table, DataRequest request)
 {
     IDataProvider providerObj = providers[provider];
     return providerObj.ReadData(table, request);
 }
Пример #3
0
        public void TestCase2()
        {
            // Web url is: https://www.quandl.com/api/v1/datasets/WIKI/AAPL.csv?sort_order=asc&exclude_headers=true&rows=3&trim_start=2012-11-01&trim_end=2013-11-30&column=4&collapse=quarterly&transformation=rdiff

            DataField[] expectedDataFields = new DataField[] { new DataField("StockData", CommonTypes.DateTime), new DataField("PriceValue", CommonTypes.Double) };
            DataHeader expectedHeader = new DataHeader(expectedDataFields);

            List<DataRecord> expectedDataRecords = new List<DataRecord>
            {
                new DataRecord(new DateTime(2013, 3, 31), -0.16820266496096),
                new DataRecord(new DateTime(2013, 6, 30), -0.10421090679077),
                new DataRecord(new DateTime(2013, 9, 30), 0.2023049958389),
            };

            DataSet expectedDataSet = new DataSet(expectedHeader, expectedDataRecords);

            QuandlDataProvider provider = new QuandlDataProvider();

            Dictionary<string, string> dataPathParams = new Dictionary<string, string>()
            {
                { "DatabaseCode", "WIKI" },
                { "TableCode", "AAPL" },
                { "FormatCode", "CSV" },
            };

            Dictionary<string, object> dataQueryParams = new Dictionary<string,object>
            {
                { "DatabaseCode", "WIKI" },
                { "TableCode", "AAPL" },
                { "FormatCode", FileType.CSV },
                { "AuthToken", null },
                { "TrimStart", new DateTime(2012, 11, 1)},
                { "TrimEnd", new DateTime(2013, 11, 30) },
                { "SortOrder", SortOrder.Ascending },
                { "ExcludeHeader", true },
                { "ExcludeData", null },
                { "Rows", 3},
                { "Column", 4},
                { "Frequency", CollapseType.Quarterly },
                { "Calculation", TransformationType.Rdiff }
            };

            // TODO: Make it typed

            DataPath dataPath = new DataPath(dataPathParams);
            DataQuery dataQuery = new DataQuery(dataQueryParams);

            DataRequest request = new DataRequest(dataPath, dataQuery);

            DataSet actualDataSet = provider.ReadData(request);

            AreEqual(expectedDataSet, actualDataSet);
        }
Пример #4
0
 public DataSet ReadData(string table, DataRequest request)
 {
     throw new NotImplementedException();
 }