local ideas to git

This commit is contained in:
acetone
2022-11-18 20:38:36 +03:00
parent 85431eb94c
commit cc19774a57
25 changed files with 2032 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
/*
3proxy-eagle: Accumulate ethical 3proxy statistics with web interface.
Source code: https://notabug.org/acetone/3proxy-eagle.
Copyright (C) 2022, acetone
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "statistics.h"
#include "g.h"
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QJsonArray>
#include <QDebug>
#include <QFile>
QStringList Statistics::m_lastDestinations;
qint64 Statistics::m_lastSerializeTimestamp = 0;
bool Statistics::m_deserialized = false;
DailyCounter Statistics::m_dailyUpload;
DailyCounter Statistics::m_dailyDownload;
quint64 Statistics::m_totalUpload = 0;
quint64 Statistics::m_totalDownload = 0;
void Statistics::report(const LogEvent& event)
{
// mutex enabled in ProxyInstanse::reader()
deserialize();
if (g::p::IGNORED_DESTINATIONS.contains(event.dest))
{
qDebug() << "Destination" << event.dest << "ignored";
return;
}
addToDestinationsList(event.dest);
incrementUpload(event.to);
incrementDownload(event.from);
// type not handled
serialize();
}
void Statistics::incrementUpload(quint64 value)
{
m_dailyUpload.increment(value);
m_totalUpload += value;
}
void Statistics::incrementDownload(quint64 value)
{
m_dailyDownload.increment(value);
m_totalDownload += value;
}
void Statistics::addToDestinationsList(const QString &dest)
{
if (static_cast<uint>(lastDestinations().size()) >= g::p::LAST_AND_TOP_LIST_SIZE)
{
m_lastDestinations.pop_back();
}
m_lastDestinations.push_front(dest);
}
void Statistics::serialize()
{
QFile file(g::p::WORKING_DIR + "/statistics.json");
}
void Statistics::deserialize()
{
if (m_deserialized) return;
QFile file(g::p::WORKING_DIR + "/statistics.json");
}