total history

This commit is contained in:
acetone
2023-02-10 10:55:04 +03:00
parent 30b0590d28
commit 971dad786b
11 changed files with 94 additions and 20 deletions
+31 -4
View File
@@ -19,6 +19,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "statistics.h"
#include "dbmanager.h"
#include "webpage.h"
#include "g.h"
#include <QRegularExpression>
@@ -36,8 +37,8 @@ std::atomic<quint64> Statistics::m_totalUpload {0};
std::atomic<quint64> Statistics::m_totalDownload {0};
QMutex Statistics::m_topDestinationsMtx;
TopDestinationList Statistics::m_dailyTopDestinations;
TopDestinationList Statistics::m_totalTopDestinations;
DestinationList Statistics::m_dailyTopDestinations;
DestinationList Statistics::m_totalTopDestinations;
bool Statistics::m_cacheUpdatedAfterLastReport = false;
qint64 Statistics::m_actualizeTopListsLastTimestamp = 0;
@@ -91,7 +92,7 @@ const QStringList Statistics::lastDestinations()
return m_lastDestinations;
}
const TopDestinationList Statistics::dailyTopDestinations()
const DestinationList Statistics::dailyTopDestinations()
{
if (not m_cacheUpdatedAfterLastReport)
{
@@ -101,7 +102,7 @@ const TopDestinationList Statistics::dailyTopDestinations()
return m_dailyTopDestinations;
}
const TopDestinationList Statistics::totalTopDestinations()
const DestinationList Statistics::totalTopDestinations()
{
QMutexLocker lock (&m_topDestinationsMtx);
return m_totalTopDestinations;
@@ -116,6 +117,32 @@ void Statistics::initTrafficCounters()
m_totalUpload = db.totalUploadTraffic();
}
QString Statistics::statsTxt()
{
static QMutex mtx;
if (not mtx.tryLock())
{
return "Service is busy, try again later.";
}
auto raw = DBManager().allHistory();
quint64 totalRequests = 0;
QString result;
for (const auto& record: raw)
{
result += WebPage::counterToHumanReadableString(record.second) + "\t" + record.first + "\n";
totalRequests += record.second;
}
result.push_front("Total destinations: " + WebPage::counterToHumanReadableString(raw.size()) + "\n"
"Total requests: " + WebPage::counterToHumanReadableString(totalRequests) + "\n\n");
mtx.unlock();
return result;
}
void Statistics::actualizeTopLists()
{
QMutexLocker lock (&m_topDestinationsMtx);