1 /***************************************************************************
2 * ktouchtrainingsession.cpp *
3 * ------------------------- *
4 * Copyright (C) 2003 by Andreas Nicolai *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
12 #ifndef KTOUCHTRAININGSESSION_H
13 #define KTOUCHTRAININGSESSION_H
15 #include <set> // I'm using std::set here because QT is missing this container type
16 #include <list> // std::list because it has a fast sort() member function
17 #include "ktouchcharstats.h"
21 /** Contains the data of one training session.
22 * The data is collection in sessions to simplify the generation of statistics. In each session
23 * the average typing speed, the number of characters (correct and total) and all missed characters
24 * will be stored. Missed characters are stored when a user does not type the required character but
25 * something else. This allows evaluation of the most often missed char to focus on.
27 class KTouchTrainingSession
{
29 /// Default constructor.
30 KTouchTrainingSession() : m_totalChars(0), m_correctChars(0), m_words(0), m_elapsedTime(0), m_wordBuffer("") {};
31 /// Constructor which creates a training session from a string (see asString() ).
32 KTouchTrainingSession(QString str
);
33 /// Resets the session to the initial state
35 /// Returns the session data as string use for writing the current session stats (session management).
36 QString
asString() const;
37 /// Updates the status variables when a correct key was pressed.
38 void addCorrectChar(QChar ch
);
39 /// Updates the status variables when a wrong key was pressed.
40 void addWrongChar(QChar missedChar
);
41 /// Returns the typing accuracy or "correctness" (0..1).
42 double correctness() const { return (m_totalChars
==0) ? 1.0 : static_cast<double>(m_correctChars
)/m_totalChars
; };
43 /// Returns the average typing speed in chars per minute.
44 double charSpeed() const { return (m_elapsedTime
==0) ? 0 : 60000.0*static_cast<double>(m_correctChars
)/m_elapsedTime
; };
45 /// Returns the average typing speed in words per minute.
46 double wordSpeed() const { return (m_elapsedTime
==0) ? 0 : 60000.0*static_cast<double>(m_words
)/m_elapsedTime
; };
47 /// Returns a value list of the characters stats sorted after the worst miss/hit ratio.
48 std::list
<KTouchCharStats
> sortedCharStats() const;
50 unsigned int m_totalChars
; ///< The total number of chars typed this session.
51 unsigned int m_correctChars
; ///< The total number of correctly typed chars.
52 unsigned int m_words
; ///< The number of typed words.
53 unsigned int m_elapsedTime
; ///< Training time in this session in seconds.
54 std::set
<KTouchCharStats
> m_charStats
; ///< Holds the characters counters
57 QString m_wordBuffer
; ///< Used for the word count.
60 #endif // KTOUCHTRAININGSESSION_H