简体   繁体   English

从API处理大数据以可视化

[英]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无法执行其他操作,则从后端获取数据:

  • get data and reduce to what the UI needs (backend), use once and throw away 获取数据并减少到UI所需的内容(后端),使用一次并丢弃
  • OR get data and reduce to what the UI needs (backend), keep in cache for a while 或获取数据并减少到UI所需的内容(后端),在缓存中保留一会儿
  • OR pre-process the data so that when the UI needs it, it will be ready 或预处理数据,以便在用户界面需要时准备就绪

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可以处理的请求负载等。以下是一些需要考虑的常规事项:

  • Any sort of MVC architecture (or similar) would be a good fit for your Web app. 任何种类的MVC架构(或类似的架构)都非常适合您的Web应用程序。
  • You mention needing a "backend app" of some type. 您提到需要某种类型的“后端应用程序”。 Not sure what you mean here, but the averaging features can be built directly into your Web app framework without needing a separate back-end app. 不确定您的意思是什么,但是平均功能可以直接内置到Web应用程序框架中,而无需单独的后端应用程序。
  • If you're going to calculate averages for display in the Web app, you will need to maintain state somewhere. 如果要计算平均值以显示在Web应用程序中,则需要在某处保持状态。 Assuming the API doesn't give this to you, you'll need a database of some type, or at least some type of memory caching storage engine to facilitate this. 假设API没有提供给您,您将需要某种类型的数据库,或者至少需要某种类型的内存缓存存储引擎来简化此过程。 How you do this will depend on your architecture and the traffic/load on your app (eg will you have multiple, load-balanced servers). 如何执行此操作将取决于您的体系结构和应用程序的流量/负载(例如,您是否将拥有多个负载平衡的服务器)。

Hope that helps. 希望能有所帮助。 We could give more if you ask some specific questions. 如果您提出一些具体问题,我们可以提供更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM