From: Sakari Poussa Date: Sun, 29 Nov 2009 18:13:00 +0000 (+0200) Subject: Statistics - final bits including all stats and error handling X-Git-Url: https://vcs.maemo.org/git/?p=scorecard;a=commitdiff_plain;h=74f6fa62b271a126a4488a2b20c0033a05288f0f Statistics - final bits including all stats and error handling --- diff --git a/data/score.xml b/data/score.xml index 63b0c8d..c7f64df 100644 --- a/data/score.xml +++ b/data/score.xml @@ -1,682 +1,682 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main-window.cpp b/src/main-window.cpp index db65fc0..02080e3 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -159,14 +159,6 @@ void MainWindow::createActions() editCourseAct = new QAction(tr("Edit Course"), this); connect(editCourseAct, SIGNAL(triggered()), this, SLOT(editCourse())); -#if 0 - viewScoreAct = new QAction(tr("&View Scores"), this); - connect(viewScoreAct, SIGNAL(triggered()), this, SLOT(viewScore())); - - viewCourseAct = new QAction(tr("&View Courses"), this); - connect(viewCourseAct, SIGNAL(triggered()), this, SLOT(viewCourse())); -#endif - statAct = new QAction(tr("Statistics"), this); connect(statAct, SIGNAL(triggered()), this, SLOT(viewStatistics())); @@ -185,12 +177,12 @@ void MainWindow::createActions() void MainWindow::createMenus() { +#ifdef Q_WS_HILDON menu = menuBar()->addMenu(""); -#if 0 - menu->addAction(viewScoreAct); - menu->addAction(viewCourseAct); - menu->addAction(viewStatisticAct); +#else + menu = menuBar()->addMenu("Menu"); #endif + menu->addAction(newScoreAct); menu->addAction(newCourseAct); menu->addAction(editScoreAct); diff --git a/src/stat-model.cpp b/src/stat-model.cpp index 8fe6b36..f2396c7 100644 --- a/src/stat-model.cpp +++ b/src/stat-model.cpp @@ -25,6 +25,9 @@ QVariant StatModel::data(const QModelIndex & index, int role) const int row = index.row(); int col = index.column(); + if (col >= stat.size()) + return QVariant(); + // // ALIGNMENT // @@ -46,10 +49,13 @@ QVariant StatModel::data(const QModelIndex & index, int role) const case ROW_MAX: return stat.at(col)->max(); case ROW_BIRDIE: + return stat.at(col)->birdies(); case ROW_PAR: + return stat.at(col)->pars(); case ROW_BOGEY: + return stat.at(col)->bogeys(); case ROW_MORE: - return QVariant(); + return stat.at(col)->more(); } } return QVariant(); @@ -63,7 +69,10 @@ QVariant StatModel::headerData(int section, Qt::Orientation orientation, int rol if (orientation == Qt::Horizontal) { // TODO: check when no or less data than cols - return stat.at(section)->year(); + // HERE CRASH + + if (section < stat.size()) + return stat.at(section)->year(); } if (orientation == Qt::Vertical) { @@ -83,34 +92,45 @@ QVariant StatModel::headerData(int section, Qt::Orientation orientation, int rol case ROW_BOGEY: return QString("Bogeys"); case ROW_MORE: - return QString("More"); + return QString("Double+"); } } return QVariant(); } +// TODO: dup code from table-model.cpp +Course *StatModel::findCourse(const QString &clubName, + const QString &courseName) +{ + QListIterator i(clubList); + Club *c; + + while (i.hasNext()) { + c = i.next(); + if (c->getName() == clubName) { + return c->getCourse(courseName); + } + } + return 0; +} + void StatModel::update(void) { QListIterator iScore(scoreList); QMultiMap yearMap; - QStringList yearList; // Create multi map with years as keys, scores as values - // Create list of years while (iScore.hasNext()) { Score *score = iScore.next(); QString year = score->getDate().split("-").at(0); yearMap.insert(year, score); - yearList << year; } - // Create uniq list of years - QSet yearSet = QSet::fromList(yearList); - - QSetIterator iYear(yearSet); + QList yearList = yearMap.uniqueKeys(); // For each year collect the statistics + QListIterator iYear(yearList); while (iYear.hasNext()) { QString year = iYear.next(); @@ -126,6 +146,10 @@ void StatModel::update(void) int sum = 0; int min = 200; int max = 0; + int pars = 0; + int birdies = 0; + int bogeys = 0; + int more = 0; while (iScoresPerYear.hasNext()) { Score *s = iScoresPerYear.next(); int tot = s->getTotal(Total).toInt(); @@ -136,9 +160,29 @@ void StatModel::update(void) if (tot < min) min = tot; + + Course *c = findCourse(s->getClubName(), s->getCourseName()); + + for (int i = 0; i < 18; i++) { + int par = c->getPar(i).toInt(); + int shots = s->getScore(i).toInt(); + + if (shots == (par - 1)) + birdies++; + else if (shots == par) + pars++; + else if (shots == (par + 1)) + bogeys++; + else if (shots >= (par + 2)) + more++; + } } + item->setBirdies(birdies); + item->setPars(pars); + item->setBogeys(bogeys); + item->setMore(more); + int avg = sum / scoresPerYear.count(); - item->setAverage(avg); item->setMin(min); item->setMax(max); diff --git a/src/stat-model.h b/src/stat-model.h index d6a77a6..445b1e7 100644 --- a/src/stat-model.h +++ b/src/stat-model.h @@ -22,6 +22,18 @@ class StatItem void setMax(int n) { m_max = n; } int max() { return m_max; } + void setBirdies(int n) { m_birdies = n; } + int birdies() { return m_birdies; } + + void setPars(int n) { m_pars = n; } + int pars() { return m_pars; } + + void setBogeys(int n) { m_bogeys = n; } + int bogeys() { return m_bogeys; } + + void setMore(int n) { m_more = n; } + int more() { return m_more; } + private: int m_year; @@ -49,6 +61,9 @@ public: private: + + Course *findCourse(const QString &clubName, + const QString &courseName); enum { ROWS = 8, COLS = 4 }; enum { ROW_ROUNDS = 0,