summaryrefslogtreecommitdiff
path: root/models/FoxLog.cpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2025-09-15 23:04:33 +0200
committerChristoph Berg <myon@debian.org>2025-09-15 23:04:33 +0200
commite1c678ef00f0159bbeb5571e5ebb0d4697121334 (patch)
tree6547edef81a62a812a4d0f64e03fda226b5f0a7e /models/FoxLog.cpp
parentb9daa22c4c3ad51cd4bc0ef624a19f21d01c9305 (diff)
parent0a13f1fdb9928b6d012569dd65f7f6ef18fac2f8 (diff)
Update upstream source from tag 'upstream/3.0.0_rc1+repack'
Update to upstream version '3.0.0~rc1+repack' with Debian dir 68c212e23136fecf9ebc6f12ff355579224d27ee
Diffstat (limited to 'models/FoxLog.cpp')
-rwxr-xr-xmodels/FoxLog.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/models/FoxLog.cpp b/models/FoxLog.cpp
index 81415d5d..c4fac283 100755
--- a/models/FoxLog.cpp
+++ b/models/FoxLog.cpp
@@ -11,6 +11,7 @@
#include <QSqlQuery>
#include <QTextStream>
#include <QDebug>
+#include "Logger.hpp"
#include "Configuration.hpp"
#include "qt_db_helpers.hpp"
#include "pimpl_impl.hpp"
@@ -37,6 +38,10 @@ public:
Configuration const * configuration_;
QSqlQuery mutable dupe_query_;
QSqlQuery mutable export_query_;
+ // queries for rates
+ QSqlQuery mutable rate_n_query_;
+ QSqlQuery mutable rate60m_query_;
+ QString rate();
};
#include "FoxLog.moc"
@@ -118,6 +123,25 @@ FoxLog::impl::impl (Configuration const * configuration)
" ORDER BY "
" \"when\"");
+ SQL_error_check (rate_n_query_, &QSqlQuery::prepare,
+ "SELECT "
+ " \"when\""
+ " FROM "
+ " fox_log "
+ " ORDER BY "
+ " \"when\" DESC"
+ " LIMIT :limitn"
+ );
+
+ SQL_error_check (rate60m_query_, &QSqlQuery::prepare,
+ "SELECT "
+ " COUNT() "
+ " FROM "
+ " fox_log "
+ " where \"when\" > :one_hour_ago"
+ " ORDER BY "
+ " \"when\" DESC"
+ );
setEditStrategy (QSqlTableModel::OnFieldChange);
setTable ("fox_log");
setHeaderData (fieldIndex ("when"), Qt::Horizontal, tr ("Date & Time(UTC)"));
@@ -135,6 +159,13 @@ FoxLog::impl::impl (Configuration const * configuration)
SQL_error_check (*this, &QSqlTableModel::select);
}
+QString FoxLog::rate()
+{
+ return QString("Last 10: %1, Last 100: %2, Last 60m: %3").arg(QString::number(this->rate_last_n(10),'f',0),
+ QString::number(this->rate_last_n(100),'f',0),
+ QString::number(this->rate_60m()));
+}
+
FoxLog::FoxLog (Configuration const * configuration)
: m_ {configuration}
{
@@ -221,6 +252,47 @@ void FoxLog::reset ()
}
}
+int FoxLog::rate_60m()
+{
+ int rate60m = 0;
+ qlonglong const& one_hour_ago = QDateTime::currentDateTime().addSecs(-3600).toMSecsSinceEpoch () / 1000;
+
+ // query the 60m rate
+ m_->rate60m_query_.bindValue (":one_hour_ago", one_hour_ago);
+ SQL_error_check (m_->rate60m_query_, static_cast<bool (QSqlQuery::*) ()> (&QSqlQuery::exec));
+ m_->rate60m_query_.next ();
+ rate60m = m_->rate60m_query_.value (0).toLongLong();
+ return rate60m;
+ //
+}
+
+double FoxLog::rate_last_n(int n)
+{
+ double rate_interval = 0;
+
+ qlonglong const& secs_now = QDateTime::currentDateTime().toMSecsSinceEpoch () / 1000;
+
+ // get last n or up to n
+ m_->rate_n_query_.bindValue (":limitn", n);
+ SQL_error_check (m_->rate_n_query_, static_cast<bool (QSqlQuery::*) ()> (&QSqlQuery::exec));
+
+ m_->rate_n_query_.next();
+ if (!m_->rate_n_query_.isValid()) {
+ LOG_ERROR(QString("rate_n result is not valid. Last error %1").arg(m_->rate_n_query_.lastError().text()));
+ return 0.0;
+ }
+ // size / (time_now - time_of_first)
+ m_->rate_n_query_.last();
+ rate_interval = secs_now - m_->rate_n_query_.value (0).toLongLong ();
+ if (rate_interval == 0) return 0.0;
+
+ m_->rate_n_query_.first(); // count the records
+
+ int size = 1;
+ while (m_->rate_n_query_.next() && m_->rate_n_query_.isValid()) size++;
+ return (size/rate_interval) * 3600;
+}
+
namespace
{
struct ADIF_field