@@ -22,8 +22,8 | |||||
22 |
|
22 | |||
23 | #include <QDebug> |
|
23 | #include <QDebug> | |
24 |
|
24 | |||
25 |
BoxDataReader::BoxDataReader(QIODevice * |
|
25 | BoxDataReader::BoxDataReader(QIODevice *device) : | |
26 |
QTextStream( |
|
26 | QTextStream(device) | |
27 | { |
|
27 | { | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
@@ -34,26 +34,39 QBoxSet* BoxDataReader::readBox() | |||||
34 | return 0; |
|
34 | return 0; | |
35 |
|
35 | |||
36 | QStringList strList = line.split(" ", QString::SkipEmptyParts); |
|
36 | QStringList strList = line.split(" ", QString::SkipEmptyParts); | |
37 | QList<qreal> sortedList; |
|
37 | sortedList.clear(); | |
38 | foreach (QString str, strList) { |
|
38 | foreach (QString str, strList) { | |
39 | sortedList.append(str.toDouble()); |
|
39 | sortedList.append(str.toDouble()); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | qSort(sortedList.begin(), sortedList.end()); |
|
42 | qSort(sortedList.begin(), sortedList.end()); | |
43 | qDebug() << "sortedList = " << sortedList; |
|
|||
44 |
|
43 | |||
45 | int count = sortedList.count(); |
|
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 | QBoxSet *box = new QBoxSet(); |
|
46 | QBoxSet *box = new QBoxSet(); | |
51 |
box->setLowerExtreme(sortedList. |
|
47 | box->setLowerExtreme(sortedList.first()); | |
52 | box->setLowerQuartile(sortedList.at(lowerQ)); |
|
|||
53 | box->setMedian(sortedList.at(median)); |
|
|||
54 | box->setUpperQuartile(sortedList.at(upperQ)); |
|
|||
55 | box->setUpperExtreme(sortedList.last()); |
|
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 | return box; |
|
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 | class BoxDataReader : public QTextStream |
|
29 | class BoxDataReader : public QTextStream | |
30 | { |
|
30 | { | |
31 | public: |
|
31 | public: | |
32 |
explicit BoxDataReader(QIODevice * |
|
32 | explicit BoxDataReader(QIODevice *device); | |
33 | QBoxSet* readBox(); |
|
33 | QBoxSet* readBox(); | |
34 |
|
34 | |||
35 | protected: |
|
35 | protected: | |
36 | qreal findMedian(int begin, int end); |
|
36 | qreal findMedian(int begin, int end); | |
37 |
|
37 | |||
38 | private: |
|
38 | private: | |
|
39 | QList<qreal> sortedList; | |||
39 | }; |
|
40 | }; | |
40 |
|
41 | |||
41 | #endif // BOXDATAREADER_H |
|
42 | #endif // BOXDATAREADER_H |
@@ -25,12 +25,6 | |||||
25 | #include <QBoxSet> |
|
25 | #include <QBoxSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 | #include <QBarCategoryAxis> |
|
27 | #include <QBarCategoryAxis> | |
28 | #include <QLineSeries> |
|
|||
29 | #include <QScatterSeries> |
|
|||
30 | #include <QTextStream> |
|
|||
31 |
|
||||
32 | #include <QBrush> |
|
|||
33 | #include <QColor> |
|
|||
34 |
|
28 | |||
35 | #include "boxdatareader.h" |
|
29 | #include "boxdatareader.h" | |
36 |
|
30 | |||
@@ -60,34 +54,6 int main(int argc, char *argv[]) | |||||
60 | series->append(set); |
|
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 | //![3] |
|
57 | //![3] | |
92 | QChart *chart = new QChart(); |
|
58 | QChart *chart = new QChart(); | |
93 | chart->addSeries(series); |
|
59 | chart->addSeries(series); |
@@ -1,3 +1,6 | |||||
|
1 | 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 | |||
|
2 | #0 1 2 3 4 5 6 7 8 9 | |||
|
3 | 4.3 5.1 3.9 4.5 4.4 4.9 5.0 4.7 4.1 4.6 4.4 4.3 4.8 4.4 4.2 4.5 4.4 | |||
1 | 1.0 1.2 2.0 2.4 2.5 3.0 3.5 3.7 4.0 4.7 5.0 |
|
4 | 1.0 1.2 2.0 2.4 2.5 3.0 3.5 3.7 4.0 4.7 5.0 | |
2 | 4.6 4.7 5.2 7.3 8.4 8.8 9.1 8.3 7.4 6.4 5.3 |
|
5 | 4.6 4.7 5.2 7.3 8.4 8.8 9.1 8.3 7.4 6.4 5.3 | |
3 | 3.5 7.2 5.4 6.3 7.4 8.3 8.8 3.3 5.4 5.7 3.9 |
|
6 | 3.5 7.2 5.4 6.3 7.4 8.3 8.8 3.3 5.4 5.7 3.9 |
General Comments 0
You need to be logged in to leave comments.
Login now