File indexing completed on 2024-04-14 03:49:47

0001 /*
0002     This file is part of the KDE Baloo Project
0003     SPDX-FileCopyrightText: 2015 Pinak Ahuja <pinak.ahuja@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef BALOO_TIMEESTIMATOR_H
0009 #define BALOO_TIMEESTIMATOR_H
0010 
0011 #define BUFFER_SIZE 5
0012 
0013 #include <QtGlobal>
0014 
0015 namespace Baloo {
0016 /*
0017 * This class handles the time estimation logic for filecontentindexer.
0018 * Time estimations use a weighted moving average of the time taken by
0019 * 5 most recent batches. The more recent the batch is, higher the weight
0020 * it will be assigned.
0021 */
0022 
0023 class TimeEstimator
0024 {
0025 public:
0026     TimeEstimator();
0027     uint calculateTimeLeft(int filesLeft);
0028 
0029     void handleNewBatchTime(uint time, uint batchSize);
0030 
0031 private:
0032     float m_batchTimeBuffer[BUFFER_SIZE];
0033 
0034     int m_bufferIndex = 0;
0035     bool m_estimateReady = false;
0036 };
0037 
0038 }
0039 
0040 #endif //BALOO_TIMEESTIMATOR_H