如何消除“抖动”从我的“预计剩余时间”开始(和预计到达时间)计算?
我有一个应用程序,在执行后台任务时,显示一个进度条,其中包含“估计剩余时间”计算(例如“剩余 5 秒”)和“估计完成时间”(例如“在 12:59:59 完成” ”),或者我称之为预计到达时间(ETA)。
计算此 ETA 的算法基本上采用随时间推移的进度“滚动平均值”:
1. 每个进度事件都会添加到当前时间的队列中。
2. 经过一定时间(例如10秒)后,项目将从队列中删除。
3. ETA 是根据队列中的第一个和最后一个项目推断出来的。
如果您关心的话,可以使用源代码: ETACalculator.cs
但是,存在抖动问题。随着每个进度事件被添加到计算中,预计到达时间将略有更新。假设 ETA 仅改变 0.1s
。这种微小的抖动很容易导致ETA“抖动”。例如,我看到的不是 5、4、3 等的平滑进展,而是 5-5-5-4-5-4-5-4-5-4-4-4。
我正在考虑将更新减少到每秒 1 次,但进度条不太平滑,而且我真的希望实时显示“实际”减速。
我很难想出一个简单的算法来减少这种跳跃性抖动。如何消除抖动?
I have an application that, while performing a background task, shows a progress bar with an "estimated time remaining" calculation (eg "5 seconds remaining") and a "estimated time of completion" (eg "complete at 12:59:59"), or as I call it, the ETA.
The algorithm for calculating this ETA basically takes the "rolling average" of progress over time:
1. Each progress event gets added to a queue with the current time.
2. After a certain duration (eg. 10s), items are removed from the queue.
3. The ETA is extrapolated from the first and last items in the queue.
The source code is available if you care: ETACalculator.cs
However, there's a jitter problem. As each progress event is added to the calculation, the ETA will be updated slightly. Let's say that the ETA changes by only 0.1s
. This small jitter easily causes the ETA to "flutter". For example, instead of seeing a smooth progression from 5s, 4s, 3s, etc..., I see 5-5-5-4-5-4-5-4-5-4-4-4.
I was thinking of just reducing the updates to 1-per-second, but then the progress bar is less smooth, and also I'd really like "actual" slowdowns to be shown real time.
I'm having trouble coming up with a simple algorithm that reduces this jumpy jitter. How can I remove the jitter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将实际抖动进度和显示进度分成两个单独的变量。
像现在一样更新紧张的进度。
定期(相对较快)间隔更新显示的进度,以接近实际进度。
一种简单的方法算法是对两个值进行平均,
这将抑制该值以反映过去的值,而不仅仅是立即值。
您还可以使用以下方法优化平滑度:
其中
P
是0.0
和1.0
之间的常量值。编辑:
这是可以使用的众多过滤器之一。这个很好,因为它不需要太多簿记。
然而,获得完美输出并不是一种选择,因为缺陷存在于您的输入中。 “抖动”和“实际减速”之间的差异只有在发生之后才能观察到。
Separate the actual jittery progress and the displayed progress into two separate variables.
Update the jittery progress as you do now.
At a regular (relatively quick) interval, update the displayed progress to approach the actual progress.
A simple approach algorithm would be to average the two values
This will dampen the value to reflect past values and not just the immediate value.
You can also refine the smoothness by using:
Where
P
is a constant value between0.0
and1.0
.Edit:
This is one of many filters that could be used. This one is nice in that it doesn't require much bookkeeping.
However, getting perfect output is not going to be an option, because the flaw is in your input. The difference between "jitter" and "actual slowdowns" is only observable after it has happened.
在没有看到代码的情况下不太清楚您的算法,但是当您更新 ETA 时,只需首先检查当前的 ETA,并且仅在新值低于旧值时才更新它。
Not quite clear on your algorithm without seeing code, but when you update your ETA just first check the current ETA and only update it if the new value is lower than the old.
听起来你想要的是“去抖动”:选择最后一个 X 值中的最小值。
It sounds like what you want is to "debounce": choose the lowest value of the last X values.