use of com.biglybt.core.util.average.MovingImmediateAverage in project BiglyBT by BiglySoftware.
the class DownloadActivityView method dataSourceChanged.
public void dataSourceChanged(Object newDataSource) {
if (!comp_focused) {
focus_pending_ds = newDataSource;
return;
}
DownloadManager newManager = ViewUtils.getDownloadManagerFromDataSource(newDataSource);
if (newManager == manager) {
return;
}
manager = newManager;
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (panel == null || panel.isDisposed()) {
return;
}
Utils.disposeComposite(panel, false);
if (manager != null) {
fillPanel();
parent.layout(true, true);
} else {
ViewUtils.setViewRequiresOneDownload(panel);
}
}
});
if (manager == null) {
mpg.setActive(false);
mpg.reset(new int[5][0]);
} else {
DownloadManagerStats stats = manager.getStats();
stats.setRecentHistoryRetention(true);
int[][] _history = stats.getRecentHistory();
// reconstitute the smoothed values to the best of our ability (good enough unless we decide we want
// to throw more memory at remembering this more accurately...)
int[] send_history = _history[0];
int[] recv_history = _history[1];
int history_secs = send_history.length;
int[] smoothed_send = new int[history_secs];
int[] smoothed_recv = new int[history_secs];
MovingImmediateAverage send_average = GeneralUtils.getSmoothAverage();
MovingImmediateAverage recv_average = GeneralUtils.getSmoothAverage();
int smooth_interval = GeneralUtils.getSmoothUpdateInterval();
int current_smooth_send = 0;
int current_smooth_recv = 0;
int pending_smooth_send = 0;
int pending_smooth_recv = 0;
for (int i = 0; i < history_secs; i++) {
pending_smooth_send += send_history[i];
pending_smooth_recv += recv_history[i];
if (i % smooth_interval == 0) {
current_smooth_send = (int) (send_average.update(pending_smooth_send) / smooth_interval);
current_smooth_recv = (int) (recv_average.update(pending_smooth_recv) / smooth_interval);
pending_smooth_send = 0;
pending_smooth_recv = 0;
}
smoothed_send[i] = current_smooth_send;
smoothed_recv[i] = current_smooth_recv;
}
int[][] history = { send_history, smoothed_send, recv_history, smoothed_recv, _history[2] };
mpg.reset(history);
mpg.setActive(true);
}
}
Aggregations