[英]Processing large data from an API to visualise
Let's say I have an API that gives me the values of stock for the last month. 假设我有一个API,可为我提供上个月的库存值。 The data is sampled every hour. 每小时采样一次数据。
Now I want to make a web app that would visualize this data on a line chart. 现在,我想制作一个Web应用程序,以可视化的折线图形式显示这些数据。 I don't need all the hourly samples, so my question is how should I make this work? 我不需要所有小时样本,所以我的问题是我应该如何进行这项工作?
My idea is that there would be a backend app (ie in Java Spring) that would GET the data from the API and calculate the average for each day (using a stream, maybe parallel stream?) and then put that in a new collection and pass it on to the front end to put in a chart. 我的想法是,将有一个后端应用程序(例如,在Java Spring中),该应用程序将从API中获取数据并计算每天的平均值(使用流,也许是并行流?),然后将其放入一个新集合中,将其传递到前端以放入图表。
Start thinking from the UI, what do you need there, how often do you need it and how fast ? 从UI开始思考,在那里需要什么,需要多久使用一次,速度有多快?
Then get the data from the backend, if there is too much data at once and the API cannot do otherwise, either: 然后,如果一次有太多数据并且API无法执行其他操作,则从后端获取数据:
For the return format, consider something lightweight, like some simple named json array {"dayAverages": [0.34, 1253.432, ...]}, "month" : 2, "year": 2018}
, then in the UI adapt to the needs of your lib (that is debatable). 对于返回格式,请考虑一些轻量级的东西,例如一些简单的命名json数组{"dayAverages": [0.34, 1253.432, ...]}, "month" : 2, "year": 2018}
,然后在UI中进行调整lib的需求(值得商is)。
Also observe how users use the UI, then you may get some ideas on how to optimize the experience (preload next month ...) 还要观察用户如何使用UI,然后您将获得一些有关如何优化体验的想法(下个月预加载...)
If you do this for learning purposes, consider doing it async + lambdas = bonus :) 如果您出于学习目的这样做,请考虑使其异步+ lambdas = bonus :)
As to your question "...how should I make this work?" 关于您的问题“ ...我应该如何进行这项工作?” -- -
This is extremely broad. 这是非常广泛的。 There are many, many ways to do this. 有很多很多方法可以做到这一点。 Some of these ways depend heavily on your architecture, how much traffic is expected to your app, what request-load the API can handle, etc. Here are a few general things to consider: 这些方式中的某些方式在很大程度上取决于您的体系结构,应用程序预期的流量,API可以处理的请求负载等。以下是一些需要考虑的常规事项:
Hope that helps. 希望能有所帮助。 We could give more if you ask some specific questions. 如果您提出一些具体问题,我们可以提供更多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.