Skip to content

Commit

Permalink
Added relays into Quickshow (#949)
Browse files Browse the repository at this point in the history
* Added relays into Quickshow

* Fix code review

---------

Co-authored-by: Lukas Konig <lukas.konig@unicornuniverse.eu>
  • Loading branch information
xkenia and Lukas Konig authored Oct 16, 2023
1 parent 5a3b444 commit c6d1db9
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 65 deletions.
2 changes: 2 additions & 0 deletions quickshow/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ QVariantMap Application::eventInfo()
while(q.next())
info[q.value(0).toString().mid(6)] = q.value(1);
info["profile"] = profile();
//set info about relay
info["isRelay"] = (info["disciplineId"] == 5 || info["disciplineId"] == 6);
}
return info;
}
Expand Down
27 changes: 23 additions & 4 deletions quickshow/src/cellrenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "cellrenderer.h"

#include "application.h"
#include <qf/core/log.h>
#include <qf/core/utils.h>
#include "src/appclioptions.h"

#include <QFontMetrics>
#include <QPainter>
Expand Down Expand Up @@ -199,6 +200,8 @@ ResultsCellRenderer::ResultsCellRenderer(const QSize &size, QWidget *widget)
QString ResultsCellRenderer::columnText(int col, const QVariantMap &data)
{
QString ret;
Application *app = Application::instance();
bool is_relay = app->eventInfo().value("isRelay").toBool();
switch(col) {
case Position: {
bool disq = data.value(QStringLiteral("disqualified")).toBool();
Expand All @@ -208,14 +211,30 @@ QString ResultsCellRenderer::columnText(int col, const QVariantMap &data)
break;
}
case Name: ret = QStringLiteral("{{lastname}} {{firstname}}"); break;
case Registration: ret = QStringLiteral("{{registration}}"); break;
case Registration:
if (is_relay) {
ret = data.value(QStringLiteral("relayname")).toString();
} else { //individual
ret = QStringLiteral("{{registration}}");
}
break;
case Time: {
int sec = data.value(QStringLiteral("timems")).toInt() / 1000;
int sec;
if (is_relay) {
sec = data.value(QStringLiteral("legfinishtimems")).toInt() / 1000;
} else { //individual
sec = data.value(QStringLiteral("timems")).toInt() / 1000;
}
ret = QString("%1.%2").arg(sec / 60).arg(sec % 60, 2, 10, QChar('0'));
return ret;
}
case Status: {
bool disq = data.value(QStringLiteral("disqualified")).toBool();
bool disq;
if (is_relay) {
disq = data.value(QStringLiteral("relaydisqualified")).toBool();
} else {
disq = data.value(QStringLiteral("disqualified")).toBool();
}
return disq? tr("DISQ"): QString();
}
default:
Expand Down
204 changes: 143 additions & 61 deletions quickshow/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,75 +81,157 @@ bool Model::addCategoryToStorage()
return false;
}
Application *app = Application::instance();
bool is_relay = app->eventInfo().value("isRelay").toBool();
int cat_id_to_load = m_categoriesToProceed.takeFirst().toInt();
QVariantMap category_map;
{
if (is_relay) {
qf::core::sql::QueryBuilder qb;
qb.select2("classes", "name")
//.select2("classdefs", "")
.select2("courses", "length, climb")
.from("classes")
.joinRestricted("classes.id", "classdefs.classId", "classdefs.stageId={{stage_id}}")
.join("classdefs.courseId", "courses.id")
.where("classes.id={{class_id}}");
QString qs = qb.toString();
QString qs = "select cd.relaylegcount as leg_count from classdefs as cd where cd.classid = {{class_id}} and cd.stageid = {{stage_id}}";
qfDebug() << "Get leg count for category:" << qs;
qs.replace("{{stage_id}}", QString::number(app->cliOptions()->stage()));
qs.replace("{{class_id}}", QString::number(cat_id_to_load));
if(first_run)
qfInfo() << "classes:" << qs;
qf::core::sql::Query q = app->execSql(qs);
if(q.next()) {
QVariantMap m;
category_map = q.values();
m["type"] = "classInfo";
m["record"] = category_map;
m_storage << m;
q.next();
int leg_count_from_class = q.value("leg_count").toInt();
for (int leg_num = 1; leg_num <= leg_count_from_class; leg_num++) {
QVariantMap category_map;
{
qf::core::sql::QueryBuilder qb;
QString qs = "select c.name || '-' || '{{leg_num}}' as name, 0 as length, 0 as climb from classes as c where c.id = {{class_id}}";
qfInfo() << "Get category:" << qs;
qs.replace("{{stage_id}}", QString::number(app->cliOptions()->stage()));
qs.replace("{{class_id}}", QString::number(cat_id_to_load));
qs.replace("{{leg_num}}", QString::number(leg_num));
if(first_run)
qfInfo() << "classes:" << qs;
qf::core::sql::Query q = app->execSql(qs);
if(q.next()) {
QVariantMap m;
category_map = q.values();
m["type"] = "classInfo";
m["record"] = category_map;
m_storage << m;
}
else {
qfError() << "Entry for classname" << cat_id_to_load << "does not exist !!!";
}
}
{
QString qs;
qf::core::sql::QueryBuilder qb;
if(app->cliOptions()->profile() == QLatin1String("results")) {
qs = "SELECT c.registration, c.lastName, c.firstName, r.*, (finishTimeMs - starttimemin*60*1000) as legFinishTimeMs, "
"relay.disqualified as relaydisqualified, "
"rel.club || ' ' || rel.name as relayname "
"FROM competitors as c join runs as r on r.competitorId = c.id "
"join relays as rel on r.relayid = rel.id "
"join classdefs as cd on cd.classid = rel.classId "
"join (select relayid, bool_or(disqualified) as disqualified from runs r group by relayid) relay on r.relayid = relay.relayid "
"where r.isRunning and r.finishTimeMs>0 and rel.classId = {{class_id}} and r.leg = {{leg_num}} "
"order by r.notCompeting, relaydisqualified, r.finishtimeMs";
if(first_run)
qfInfo() << "results:" << qs;
}
else {
qb.select2("competitors", "registration, lastName, firstName")
//.select("COALESCE(competitors.lastName, '') || ' ' || COALESCE(competitors.firstName, '') AS competitorName")
.select2("runs", "*")
.from("competitors")
.joinRestricted("competitors.id", "runs.competitorId", "runs.stageId={{stage_id}} AND runs.isRunning", "JOIN")
.where("competitors.classId={{class_id}}")
.orderBy("runs.startTimeMs");
qs = qb.toString();
if(first_run)
qfInfo() << "startlist:" << qs;
}
qs.replace("{{stage_id}}", QString::number(app->cliOptions()->stage()));
qs.replace("{{class_id}}", QString::number(cat_id_to_load));
qs.replace("{{leg_num}}", QString::number(leg_num));
qf::core::sql::Query q = app->execSql(qs);
int pos = 0;
while(q.next()) {
QVariantMap m;
//QVariantMap detail_map = app->sqlRecordToMap(rec);
QVariantMap detail_map = q.values();
detail_map["pos"] = ++pos;
m["type"] = app->cliOptions()->profile();
m["record"] = detail_map;
/// pridej k detailu i kategorii, protoze na prvnim miste listu se zobrazuje vzdy zahlavi aktualni kategorie kvuli prehlednosti
//m["category"] = category_map;
m_storage << m;
}
}
}
else {
qfError() << "Entry for classname" << cat_id_to_load << "does not exist !!!";
}
}
{
QString qs;
qf::core::sql::QueryBuilder qb;
if(app->cliOptions()->profile() == QLatin1String("results")) {
qb.select2("competitors", "registration, lastName, firstName")
//.select("COALESCE(competitors.lastName, '') || ' ' || COALESCE(competitors.firstName, '') AS competitorName")
.select2("runs", "*")
.from("competitors")
.joinRestricted("competitors.id", "runs.competitorId", "runs.stageId={{stage_id}} AND runs.isRunning AND runs.finishTimeMs>0", "JOIN")
.where("competitors.classId={{class_id}}")
.orderBy("runs.notCompeting, runs.disqualified, runs.timeMs");
qs = qb.toString();
if(first_run)
qfInfo() << "results:" << qs;
}
else {
qb.select2("competitors", "registration, lastName, firstName")
//.select("COALESCE(competitors.lastName, '') || ' ' || COALESCE(competitors.firstName, '') AS competitorName")
.select2("runs", "*")
.from("competitors")
.joinRestricted("competitors.id", "runs.competitorId", "runs.stageId={{stage_id}} AND runs.isRunning", "JOIN")
.where("competitors.classId={{class_id}}")
.orderBy("runs.startTimeMs");
qs = qb.toString();
} else { //event type 'individual'
QVariantMap category_map;
{
qf::core::sql::QueryBuilder qb;
qb.select2("classes", "name")
//.select2("classdefs", "")
.select2("courses", "length, climb")
.from("classes")
.joinRestricted("classes.id", "classdefs.classId", "classdefs.stageId={{stage_id}}")
.join("classdefs.courseId", "courses.id")
.where("classes.id={{class_id}}");
QString qs = qb.toString();
qs.replace("{{stage_id}}", QString::number(app->cliOptions()->stage()));
qs.replace("{{class_id}}", QString::number(cat_id_to_load));
if(first_run)
qfInfo() << "startlist:" << qs;
qfInfo() << "classes:" << qs;
qf::core::sql::Query q = app->execSql(qs);
if(q.next()) {
QVariantMap m;
category_map = q.values();
m["type"] = "classInfo";
m["record"] = category_map;
m_storage << m;
}
else {
qfError() << "Entry for classname" << cat_id_to_load << "does not exist !!!";
}
}
qs.replace("{{stage_id}}", QString::number(app->cliOptions()->stage()));
qs.replace("{{class_id}}", QString::number(cat_id_to_load));
qf::core::sql::Query q = app->execSql(qs);
int pos = 0;
while(q.next()) {
QVariantMap m;
//QVariantMap detail_map = app->sqlRecordToMap(rec);
QVariantMap detail_map = q.values();
detail_map["pos"] = ++pos;
m["type"] = app->cliOptions()->profile();
m["record"] = detail_map;
/// pridej k detailu i kategorii, protoze na prvnim miste listu se zobrazuje vzdy zahlavi aktualni kategorie kvuli prehlednosti
//m["category"] = category_map;
m_storage << m;
{
QString qs;
qf::core::sql::QueryBuilder qb;
if(app->cliOptions()->profile() == QLatin1String("results")) {
qfInfo() << "vytazeni zavodniku pro kategorii" << qs;
qb.select2("competitors", "registration, lastName, firstName")
//.select("COALESCE(competitors.lastName, '') || ' ' || COALESCE(competitors.firstName, '') AS competitorName")
.select2("runs", "*")
.from("competitors")
.joinRestricted("competitors.id", "runs.competitorId", "runs.stageId={{stage_id}} AND runs.isRunning AND runs.finishTimeMs>0", "JOIN")
.where("competitors.classId={{class_id}}")
.orderBy("runs.notCompeting, runs.disqualified, runs.timeMs");
qs = qb.toString();
if(first_run)
qfInfo() << "results:" << qs;
}
else {
qb.select2("competitors", "registration, lastName, firstName")
//.select("COALESCE(competitors.lastName, '') || ' ' || COALESCE(competitors.firstName, '') AS competitorName")
.select2("runs", "*")
.from("competitors")
.joinRestricted("competitors.id", "runs.competitorId", "runs.stageId={{stage_id}} AND runs.isRunning", "JOIN")
.where("competitors.classId={{class_id}}")
.orderBy("runs.startTimeMs");
qs = qb.toString();
if(first_run)
qfInfo() << "startlist:" << qs;
}
qs.replace("{{stage_id}}", QString::number(app->cliOptions()->stage()));
qs.replace("{{class_id}}", QString::number(cat_id_to_load));
qf::core::sql::Query q = app->execSql(qs);
int pos = 0;
while(q.next()) {
QVariantMap m;
//QVariantMap detail_map = app->sqlRecordToMap(rec);
QVariantMap detail_map = q.values();
detail_map["pos"] = ++pos;
m["type"] = app->cliOptions()->profile();
m["record"] = detail_map;
/// pridej k detailu i kategorii, protoze na prvnim miste listu se zobrazuje vzdy zahlavi aktualni kategorie kvuli prehlednosti
//m["category"] = category_map;
m_storage << m;
}
}
}
first_run = false;
Expand Down

0 comments on commit c6d1db9

Please sign in to comment.