Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved all existing settings into a "Analysis" tab. Added a new "Parse…

…r" tab which allows the user to set the Episodes discretizer settings file.
  • Loading branch information...
commit de9c048b79bbb0af986f16cfcbbfbcecb19fd89e 1 parent 882e3ef
Wim Leers authored June 29, 2011
9  code/UI/MainWindow.cpp
@@ -353,20 +353,21 @@ void MainWindow::initLogic() {
353 353
     qRegisterMetaType<Time>("Time");
354 354
     Analytics::registerBasicMetaTypes();
355 355
 
  356
+    QSettings settings;
356 357
     QString basePath = QCoreApplication::applicationDirPath();
  358
+    QString defaultValue = basePath + "/config/EpisodesSpeeds.csv";
  359
+    QString episodeDiscretizerCSV = settings.value("parser/episodeDiscretizerCSVFile", defaultValue).toString();
  360
+
357 361
     EpisodesParser::Parser::initParserHelpers(basePath + "/config/browscap.csv",
358 362
                                               basePath + "/config/browscap-index.db",
359 363
                                               basePath + "/config/GeoIPCity.dat",
360 364
                                               basePath + "/config/GeoIPASNum.dat",
361  
-                                              basePath + "/config/EpisodesSpeeds.csv"
  365
+                                              episodeDiscretizerCSV
362 366
                                               );
363 367
 
364 368
     // Instantiate the EpisodesParser and the Analytics. Then connect them.
365 369
     this->parser = new EpisodesParser::Parser();
366 370
 
367  
-    // TODO: when these parameters have been figured out, they should be the defaults
368  
-    // and therefor they should be moved to the Analyst constructor.
369  
-    QSettings settings;
370 371
     double minSupport = settings.value("analyst/minimumSupport", 0.05).toDouble();
371 372
     double minPatternTreeSupport = settings.value("analyst/minimumPatternTreeSupport", 0.04).toDouble();
372 373
     double minConfidence = settings.value("analyst/minimumConfidence", 0.2).toDouble();
169  code/UI/SettingsDialog.cpp
@@ -3,7 +3,102 @@
3 3
 SettingsDialog::SettingsDialog(QWidget * parent) :
4 4
     QDialog(parent)
5 5
 {
  6
+    QTabWidget * mainWidget = new QTabWidget(this);
  7
+
  8
+    mainWidget->addTab(this->createAnalystTab(), tr("Analysis"));
  9
+    mainWidget->addTab(this->createParserTab(), tr("Parser"));
  10
+
  11
+    // Buttons.
  12
+    QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
  13
+    buttonBox->setOrientation(Qt::Horizontal);
  14
+    buttonBox->addButton(QDialogButtonBox::RestoreDefaults);
  15
+    buttonBox->addButton(QDialogButtonBox::Cancel);
  16
+    buttonBox->addButton(QDialogButtonBox::Save);
  17
+    buttonBox->button(QDialogButtonBox::RestoreDefaults)->setAutoDefault(false);
  18
+
  19
+    // Layout.
  20
+    QVBoxLayout * mainLayout = new QVBoxLayout();
  21
+    this->setLayout(mainLayout);
  22
+    mainLayout->addWidget(mainWidget);
  23
+    mainLayout->addWidget(buttonBox);
  24
+
  25
+    // Connections.
  26
+    connect(this->minSupport, SIGNAL(valueChanged(double)), SLOT(minSupportChanged(double)));
  27
+    connect(this->minConfidence, SIGNAL(valueChanged(double)), SLOT(minConfidenceChanged(double)));
  28
+    connect(this->patternTreeSupportErrorMargin, SIGNAL(valueChanged(double)), SLOT(patternTreeSupportErrorMarginChanged(double)));
  29
+    connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), SLOT(buttonRestoreDefaults()));
  30
+    connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(buttonCancel()));
  31
+    connect(buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), SLOT(buttonSave()));
  32
+}
  33
+
  34
+double SettingsDialog::errorMarginToAbsolute(double minSupport, double errorMargin) {
  35
+    double sigma = minSupport / 100.0;
  36
+    double e = errorMargin / 100.0;
  37
+    return sigma * (1 - e) * 100.0;
  38
+}
  39
+
  40
+double SettingsDialog::absoluteToErrorMargin(double minSupport, double minPatternTreeSupport) {
  41
+    double sigma = minSupport / 100.0;
  42
+    double epsilon = minPatternTreeSupport / 100.0;
  43
+    return (1.0 - (epsilon / sigma)) * 100.0;
  44
+}
  45
+
  46
+void SettingsDialog::minSupportChanged(double value) {
  47
+    this->resultingParametersMinSupport->setText(QString("%1%").arg(QString::number(value, 'f', 2)));
  48
+    this->resultingParametersMinPatternTreeSupport->setText(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(value, this->patternTreeSupportErrorMargin->value()), 'f', 2)));
  49
+}
  50
+
  51
+void SettingsDialog::minConfidenceChanged(double value) {
  52
+    this->resultingParametersMinConfidence->setText(QString("%1%").arg(QString::number(value, 'f', 2)));
  53
+}
  54
+
  55
+void SettingsDialog::patternTreeSupportErrorMarginChanged(double value) {
  56
+    this->resultingParametersMinPatternTreeSupport->setText(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), value), 'f', 2)));
  57
+}
  58
+
  59
+void SettingsDialog::browseForFile() {
  60
+    QString episodesDiscretizerCSVFile = QFileDialog::getOpenFileName(this, tr("Open Episodes Discretizer settings file"), "", tr("Episodes Discretizer settings file (*.csv)"), NULL, QFileDialog::ReadOnly);
  61
+    if (!episodesDiscretizerCSVFile.isEmpty()) {
  62
+        this->parserEpisodesDiscretizerFileLineEdit->setText(episodesDiscretizerCSVFile);
  63
+    }
  64
+}
  65
+
  66
+void SettingsDialog::buttonRestoreDefaults() {
6 67
     QSettings settings;
  68
+    settings.remove("analyst");
  69
+    settings.remove("parser");
  70
+
  71
+    this->close();
  72
+
  73
+    emit this->settingsChanged();
  74
+}
  75
+
  76
+void SettingsDialog::buttonCancel() {
  77
+    this->close();
  78
+}
  79
+
  80
+void SettingsDialog::buttonSave() {
  81
+    QSettings settings;
  82
+
  83
+    settings.beginGroup("analyst");
  84
+    settings.setValue("minimumSupport", this->minSupport->value() / 100.0);
  85
+    settings.setValue("minimumPatternTreeSupport", SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), this->patternTreeSupportErrorMargin->value()) / 100.0);
  86
+    settings.setValue("minimumConfidence", this->minConfidence->value() / 100.0);
  87
+    settings.endGroup();
  88
+
  89
+    settings.beginGroup("parser");
  90
+    settings.setValue("episodeDiscretizerCSVFile", this->parserEpisodesDiscretizerFileLineEdit->text());
  91
+    settings.endGroup();
  92
+
  93
+    this->close();
  94
+
  95
+    emit this->settingsChanged();
  96
+}
  97
+
  98
+QWidget * SettingsDialog::createAnalystTab() {
  99
+    QSettings settings;
  100
+
  101
+    QWidget * tab = new QWidget();
7 102
 
8 103
     QLabel * descriptionLabel = new QLabel(tr("Find causes for all problems that:"));
9 104
 
@@ -76,77 +171,37 @@ SettingsDialog::SettingsDialog(QWidget * parent) :
76 171
     rpMinConfidenceLayout->addStretch();
77 172
     resultingParametersLayout->addLayout(rpMinConfidenceLayout);
78 173
 
79  
-    // Buttons.
80  
-    QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
81  
-    buttonBox->setOrientation(Qt::Horizontal);
82  
-    buttonBox->addButton(QDialogButtonBox::RestoreDefaults);
83  
-    buttonBox->addButton(QDialogButtonBox::Cancel);
84  
-    buttonBox->addButton(QDialogButtonBox::Save);
85  
-    buttonBox->button(QDialogButtonBox::RestoreDefaults)->setAutoDefault(false);
86  
-
87 174
     // Layout.
88 175
     QVBoxLayout * mainLayout = new QVBoxLayout();
89  
-    this->setLayout(mainLayout);
  176
+    tab->setLayout(mainLayout);
90 177
     mainLayout->addWidget(descriptionLabel);
91 178
     mainLayout->addLayout(minSupLayout);
92 179
     mainLayout->addLayout(minPatternTreeSupLayout);
93 180
     mainLayout->addLayout(minConfidenceLayout);
94 181
     mainLayout->addWidget(resultingParameters);
95  
-    mainLayout->addWidget(buttonBox);
96 182
 
97  
-    connect(this->minSupport, SIGNAL(valueChanged(double)), SLOT(minSupportChanged(double)));
98  
-    connect(this->minConfidence, SIGNAL(valueChanged(double)), SLOT(minConfidenceChanged(double)));
99  
-    connect(this->patternTreeSupportErrorMargin, SIGNAL(valueChanged(double)), SLOT(patternTreeSupportErrorMarginChanged(double)));
100  
-    connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), SLOT(buttonRestoreDefaults()));
101  
-    connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(buttonCancel()));
102  
-    connect(buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), SLOT(buttonSave()));
  183
+    return tab;
103 184
 }
104 185
 
105  
-double SettingsDialog::errorMarginToAbsolute(double minSupport, double errorMargin) {
106  
-    double sigma = minSupport / 100.0;
107  
-    double e = errorMargin / 100.0;
108  
-    return sigma * (1 - e) * 100.0;
109  
-}
110  
-
111  
-double SettingsDialog::absoluteToErrorMargin(double minSupport, double minPatternTreeSupport) {
112  
-    double sigma = minSupport / 100.0;
113  
-    double epsilon = minPatternTreeSupport / 100.0;
114  
-    return (1.0 - (epsilon / sigma)) * 100.0;
115  
-}
116  
-
117  
-void SettingsDialog::minSupportChanged(double value) {
118  
-    this->resultingParametersMinSupport->setText(QString("%1%").arg(QString::number(value, 'f', 2)));
119  
-    this->resultingParametersMinPatternTreeSupport->setText(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(value, this->patternTreeSupportErrorMargin->value()), 'f', 2)));
120  
-}
121  
-
122  
-void SettingsDialog::minConfidenceChanged(double value) {
123  
-    this->resultingParametersMinConfidence->setText(QString("%1%").arg(QString::number(value, 'f', 2)));
124  
-}
125  
-
126  
-void SettingsDialog::patternTreeSupportErrorMarginChanged(double value) {
127  
-    this->resultingParametersMinPatternTreeSupport->setText(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), value), 'f', 2)));
128  
-}
129  
-
130  
-void SettingsDialog::buttonRestoreDefaults() {
  186
+QWidget * SettingsDialog::createParserTab() {
  187
+    QSettings settings;
131 188
 
132  
-}
  189
+    QWidget * tab = new QWidget();
133 190
 
134  
-void SettingsDialog::buttonCancel() {
135  
-    this->close();
136  
-}
  191
+    QHBoxLayout * mainLayout = new QHBoxLayout();
137 192
 
138  
-void SettingsDialog::buttonSave() {
139  
-    QSettings settings;
  193
+    mainLayout->addWidget(new QLabel(tr("Episodes discretizer settings")));
  194
+    QString basePath = QCoreApplication::applicationDirPath();
  195
+    QString defaultValue = basePath + "/config/EpisodesSpeeds.csv";
  196
+    this->parserEpisodesDiscretizerFileLineEdit = new QLineEdit(settings.value("parser/episodeDiscretizerCSVFile", defaultValue).toString());
  197
+    mainLayout->addWidget(this->parserEpisodesDiscretizerFileLineEdit);
  198
+    QPushButton * browseButton = new QPushButton(tr("Browse"));
  199
+    browseButton->setAutoDefault(false);
  200
+    mainLayout->addWidget(browseButton);
140 201
 
141  
-    settings.beginGroup("analyst");
142  
-    settings.setValue("minimumSupport", this->minSupport->value() / 100.0);
143  
-    qDebug() << "epsilon" << SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), this->patternTreeSupportErrorMargin->value());
144  
-    settings.setValue("minimumPatternTreeSupport", SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), this->patternTreeSupportErrorMargin->value()) / 100.0);
145  
-    settings.setValue("minimumConfidence", this->minConfidence->value() / 100.0);
146  
-    settings.endGroup();
  202
+    connect(browseButton, SIGNAL(pressed()), SLOT(browseForFile()));
147 203
 
148  
-    settings.beginGroup("parser");
149  
-    settings.endGroup();
  204
+    tab->setLayout(mainLayout);
150 205
 
151  
-    this->close();
  206
+    return tab;
152 207
 }
16  code/UI/SettingsDialog.h
@@ -9,7 +9,11 @@
9 9
 #include <QDoubleSpinBox>
10 10
 #include <QPushButton>
11 11
 #include <QGroupBox>
  12
+#include <QTableWidget>
  13
+#include <QLineEdit>
  14
+#include <QFileDialog>
12 15
 #include <QSettings>
  16
+#include <QApplication>
13 17
 
14 18
 class SettingsDialog : public QDialog {
15 19
 
@@ -22,25 +26,33 @@ class SettingsDialog : public QDialog {
22 26
     static double absoluteToErrorMargin(double minSupport, double minPatternTreeSupport);
23 27
 
24 28
 signals:
25  
-
26  
-public slots:
  29
+    void settingsChanged();
27 30
 
28 31
 protected slots:
29 32
     void minSupportChanged(double value);
30 33
     void minConfidenceChanged(double value);
31 34
     void patternTreeSupportErrorMarginChanged(double value);
32 35
 
  36
+    void browseForFile();
  37
+
33 38
     void buttonRestoreDefaults();
34 39
     void buttonCancel();
35 40
     void buttonSave();
36 41
 
37 42
 protected:
  43
+    QWidget * createAnalystTab();
  44
+    QWidget * createParserTab();
  45
+
  46
+    // Analyst settings tab.
38 47
     QDoubleSpinBox * minSupport;
39 48
     QDoubleSpinBox * minConfidence;
40 49
     QDoubleSpinBox * patternTreeSupportErrorMargin;
41 50
     QLabel * resultingParametersMinSupport;
42 51
     QLabel * resultingParametersMinConfidence;
43 52
     QLabel * resultingParametersMinPatternTreeSupport;
  53
+
  54
+    // Parser settings tab.
  55
+    QLineEdit * parserEpisodesDiscretizerFileLineEdit;
44 56
 };
45 57
 
46 58
 #endif // SETTINGSDIALOG_H

0 notes on commit de9c048

Please sign in to comment.
Something went wrong with that request. Please try again.