simplyfied test result evaluation

This commit is contained in:
mandlm 2018-06-14 19:19:53 +02:00
parent dbf29d194b
commit 017ff01a83
5 changed files with 116 additions and 121 deletions

View File

@ -13,6 +13,7 @@ qt5_wrap_ui(GENUS_UI
add_library(${PROJECT_NAME} add_library(${PROJECT_NAME}
ResultWidget.cpp ResultWidget.cpp
ResultModel.cpp ResultModel.cpp
PRMap.cpp
${GENUS_UI} ${GENUS_UI}
) )

View File

@ -0,0 +1,41 @@
#include "PRMap.h"
unsigned int PRMap::lookup(const Age &age, const unsigned int &points)
{
if (points >= m_PRs.size())
{
return 0;
}
auto ageIndex = [&]() -> size_t {
if (m_ages.empty())
{
return 0;
}
if (age < m_ages.front())
{
return 0;
}
if (m_ages.back() < age)
{
return m_ages.size() - 1;
}
for (size_t index = 1; index < m_ages.size(); ++index)
{
if (age < m_ages.at(index))
{
return index - 1;
}
}
}();
if (ageIndex >= m_PRs.at(points).size())
{
return 0;
}
return m_PRs.at(points).at(ageIndex);
}

View File

@ -0,0 +1,14 @@
#pragma once
#include "../Age.h"
#include <vector>
class PRMap
{
protected:
std::vector<Age> m_ages;
std::vector<std::vector<unsigned int>> m_PRs;
public:
unsigned int lookup(const Age &age, const unsigned int &points);
};

View File

@ -21,71 +21,49 @@ int ResultModel::columnCount(const QModelIndex &parent) const
QVariant ResultModel::data(const QModelIndex &index, int role) const QVariant ResultModel::data(const QModelIndex &index, int role) const
{ {
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole && index.column() < m_results.size())
{ {
switch (index.row()) switch (index.row())
{ {
case 0: case 0:
if (index.column() < m_results.size()) {
auto points = m_results[index.column()].points();
if (points != 0)
{ {
size_t points = m_results[index.column()].points(); return static_cast<uint>(points);
if (points != 0)
{
return static_cast<uint>(points);
}
} }
break; break;
}
case 1: case 1:
switch (index.column()) {
auto pr = m_results[index.column()].pr();
if (pr >= 84)
{ {
case 8: return static_cast<uint>(pr);
{
auto pR = getPluralPR();
if (pR >= 84)
{
return pR;
}
}
break;
default:
break;
} }
break; break;
}
case 2: case 2:
switch (index.column()) {
auto pr = m_results[index.column()].pr();
if (pr < 84 && pr > 16)
{ {
case 8: return static_cast<uint>(pr);
{
auto pR = getPluralPR();
if (pR < 84 && pR > 16)
{
return pR;
}
}
break;
default:
break;
} }
break; break;
}
case 3: case 3:
switch (index.column()) {
auto pr = m_results[index.column()].pr();
if (pr <= 16)
{ {
case 8: return static_cast<uint>(pr);
{
auto pR = getPluralPR();
if (pR <= 16)
{
return pR;
}
}
break;
default:
break;
} }
break; break;
}
default: default:
break; break;
} };
return "-"; return "-";
} }
@ -140,17 +118,9 @@ void ResultModel::setPluralResult(size_t points)
{ {
if (m_results[8].points() != points) if (m_results[8].points() != points)
{ {
m_results[8] = points; m_results[8].setPoints(points);
m_results[8].setPR(PluralPR().lookup(m_age, points));
emit dataChanged(index(0, 8), index(4, 8)); emit dataChanged(index(0, 8), index(4, 8));
} }
} }
unsigned int ResultModel::getPluralPoints() const
{
return m_results[8].points();
}
unsigned int ResultModel::getPluralPR() const
{
return PluralPR().lookup(m_age, getPluralPoints());
}

View File

@ -1,72 +1,35 @@
#pragma once #pragma once
#include "../Age.h" #include "../Age.h"
#include <vector> #include "PRMap.h"
#include <QAbstractTableModel> #include <QAbstractTableModel>
class PluralPR class PluralPR : public PRMap
{ {
// clang-format off
const std::vector<Age> m_ages = {
{ 4, 0 },
{ 4, 6 },
{ 5, 6 },
{ 9, 0 }
};
const std::vector<std::vector<unsigned int>> m_PRs = {
{ 0, 0, 0 },
{ 0, 1, 0 },
{ 0, 1, 0 },
{ 1, 1, 0 },
{ 7, 2, 1 },
{ 10, 4, 1},
{ 26, 10, 2 },
{ 57, 25, 7 },
{ 79, 56, 27 },
{ 100, 100, 100 }
};
// clang-format on
public: public:
unsigned int lookup(const Age &age, const unsigned int &points) PluralPR()
{ {
if (points >= m_PRs.size()) // clang-format off
{ m_ages = {
return 0; { 4, 0 },
} { 4, 6 },
{ 5, 6 },
{ 9, 0 }
};
auto ageIndex = [&]() -> size_t { m_PRs = {
if (m_ages.empty()) { 0, 0, 0 },
{ { 0, 1, 0 },
return 0; { 0, 1, 0 },
} { 1, 1, 0 },
{ 7, 2, 1 },
if (age < m_ages.front()) { 10, 4, 1},
{ { 26, 10, 2 },
return 0; { 57, 25, 7 },
} { 79, 56, 27 },
{ 100, 100, 100 }
if (m_ages.back() < age) };
{ // clang-format on
return m_ages.size() - 1;
}
for (size_t index = 1; index < m_ages.size(); ++index)
{
if (age < m_ages.at(index))
{
return index - 1;
}
}
}();
if (ageIndex >= m_PRs.at(points).size())
{
return 0;
}
return m_PRs.at(points).at(ageIndex);
} }
}; };
@ -74,20 +37,25 @@ class TestResult
{ {
private: private:
QString m_name; QString m_name;
size_t m_points; size_t m_points = 0;
size_t m_pr = 0;
public: public:
TestResult(const char *name) TestResult(const char *name)
: m_name(name) : m_name(name)
, m_points(0)
{ {
} }
void operator=(const size_t &points) void setPoints(const size_t &points)
{ {
m_points = points; m_points = points;
} }
void setPR(const unsigned int &pr)
{
m_pr = pr;
}
const QString &name() const const QString &name() const
{ {
return m_name; return m_name;
@ -97,6 +65,11 @@ public:
{ {
return m_points; return m_points;
} }
const size_t pr() const
{
return m_pr;
}
}; };
class ResultModel : public QAbstractTableModel class ResultModel : public QAbstractTableModel
@ -121,8 +94,4 @@ public:
void setAge(const Age &age); void setAge(const Age &age);
void setPluralResult(size_t points); void setPluralResult(size_t points);
private:
unsigned int getPluralPoints() const;
unsigned int getPluralPR() const;
}; };