ClassDocument::ClassDocument(QObject *parent) : Super(parent) { qf::core::sql::QueryBuilder qb; qb.select2("classes", "*") .from("classes") .where("classes.id={{ID}}"); setQueryBuilder(qb); }
EventStatisticsModel::EventStatisticsModel(QObject *parent) : Super(parent) { addColumn("classes.name", tr("Class")); addColumn("classdefs.mapCount", tr("Maps")); addColumn("freeMapCount", tr("Free maps")); addColumn("runnersCount", tr("Runners")); addColumn("startFirstMs", tr("Start first")).setCastType(qMetaTypeId<quickevent::og::TimeMs>()); addColumn("startLastMs", tr("Start last")).setCastType(qMetaTypeId<quickevent::og::TimeMs>()); addColumn("time1Ms", tr("Time 1")).setToolTip(tr("Finish time of first runner in current class")).setCastType(qMetaTypeId<quickevent::og::TimeMs>()); addColumn("time3Ms", tr("Time 3")).setToolTip(tr("Finish time of third runner in current class")).setCastType(qMetaTypeId<quickevent::og::TimeMs>()); addColumn("runnersFinished", tr("Finished")); addColumn("runnersNotFinished", tr("Not finished")); addColumn("resultsNotPrinted", tr("New results")).setToolTip(tr("Number of finished competitors not printed in results.")); { qf::core::sql::QueryBuilder qb_runners_count; qb_runners_count.select("COUNT(runs.id)") .from("runs").joinRestricted("runs.competitorId", "competitors.id", "runs.stageId={{stage_id}} AND competitors.classId=classes.id", qf::core::sql::QueryBuilder::INNER_JOIN); qf::core::sql::QueryBuilder qb_runners_finished; qb_runners_finished.select("COUNT(runs.id)") .from("runs").joinRestricted("runs.competitorId", "competitors.id", "runs.stageId={{stage_id}} AND competitors.classId=classes.id", qf::core::sql::QueryBuilder::INNER_JOIN) .where("runs.finishTimeMs > 0 OR runs.disqualified"); qf::core::sql::QueryBuilder qb_runners_start_first; qb_runners_start_first.select("MIN(runs.startTimeMs)") .from("runs").joinRestricted("runs.competitorId", "competitors.id", "runs.stageId={{stage_id}} AND competitors.classId=classes.id", qf::core::sql::QueryBuilder::INNER_JOIN) .where("runs.startTimeMs IS NOT NULL"); qf::core::sql::QueryBuilder qb_runners_start_last; qb_runners_start_last.select("MAX(runs.startTimeMs)") .from("runs").joinRestricted("runs.competitorId", "competitors.id", "runs.stageId={{stage_id}} AND competitors.classId=classes.id", qf::core::sql::QueryBuilder::INNER_JOIN) .where("runs.startTimeMs IS NOT NULL"); qf::core::sql::QueryBuilder qb_first_time; { qf::core::sql::QueryBuilder qb; qb.select("runs.timeMs") .from("runs").joinRestricted("runs.competitorId", "competitors.id", "runs.stageId={{stage_id}} AND competitors.classId=classes.id AND runs.timeMs>0 AND NOT runs.disqualified", qf::core::sql::QueryBuilder::INNER_JOIN) .orderBy("runs.timeMs") .limit(1) .as("results1"); qb_first_time.select("MAX(timeMs)") .from(qb.toString()); } qf::core::sql::QueryBuilder qb_third_time; { qf::core::sql::QueryBuilder qb; qb.select("runs.timeMs") .from("runs").joinRestricted("runs.competitorId", "competitors.id", "runs.stageId={{stage_id}} AND competitors.classId=classes.id AND runs.timeMs>0 AND NOT runs.disqualified", qf::core::sql::QueryBuilder::INNER_JOIN) .orderBy("runs.timeMs") .limit(3) .as("results3"); qb_third_time.select("MAX(timeMs)")//.select("COUNT(timeMs) AS count3") .from(qb.toString()); } qf::core::sql::QueryBuilder qb; qb.select2("classes", "*") .select2("classdefs", "*") .select("(" + qb_runners_count.toString() + ") AS runnersCount") .select("(" + qb_runners_finished.toString() + ") AS runnersFinished") .select("(" + qb_runners_start_first.toString() + ") AS startFirstMs") .select("(" + qb_runners_start_last.toString() + ") AS startLastMs") .select("(" + qb_first_time.toString() + ") AS time1Ms") .select("(" + qb_third_time.toString() + ") AS time3Ms") .select("0 AS freeMapCount") .select("0 AS runnersNotFinished") .select("0 AS resultsNotPrinted") .from("classes") .joinRestricted("classes.id", "classdefs.classId", "classdefs.stageId={{stage_id}}") //.join("classes.id", "competitors.classId") //.joinRestricted("competitors.id", "runs.competitorId", "runs.stageId={{stage_id}}") //.groupBy("classes.id") .orderBy("classes.name"); setQueryBuilder(qb); } }