Baloo

timeestimator.cpp
1/*
2 This file is part of the KDE Baloo Project
3 SPDX-FileCopyrightText: 2015 Pinak Ahuja <pinak.ahuja@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include <cmath>
9
10#include "timeestimator.h"
11
12using namespace Baloo;
13
14TimeEstimator::TimeEstimator() = default;
15
16uint TimeEstimator::calculateTimeLeft(int filesLeft)
17{
18 if (!m_estimateReady) {
19 return 0;
20 }
21
22 float totalTime = 0;
23 float totalWeight = 0;
24
25 int bufferIndex = m_bufferIndex;
26 for (int i = 0; i < BUFFER_SIZE; ++i) {
27 float weight = sqrt(i + 1);
28 totalWeight += weight;
29
30 totalTime += m_batchTimeBuffer[bufferIndex] * weight;
31 bufferIndex = (bufferIndex + 1) % BUFFER_SIZE;
32 }
33
34 float weightedAverage = totalTime / totalWeight;
35
37}
38
39void TimeEstimator::handleNewBatchTime(uint time, uint batchSize)
40{
41 // add the current batch time in place of the oldest batch time
42 m_batchTimeBuffer[m_bufferIndex] = (float)time / batchSize;
43
44 m_bufferIndex = (m_bufferIndex + 1) % BUFFER_SIZE;
45
46 if (!m_estimateReady && m_bufferIndex == 0) {
47 // Buffer has been filled once. We are ready to estimate
48 m_estimateReady = true;
49 }
50}
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 11:58:46 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.