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())
{ {
size_t points = m_results[index.column()].points(); auto points = m_results[index.column()].points();
if (points != 0) if (points != 0)
{ {
return static_cast<uint>(points); return static_cast<uint>(points);
} }
}
break; break;
}
case 1: case 1:
switch (index.column())
{ {
case 8: auto pr = m_results[index.column()].pr();
if (pr >= 84)
{ {
auto pR = getPluralPR(); return static_cast<uint>(pr);
if (pR >= 84)
{
return pR;
}
} }
break; break;
default:
break;
} }
break;
case 2: case 2:
switch (index.column())
{ {
case 8: auto pr = m_results[index.column()].pr();
if (pr < 84 && pr > 16)
{ {
auto pR = getPluralPR(); return static_cast<uint>(pr);
if (pR < 84 && pR > 16)
{
return pR;
}
} }
break; break;
default:
break;
} }
break;
case 3: case 3:
switch (index.column())
{ {
case 8: auto pr = m_results[index.column()].pr();
if (pr <= 16)
{ {
auto pR = getPluralPR(); return static_cast<uint>(pr);
if (pR <= 16)
{
return pR;
}
} }
break; break;
}
default: default:
break; break;
} };
break;
default:
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,20 +1,23 @@
#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
{ {
public:
PluralPR()
{
// clang-format off // clang-format off
const std::vector<Age> m_ages = { m_ages = {
{ 4, 0 }, { 4, 0 },
{ 4, 6 }, { 4, 6 },
{ 5, 6 }, { 5, 6 },
{ 9, 0 } { 9, 0 }
}; };
const std::vector<std::vector<unsigned int>> m_PRs = { m_PRs = {
{ 0, 0, 0 }, { 0, 0, 0 },
{ 0, 1, 0 }, { 0, 1, 0 },
{ 0, 1, 0 }, { 0, 1, 0 },
@ -27,46 +30,6 @@ class PluralPR
{ 100, 100, 100 } { 100, 100, 100 }
}; };
// clang-format on // clang-format on
public:
unsigned int 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);
} }
}; };
@ -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;
}; };