public Message CSVMessage(MessageVersion messageVersion, TimeSeriesResponse origResult) { MultipleTimeSeries result = null; if (origResult is MultipleTimeSeries) { result = (MultipleTimeSeries)origResult; } else if (origResult is TimeSeriesFullSummary) { result = new MultipleTimeSeries(origResult as TimeSeriesFullSummary); } else // SimpleTimeSeries { result = new MultipleTimeSeries(((SimpleTimeSeries)origResult).Slim()); } StringBuilder sb = new StringBuilder(); sb.Append(BuildHeader(result)); sb.AppendLine("-----------------------"); sb.Append(BuildBody(result)); Message reply = Message.CreateMessage(messageVersion, null, new RawBodyWriter(sb.ToString())); reply.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Raw)); HttpResponseMessageProperty httpResp = new HttpResponseMessageProperty(); reply.Properties.Add(HttpResponseMessageProperty.Name, httpResp); httpResp.Headers[HttpResponseHeader.ContentType] = "text/csv"; return(reply); }
public async Task GetTimeSeries_Success() { TimeSeriesRequest request = new TimeSeriesRequest() { MeasurementName = "temperature", ValueType = TimeSeriesValueType.Float, Range = TimeSeriesRange.OneDay, Tags = new Dictionary <string, string>() { ["location"] = "Room1" } }; var dataPoints = new List <DataPoint>() { new DataPoint <float>(new DateTime(2020, 10, 30), 3.14f), new DataPoint <float>(new DateTime(2020, 10, 31), 3.14f) }; TimeSeriesResponse response = new TimeSeriesResponse() { Status = TimeSeriesResponseStatus.Success, DataPoints = dataPoints }; IInfluxDBProvider influxProvider = Substitute.For <IInfluxDBProvider>(); influxProvider.GetTimeSeriesAsync(request).Returns(Task.FromResult(response)); TimeSeriesController controller = new TimeSeriesController(influxProvider); var result = await controller.GetTimeSeries(request); var okResult = Assert.IsType <OkObjectResult>(result.Result); var resultList = Assert.IsType <List <DataPoint> >(okResult.Value); Assert.Equal(dataPoints, resultList); }
public async Task GetTimeSeries_BadRequest() { TimeSeriesRequest request = new TimeSeriesRequest() { MeasurementName = "temperature", ValueType = TimeSeriesValueType.Float, Range = TimeSeriesRange.OneDay, Tags = new Dictionary <string, string>() { ["location"] = "Room1" } }; TimeSeriesResponse response = new TimeSeriesResponse() { Status = TimeSeriesResponseStatus.BadRequest, DataPoints = null }; IInfluxDBProvider influxProvider = Substitute.For <IInfluxDBProvider>(); influxProvider.GetTimeSeriesAsync(request).Returns(Task.FromResult(response)); TimeSeriesController controller = new TimeSeriesController(influxProvider); var result = await controller.GetTimeSeries(request); Assert.IsType <BadRequestResult>(result.Result); }
private void FillCotacoes(TimeSeriesResponse res) { foreach (DataRow cotacao in res.Data.Rows) { DataRow row = Data.NewRow(); row["EXT_ID"] = res.Request.Datacode.ToString(); row["ProcessId"] = Queue.Process.Id; row["AtivoId"] = 0; row["DataPregao"] = res.Request.EndDate; row["NomeResumido"] = res.Request.Datacode.ToString(); row["EspecPapel"] = ""; row["Ticker"] = res.Request.Datacode.ToString('.'); row["TipoMercado"] = 99; row["PrecoAbertura"] = cotacao[Queue.Process.Feed.GetValue("ColumnValue")]; row["PrecoMaximo"] = cotacao[Queue.Process.Feed.GetValue("ColumnValue")]; row["PrecoMedio"] = cotacao[Queue.Process.Feed.GetValue("ColumnValue")]; row["PrecoMinimo"] = cotacao[Queue.Process.Feed.GetValue("ColumnValue")]; row["PrecoFechamento"] = cotacao[Queue.Process.Feed.GetValue("ColumnValue")]; row["Quantidade"] = 1; row["TotalNegocios"] = 1; row["Volume"] = 1; row["ISIN"] = ""; row["Variacao"] = 0; Data.Rows.Add(row); } }
public override void ExecuteFeed() { try { Tebaldi.Quandl.Business.Connection conn = new Tebaldi.Quandl.Business.Connection(); TimeSeriesResponse res = conn.Get(request); FillCotacoes(res); } catch (Exception ex) { logger.Error("Erro no processamento do arquivo bdi", ex); throw; } }
public async Task <TimeSeriesResponse> GetTimeSeriesAsync(TimeSeriesRequest request) { TimeSeriesResponse response = new TimeSeriesResponse(); try { string url = $"{apiUrl}/query"; var httpClient = clientFactory.CreateClient(); var httpRequest = new HttpRequestMessage() { RequestUri = new Uri(url), Method = HttpMethod.Post }; httpRequest.Headers.Add("Accept", "application/csv"); string flux = fluxHelper.CreateQuery(options.Database, request); httpRequest.Content = new StringContent( flux, Encoding.UTF8, "application/vnd.flux" ); var httpResponseMessage = await httpClient.SendAsync(httpRequest); string queryResult = await httpResponseMessage.Content.ReadAsStringAsync(); response.DataPoints = queryResultParser.ParseQueryResult(queryResult, request.ValueType); response.Status = TimeSeriesResponseStatus.Success; } catch { response.DataPoints = null; response.Status = TimeSeriesResponseStatus.InternalError; } return(response); }