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 | #ifndef BALOO_TIMEESTIMATOR_H |
9 | #define BALOO_TIMEESTIMATOR_H |
10 | |
11 | #define BUFFER_SIZE 5 |
12 | |
13 | #include <QAtomicInteger> |
14 | |
15 | namespace Baloo { |
16 | /* |
17 | * This class handles the time estimation logic for filecontentindexer. |
18 | * Time estimations use a weighted moving average of the time taken by |
19 | * 5 most recent batches. The more recent the batch is, higher the weight |
20 | * it will be assigned. |
21 | */ |
22 | |
23 | class TimeEstimator |
24 | { |
25 | public: |
26 | TimeEstimator(); |
27 | uint calculateTimeLeft() const; |
28 | |
29 | void setProgress(uint remainingCount) |
30 | { |
31 | m_remainingCount.storeRelaxed(newValue: remainingCount); |
32 | } |
33 | void handleNewBatchTime(uint time, uint batchSize); |
34 | |
35 | private: |
36 | float m_batchTimeBuffer[BUFFER_SIZE]; |
37 | |
38 | int m_bufferIndex = 0; |
39 | bool m_estimateReady = false; |
40 | |
41 | QAtomicInteger<uint> m_remainingCount = 0; |
42 | }; |
43 | |
44 | } |
45 | |
46 | #endif //BALOO_TIMEESTIMATOR_H |
47 | |