@@ -22,8 +22,8 | |||
|
22 | 22 | |
|
23 | 23 | #include <QDebug> |
|
24 | 24 | |
|
25 |
BoxDataReader::BoxDataReader(QIODevice * |
|
|
26 |
QTextStream( |
|
|
25 | BoxDataReader::BoxDataReader(QIODevice *device) : | |
|
26 | QTextStream(device) | |
|
27 | 27 | { |
|
28 | 28 | } |
|
29 | 29 | |
@@ -34,26 +34,39 QBoxSet* BoxDataReader::readBox() | |||
|
34 | 34 | return 0; |
|
35 | 35 | |
|
36 | 36 | QStringList strList = line.split(" ", QString::SkipEmptyParts); |
|
37 | QList<qreal> sortedList; | |
|
37 | sortedList.clear(); | |
|
38 | 38 | foreach (QString str, strList) { |
|
39 | 39 | sortedList.append(str.toDouble()); |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | qSort(sortedList.begin(), sortedList.end()); |
|
43 | qDebug() << "sortedList = " << sortedList; | |
|
44 | 43 | |
|
45 | 44 | int count = sortedList.count(); |
|
46 | int median = (int)(count / 2); | |
|
47 | int lowerQ = (int)(median / 2); | |
|
48 | int upperQ = median + lowerQ + 1; | |
|
49 | 45 | |
|
50 | 46 | QBoxSet *box = new QBoxSet(); |
|
51 |
box->setLowerExtreme(sortedList. |
|
|
52 | box->setLowerQuartile(sortedList.at(lowerQ)); | |
|
53 | box->setMedian(sortedList.at(median)); | |
|
54 | box->setUpperQuartile(sortedList.at(upperQ)); | |
|
47 | box->setLowerExtreme(sortedList.first()); | |
|
55 | 48 | box->setUpperExtreme(sortedList.last()); |
|
49 | box->setMedian(findMedian(0, count)); | |
|
50 | box->setLowerQuartile(findMedian(0, count / 2)); | |
|
51 | if (count % 2) | |
|
52 | box->setUpperQuartile(findMedian(count / 2 + 1, count)); | |
|
53 | else // even amount of numbers | |
|
54 | box->setUpperQuartile(findMedian(count / 2, count)); | |
|
55 | ||
|
56 | qDebug() << "Box = " << box->lowerExtreme() << ", " << box->lowerQuartile() << ", " << | |
|
57 | box->median() << ", " << box->upperQuartile() << ", " << box->upperExtreme(); | |
|
56 | 58 | |
|
57 | 59 | return box; |
|
58 | 60 | } |
|
59 | 61 | |
|
62 | qreal BoxDataReader::findMedian(int begin, int end) | |
|
63 | { | |
|
64 | int count = end - begin; | |
|
65 | if (count % 2 ) { | |
|
66 | return sortedList.at((int) (count/2) + begin); | |
|
67 | } else { | |
|
68 | qreal right = sortedList.at(count / 2 + begin); | |
|
69 | qreal left = sortedList.at(count / 2 - 1 + begin); | |
|
70 | return (right + left) / 2.0; | |
|
71 | } | |
|
72 | } |
@@ -29,13 +29,14 QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
29 | 29 | class BoxDataReader : public QTextStream |
|
30 | 30 | { |
|
31 | 31 | public: |
|
32 |
explicit BoxDataReader(QIODevice * |
|
|
32 | explicit BoxDataReader(QIODevice *device); | |
|
33 | 33 | QBoxSet* readBox(); |
|
34 | 34 | |
|
35 | 35 | protected: |
|
36 | 36 | qreal findMedian(int begin, int end); |
|
37 | 37 | |
|
38 | 38 | private: |
|
39 | QList<qreal> sortedList; | |
|
39 | 40 | }; |
|
40 | 41 | |
|
41 | 42 | #endif // BOXDATAREADER_H |
@@ -25,12 +25,6 | |||
|
25 | 25 | #include <QBoxSet> |
|
26 | 26 | #include <QLegend> |
|
27 | 27 | #include <QBarCategoryAxis> |
|
28 | #include <QLineSeries> | |
|
29 | #include <QScatterSeries> | |
|
30 | #include <QTextStream> | |
|
31 | ||
|
32 | #include <QBrush> | |
|
33 | #include <QColor> | |
|
34 | 28 | |
|
35 | 29 | #include "boxdatareader.h" |
|
36 | 30 | |
@@ -60,34 +54,6 int main(int argc, char *argv[]) | |||
|
60 | 54 | series->append(set); |
|
61 | 55 | } |
|
62 | 56 | |
|
63 | // QTextStream stream(&stockData); | |
|
64 | // while (!stream.atEnd()) { | |
|
65 | // QString line = stream.readLine(); | |
|
66 | // if (line.startsWith("#")) | |
|
67 | // continue; | |
|
68 | // QStringList strList = line.split(" ", QString::SkipEmptyParts); | |
|
69 | // QList<qreal> realList; | |
|
70 | // foreach (QString str, strList) { | |
|
71 | // realList.append(str.toDouble()); | |
|
72 | // } | |
|
73 | ||
|
74 | // qSort(realList.begin(), realList.end()); | |
|
75 | ||
|
76 | // int count = realList.count(); | |
|
77 | // int median = (int)(count / 2); | |
|
78 | // int lowerQ = (int)(median / 2); | |
|
79 | // int upperQ = median + lowerQ + 1; | |
|
80 | // QBoxSet *set = new QBoxSet(); | |
|
81 | ||
|
82 | // set->setLowerExtreme(realList.at(0)); | |
|
83 | // set->setLowerQuartile(realList.at(lowerQ)); | |
|
84 | // set->setMedian(realList.at(median)); | |
|
85 | // set->setUpperQuartile(realList.at(upperQ)); | |
|
86 | // set->setUpperExtreme(realList.last()); | |
|
87 | ||
|
88 | // series->append(set); | |
|
89 | // } | |
|
90 | ||
|
91 | 57 | //![3] |
|
92 | 58 | QChart *chart = new QChart(); |
|
93 | 59 | chart->addSeries(series); |
General Comments 0
You need to be logged in to leave comments.
Login now