Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add a user-friendly settings dialog capable of storing the minimum su…

…pport, minimum PatternTree support and minimum confidence through QSettings.
  • Loading branch information...
commit a74e1e063a701c4b0a99d180bacacdc86247cd8a 1 parent c38f293
Wim Leers authored
17 code/UI/MainWindow.cpp
@@ -336,6 +336,13 @@ void MainWindow::importFile() {
336 336 }
337 337 }
338 338
  339 +void MainWindow::settingsDialog() {
  340 + SettingsDialog * settingsDialog = new SettingsDialog(this);
  341 + settingsDialog->show();
  342 + settingsDialog->raise();
  343 + settingsDialog->activateWindow();
  344 +}
  345 +
339 346
340 347 //------------------------------------------------------------------------------
341 348 // Private methods: logic.
@@ -358,7 +365,11 @@ void MainWindow::initLogic() {
358 365
359 366 // TODO: when these parameters have been figured out, they should be the defaults
360 367 // and therefor they should be moved to the Analyst constructor.
361   - this->analyst = new Analytics::Analyst(0.05, 0.04, 0.2);
  368 + QSettings settings;
  369 + double minSupport = settings.value("analyst/minimumSupport", 0.05).toDouble();
  370 + double minPatternTreeSupport = settings.value("analyst/minimumPatternTreeSupport", 0.04).toDouble();
  371 + double minConfidence = settings.value("analyst/minimumConfidence", 0.2).toDouble();
  372 + this->analyst = new Analytics::Analyst(minSupport, minPatternTreeSupport, minConfidence);
362 373
363 374 // Set constraints. This defines which associations will be found. By
364 375 // default, only causes for slow episodes will be searched.
@@ -733,6 +744,9 @@ void MainWindow::createMenuBar() {
733 744 this->menuFileImport->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_I));
734 745 this->menuFile->addAction(this->menuFileImport);
735 746
  747 + this->menuFileSettings = new QAction(tr("Settings"), this->menuFile);
  748 + this->menuFile->addAction(this->menuFileSettings);
  749 +
736 750 menuBar->addMenu(this->menuFile);
737 751 }
738 752
@@ -744,4 +758,5 @@ void MainWindow::connectUI() {
744 758
745 759 // Menus.
746 760 connect(this->menuFileImport, SIGNAL(triggered()), SLOT(importFile()));
  761 + connect(this->menuFileSettings, SIGNAL(triggered()), SLOT(settingsDialog()));
747 762 }
4 code/UI/MainWindow.h
@@ -28,6 +28,7 @@
28 28 #include <QLineEdit>
29 29 #include <QFileDialog>
30 30 #include <QDesktopServices>
  31 +#include <QDialog>
31 32
32 33 #include <QTableView>
33 34 #include <QHeaderView>
@@ -40,6 +41,7 @@
40 41
41 42 #include "ConceptHierarchyCompleter.h"
42 43 #include "CausesTableFilterProxyModel.h"
  44 +#include "SettingsDialog.h"
43 45
44 46 #include "../EpisodesParser/Parser.h"
45 47 #include "../Analytics/Analyst.h"
@@ -98,6 +100,7 @@ protected slots:
98 100 void causesFilterChanged(QString filterString);
99 101
100 102 void importFile();
  103 + void settingsDialog();
101 104
102 105 private:
103 106 // Logic.
@@ -181,6 +184,7 @@ protected slots:
181 184 // Menu bar.
182 185 QMenu * menuFile;
183 186 QAction * menuFileImport;
  187 + QAction * menuFileSettings;
184 188 };
185 189
186 190 #endif // MAINWINDOW_H
152 code/UI/SettingsDialog.cpp
... ... @@ -0,0 +1,152 @@
  1 +#include "SettingsDialog.h"
  2 +
  3 +SettingsDialog::SettingsDialog(QWidget * parent) :
  4 + QDialog(parent)
  5 +{
  6 + QSettings settings;
  7 +
  8 + QLabel * descriptionLabel = new QLabel(tr("Find causes for all problems that:"));
  9 +
  10 + // Minimum frequent itemset support.
  11 + QHBoxLayout * minSupLayout = new QHBoxLayout();
  12 + QLabel * minSupPrefixLabel = new QLabel(tr("affect at least"));
  13 + QLabel * minSupSuffixLabel = new QLabel(tr("of all page views"));
  14 + this->minSupport = new QDoubleSpinBox();
  15 + this->minSupport->setSuffix("%");
  16 + this->minSupport->setMinimum(1);
  17 + this->minSupport->setMaximum(100);
  18 + this->minSupport->setValue(qRound(settings.value("analyst/minimumSupport", 0.05).toDouble() * 100));
  19 + minSupLayout->addWidget(minSupPrefixLabel);
  20 + minSupLayout->addWidget(this->minSupport);
  21 + minSupLayout->addWidget(minSupSuffixLabel);
  22 + minSupLayout->addStretch();
  23 +
  24 + // Minimum PatternTree support.
  25 + QHBoxLayout * minPatternTreeSupLayout = new QHBoxLayout();
  26 + QLabel * minPatternTreeSupPrefixLabel = new QLabel(tr("(but allow a frequency estimation error margin of"));
  27 + QLabel * minPatternTreeSupSuffixLabel = new QLabel(tr(")"));
  28 + this->patternTreeSupportErrorMargin = new QDoubleSpinBox();
  29 + this->patternTreeSupportErrorMargin->setSuffix("%");
  30 + this->patternTreeSupportErrorMargin->setMinimum(1);
  31 + this->patternTreeSupportErrorMargin->setMaximum(100);
  32 + this->patternTreeSupportErrorMargin->setValue(SettingsDialog::absoluteToErrorMargin(this->minSupport->value(), settings.value("analyst/minimumPatternTreeSupport", 0.04).toDouble() * 100));
  33 +
  34 + minPatternTreeSupLayout->addWidget(minPatternTreeSupPrefixLabel);
  35 + minPatternTreeSupLayout->addWidget(this->patternTreeSupportErrorMargin);
  36 + minPatternTreeSupLayout->addWidget(minPatternTreeSupSuffixLabel);
  37 + minPatternTreeSupLayout->addStretch();
  38 +
  39 + // Minimum confidence.
  40 + QHBoxLayout * minConfidenceLayout = new QHBoxLayout();
  41 + QLabel * minConfidencePrefixLabel = new QLabel(tr("and are slow at least"));
  42 + QLabel * minConfidenceSuffixLabel = new QLabel(tr("of the time"));
  43 + this->minConfidence = new QDoubleSpinBox();
  44 + this->minConfidence->setSuffix("%");
  45 + this->minConfidence->setMinimum(1);
  46 + this->minConfidence->setMaximum(100);
  47 + this->minConfidence->setValue(qRound(settings.value("analyst/minimumConfidence", 0.2).toDouble() * 100));
  48 + minConfidenceLayout->addWidget(minConfidencePrefixLabel);
  49 + minConfidenceLayout->addWidget(this->minConfidence);
  50 + minConfidenceLayout->addWidget(minConfidenceSuffixLabel);
  51 + minConfidenceLayout->addStretch();
  52 +
  53 + // Resulting parameters.
  54 + QGroupBox * resultingParameters = new QGroupBox(tr("Resulting parameters"));
  55 + QVBoxLayout * resultingParametersLayout = new QVBoxLayout();
  56 + resultingParameters->setLayout(resultingParametersLayout);
  57 +
  58 + QHBoxLayout * rpMinSupportLayout = new QHBoxLayout();
  59 + this->resultingParametersMinSupport = new QLabel(QString("%1%").arg(QString::number(this->minSupport->value(), 'f', 2)));
  60 + rpMinSupportLayout->addWidget(new QLabel(tr("Minimum frequent itemset support") + ":"));
  61 + rpMinSupportLayout->addWidget(this->resultingParametersMinSupport);
  62 + rpMinSupportLayout->addStretch();
  63 + resultingParametersLayout->addLayout(rpMinSupportLayout);
  64 +
  65 + QHBoxLayout * rpMinPatternTreeSupportLayout = new QHBoxLayout();
  66 + this->resultingParametersMinPatternTreeSupport = new QLabel(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), this->patternTreeSupportErrorMargin->value()), 'f', 2)));
  67 + rpMinPatternTreeSupportLayout->addWidget(new QLabel(tr("Minimum PatternTree suppport") + ":"));
  68 + rpMinPatternTreeSupportLayout->addWidget(this->resultingParametersMinPatternTreeSupport);
  69 + rpMinPatternTreeSupportLayout->addStretch();
  70 + resultingParametersLayout->addLayout(rpMinPatternTreeSupportLayout);
  71 +
  72 + QHBoxLayout * rpMinConfidenceLayout = new QHBoxLayout();
  73 + this->resultingParametersMinConfidence = new QLabel(QString("%1%").arg(QString::number(this->minConfidence->value(), 'f', 2)));
  74 + rpMinConfidenceLayout->addWidget(new QLabel(tr("Minimum confidence") + ":"));
  75 + rpMinConfidenceLayout->addWidget(this->resultingParametersMinConfidence);
  76 + rpMinConfidenceLayout->addStretch();
  77 + resultingParametersLayout->addLayout(rpMinConfidenceLayout);
  78 +
  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 + // Layout.
  88 + QVBoxLayout * mainLayout = new QVBoxLayout();
  89 + this->setLayout(mainLayout);
  90 + mainLayout->addWidget(descriptionLabel);
  91 + mainLayout->addLayout(minSupLayout);
  92 + mainLayout->addLayout(minPatternTreeSupLayout);
  93 + mainLayout->addLayout(minConfidenceLayout);
  94 + mainLayout->addWidget(resultingParameters);
  95 + mainLayout->addWidget(buttonBox);
  96 +
  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()));
  103 +}
  104 +
  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() {
  131 +
  132 +}
  133 +
  134 +void SettingsDialog::buttonCancel() {
  135 + this->close();
  136 +}
  137 +
  138 +void SettingsDialog::buttonSave() {
  139 + QSettings settings;
  140 +
  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();
  147 +
  148 + settings.beginGroup("parser");
  149 + settings.endGroup();
  150 +
  151 + this->close();
  152 +}
46 code/UI/SettingsDialog.h
... ... @@ -0,0 +1,46 @@
  1 +#ifndef SETTINGSDIALOG_H
  2 +#define SETTINGSDIALOG_H
  3 +
  4 +#include <QDialog>
  5 +#include <QDialogButtonBox>
  6 +#include <QHBoxLayout>
  7 +#include <QVBoxLayout>
  8 +#include <QLabel>
  9 +#include <QDoubleSpinBox>
  10 +#include <QPushButton>
  11 +#include <QGroupBox>
  12 +#include <QSettings>
  13 +
  14 +class SettingsDialog : public QDialog {
  15 +
  16 + Q_OBJECT
  17 +
  18 +public:
  19 + explicit SettingsDialog(QWidget * parent = NULL);
  20 +
  21 + static double errorMarginToAbsolute(double minSupport, double errorMargin);
  22 + static double absoluteToErrorMargin(double minSupport, double minPatternTreeSupport);
  23 +
  24 +signals:
  25 +
  26 +public slots:
  27 +
  28 +protected slots:
  29 + void minSupportChanged(double value);
  30 + void minConfidenceChanged(double value);
  31 + void patternTreeSupportErrorMarginChanged(double value);
  32 +
  33 + void buttonRestoreDefaults();
  34 + void buttonCancel();
  35 + void buttonSave();
  36 +
  37 +protected:
  38 + QDoubleSpinBox * minSupport;
  39 + QDoubleSpinBox * minConfidence;
  40 + QDoubleSpinBox * patternTreeSupportErrorMargin;
  41 + QLabel * resultingParametersMinSupport;
  42 + QLabel * resultingParametersMinConfidence;
  43 + QLabel * resultingParametersMinPatternTreeSupport;
  44 +};
  45 +
  46 +#endif // SETTINGSDIALOG_H
6 code/UI/UI.pri
@@ -5,11 +5,13 @@ INCLUDEPATH += $${PWD}
5 5 SOURCES += \
6 6 $${PWD}/MainWindow.cpp \
7 7 $${PWD}/ConceptHierarchyCompleter.cpp \
8   - $${PWD}/CausesTableFilterProxyModel.cpp
  8 + $${PWD}/CausesTableFilterProxyModel.cpp \
  9 + $${PWD}/SettingsDialog.cpp
9 10 HEADERS += \
10 11 $${PWD}/MainWindow.h \
11 12 $${PWD}/ConceptHierarchyCompleter.h \
12   - $${PWD}/CausesTableFilterProxyModel.h
  13 + $${PWD}/CausesTableFilterProxyModel.h \
  14 + $${PWD}/SettingsDialog.h
13 15
14 16 # Disable qDebug() output when in release mode.
15 17 CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT

0 comments on commit a74e1e0

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