增量价格图近似值 [英] Incremental price graph approximation

查看:100
本文介绍了增量价格图近似值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示类似于CoinMarketCap上的加密货币价格图: https://coinmarketcap .com/currencies/bitcoin/

I need to display a crypto currency price graph based similar to what is done on CoinMarketCap: https://coinmarketcap.com/currencies/bitcoin/

在很长一段时间内,一个货币对可能有千兆字节的数据,因此将所有数据发送到客户端不是一种选择. 经过一些研究,我最终使用了道格拉斯·皮克线近似算法: https://www.codeproject.com/Articles/18936/AC-Implementation-of-Douglas-Peucker-Line-Appro 它可以减少发送给客户端的点数但是有一个问题:每次有新数据时,我都必须遍历服务器上的所有数据,而且由于我想实时更新客户端上的数据,因此需要大量资源.

There could be gigabytes of data for one currency pair over a long period of time, so sending all the data to the client is not an option. After doing some research I ended up using a Douglas-Peucker Line Approximation Algorithm: https://www.codeproject.com/Articles/18936/A-C-Implementation-of-Douglas-Peucker-Line-Appro It allows to reduce the amount of dots that is sent to the client but there's one problem: every time there's new data I have to go through all the data on the server and as I'd like to update data on the client in real time, it takes a lot of resources.

因此,我正在考虑一种渐进算法,例如,如果需要显示上个月的数据,可以将数据分为5分钟间隔,仅预处理最后一个间隔,并在完成后将其删除第一个.我正在讨论自定义Douglas-Peucker算法(但是我不确定是否适合这种情况)或找到一种为此目的而设计的算法(任何提示将不胜感激)

So I'm thinking about a some kind of progressive algorithm where, let's say, if I need to display data for the last month I can split data into 5 minute intervals, preprocess only the last interval and when it's completed, remove the first one. I'm debating either customising the Douglas-Peucker algorithm (but I'm not sure if it fits this scenario) or finding an algorithm designed for this purpose (any hint would be highly appreciated)

推荐答案

当新数据到达时,不断重新计算整个归约点将不断改变您的图形.该图将缺乏一致性.一个用户看到的图形将不同于另一个用户看到的图形,并且当用户刷新页面时该图形将发生变化(这不应该发生!),即使在服务器/应用程序关闭的情况下,您的数据也需要与以前保持一致.

Constantly re-computing the entire reduction points when the new data arrives would change your graph continuously. The graph will lack consistency. The graph seen by one user would be different from the graph seen by another user and the graph would change when the user refreshes the page(this shouldn't happen!), and even in case of server/application shutdown, your data needs to be consistent to what it was before.

  • 这是我的处理方式:

您的减少点应该保持原样.假设您正在获取每秒的数据,并且已经为5分钟的间隔图计算了减少的点,然后将这些数据点保存在限制队列中.现在,收集接下来5分钟的所有秒数数据,并对这600个数据点执行归约操作,并将最后的归约点添加到您的限制队列中.

Your reduced points should be as they are. For suppose, you are getting data for every second and you have computed reduced points for a 5-minute interval graph, save those data points in a limiting queue. Now gather all seconds data for next 5-minutes and perform the reduction operation on these 600 data points and add the final reduced point to your limiting queue.

只要有一个API调用,我都会使队列同步,并且主线程将返回队列中的数据点.并且一旦整个5分钟间隔的数据都可用,工作线程就会在5分钟数据上计算减少点.

I would make the Queue synchronous and the main thread would return the data points in the queue whenever there is an API call. And the worker thread would compute the reduction point on the 5-minute data once the data for the entire 5-minute interval is available.

这篇关于增量价格图近似值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆