summaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rwxr-xr-xmodels/FoxLog.cpp72
-rwxr-xr-xmodels/FoxLog.hpp3
-rwxr-xr-xmodels/FrequencyList.cpp4
3 files changed, 77 insertions, 2 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
diff --git a/models/FoxLog.hpp b/models/FoxLog.hpp
index 67ea66bc..850ac1f1 100755
--- a/models/FoxLog.hpp
+++ b/models/FoxLog.hpp
@@ -26,6 +26,9 @@ public:
QSqlTableModel * model ();
void reset ();
void export_qsos (QTextStream&) const;
+ QString rate();
+ double rate_last_n(int n); // get the rate for the last n
+ int rate_60m();
private:
class impl;
diff --git a/models/FrequencyList.cpp b/models/FrequencyList.cpp
index 03176584..5b7f2be6 100755
--- a/models/FrequencyList.cpp
+++ b/models/FrequencyList.cpp
@@ -1335,8 +1335,8 @@ FrequencyList_v2_101::FrequencyItems FrequencyList_v2_101::from_json_file(QFile
{
throw ReadFileException{tr ("No Frequencies were found")};
}
- int valid_entry_count = 0;
- int skipped_entry_count = 0;
+ int valid_entry_count [[maybe_unused]] = 0;
+ int skipped_entry_count [[maybe_unused]] = 0;
for (auto const &item: arr)
{
QString mode_s, region_s;