mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-05-29 21:02:26 -04:00
show last_10, last_100, and last 60m rates in FoxLog window
This commit is contained in:
parent
c348791b28
commit
7aa00f33a8
@ -11,6 +11,7 @@
|
|||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "Logger.hpp"
|
||||||
#include "Configuration.hpp"
|
#include "Configuration.hpp"
|
||||||
#include "qt_db_helpers.hpp"
|
#include "qt_db_helpers.hpp"
|
||||||
#include "pimpl_impl.hpp"
|
#include "pimpl_impl.hpp"
|
||||||
@ -37,6 +38,10 @@ public:
|
|||||||
Configuration const * configuration_;
|
Configuration const * configuration_;
|
||||||
QSqlQuery mutable dupe_query_;
|
QSqlQuery mutable dupe_query_;
|
||||||
QSqlQuery mutable export_query_;
|
QSqlQuery mutable export_query_;
|
||||||
|
// queries for rates
|
||||||
|
QSqlQuery mutable rate_n_query_;
|
||||||
|
QSqlQuery mutable rate60m_query_;
|
||||||
|
QString rate();
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "FoxLog.moc"
|
#include "FoxLog.moc"
|
||||||
@ -118,6 +123,25 @@ FoxLog::impl::impl (Configuration const * configuration)
|
|||||||
" ORDER BY "
|
" ORDER BY "
|
||||||
" \"when\"");
|
" \"when\"");
|
||||||
|
|
||||||
|
SQL_error_check (rate_n_query_, &QSqlQuery::prepare,
|
||||||
|
"SELECT "
|
||||||
|
" \"when\""
|
||||||
|
" FROM "
|
||||||
|
" fox_log "
|
||||||
|
" ORDER BY "
|
||||||
|
" \"when\" DESC"
|
||||||
|
" LIMIT 100"
|
||||||
|
);
|
||||||
|
|
||||||
|
SQL_error_check (rate60m_query_, &QSqlQuery::prepare,
|
||||||
|
"SELECT "
|
||||||
|
" COUNT() "
|
||||||
|
" FROM "
|
||||||
|
" fox_log "
|
||||||
|
" where \"when\" > :one_hour_ago"
|
||||||
|
" ORDER BY "
|
||||||
|
" \"when\" DESC"
|
||||||
|
);
|
||||||
setEditStrategy (QSqlTableModel::OnFieldChange);
|
setEditStrategy (QSqlTableModel::OnFieldChange);
|
||||||
setTable ("fox_log");
|
setTable ("fox_log");
|
||||||
setHeaderData (fieldIndex ("when"), Qt::Horizontal, tr ("Date & Time(UTC)"));
|
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);
|
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),'g',1),
|
||||||
|
QString::number(this->rate_last_n(100),'g',1),
|
||||||
|
QString::number(this->rate_60m()));
|
||||||
|
}
|
||||||
|
|
||||||
FoxLog::FoxLog (Configuration const * configuration)
|
FoxLog::FoxLog (Configuration const * configuration)
|
||||||
: m_ {configuration}
|
: m_ {configuration}
|
||||||
{
|
{
|
||||||
@ -221,6 +252,45 @@ 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 (":lastn", 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 ();
|
||||||
|
|
||||||
|
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
|
namespace
|
||||||
{
|
{
|
||||||
struct ADIF_field
|
struct ADIF_field
|
||||||
|
@ -26,6 +26,9 @@ public:
|
|||||||
QSqlTableModel * model ();
|
QSqlTableModel * model ();
|
||||||
void reset ();
|
void reset ();
|
||||||
void export_qsos (QTextStream&) const;
|
void export_qsos (QTextStream&) const;
|
||||||
|
QString rate();
|
||||||
|
double rate_last_n(int n); // get the rate for the last n
|
||||||
|
int rate_60m();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class impl;
|
class impl;
|
||||||
|
@ -47,7 +47,7 @@ FoxLogWindow::FoxLogWindow (QSettings * settings, Configuration const * configur
|
|||||||
m_->ui_.log_table_view->setItemDelegateForColumn (3, new MaidenheadLocatorDelegate {this});
|
m_->ui_.log_table_view->setItemDelegateForColumn (3, new MaidenheadLocatorDelegate {this});
|
||||||
m_->ui_.log_table_view->setItemDelegateForColumn (6, new ForeignKeyDelegate {configuration->bands (), 0, this});
|
m_->ui_.log_table_view->setItemDelegateForColumn (6, new ForeignKeyDelegate {configuration->bands (), 0, this});
|
||||||
m_->ui_.log_table_view->horizontalHeader ()->moveSection (6, 1); // move band to first column
|
m_->ui_.log_table_view->horizontalHeader ()->moveSection (6, 1); // move band to first column
|
||||||
m_->ui_.rate_label->setNum (0);
|
m_->ui_.rate_label->setText ("");
|
||||||
m_->ui_.queued_label->setNum (0);
|
m_->ui_.queued_label->setNum (0);
|
||||||
m_->ui_.callers_label->setNum (0);
|
m_->ui_.callers_label->setNum (0);
|
||||||
|
|
||||||
@ -111,6 +111,11 @@ void FoxLogWindow::rate (int n)
|
|||||||
m_->ui_.rate_label->setNum (n);
|
m_->ui_.rate_label->setNum (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FoxLogWindow::rate (QString s)
|
||||||
|
{
|
||||||
|
m_->ui_.rate_label->setText(s);
|
||||||
|
}
|
||||||
|
|
||||||
void FoxLogWindow::log_model_changed (int row)
|
void FoxLogWindow::log_model_changed (int row)
|
||||||
{
|
{
|
||||||
if (row >= 0)
|
if (row >= 0)
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
void callers (int);
|
void callers (int);
|
||||||
void queued (int);
|
void queued (int);
|
||||||
void rate (int);
|
void rate (int);
|
||||||
|
void rate (QString);
|
||||||
|
|
||||||
Q_SIGNAL void reset_log_model () const;
|
Q_SIGNAL void reset_log_model () const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user