Permalink
Browse files

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...
1 parent 882e3ef commit de9c048b79bbb0af986f16cfcbbfbcecb19fd89e @wimleers committed Jun 29, 2011
Showing with 131 additions and 63 deletions.
  1. +5 −4 code/UI/MainWindow.cpp
  2. +112 −57 code/UI/SettingsDialog.cpp
  3. +14 −2 code/UI/SettingsDialog.h
View
9 code/UI/MainWindow.cpp
@@ -353,20 +353,21 @@ void MainWindow::initLogic() {
qRegisterMetaType<Time>("Time");
Analytics::registerBasicMetaTypes();
+ QSettings settings;
QString basePath = QCoreApplication::applicationDirPath();
+ QString defaultValue = basePath + "/config/EpisodesSpeeds.csv";
+ QString episodeDiscretizerCSV = settings.value("parser/episodeDiscretizerCSVFile", defaultValue).toString();
+
EpisodesParser::Parser::initParserHelpers(basePath + "/config/browscap.csv",
basePath + "/config/browscap-index.db",
basePath + "/config/GeoIPCity.dat",
basePath + "/config/GeoIPASNum.dat",
- basePath + "/config/EpisodesSpeeds.csv"
+ episodeDiscretizerCSV
);
// Instantiate the EpisodesParser and the Analytics. Then connect them.
this->parser = new EpisodesParser::Parser();
- // TODO: when these parameters have been figured out, they should be the defaults
- // and therefor they should be moved to the Analyst constructor.
- QSettings settings;
double minSupport = settings.value("analyst/minimumSupport", 0.05).toDouble();
double minPatternTreeSupport = settings.value("analyst/minimumPatternTreeSupport", 0.04).toDouble();
double minConfidence = settings.value("analyst/minimumConfidence", 0.2).toDouble();
View
169 code/UI/SettingsDialog.cpp
@@ -3,7 +3,102 @@
SettingsDialog::SettingsDialog(QWidget * parent) :
QDialog(parent)
{
+ QTabWidget * mainWidget = new QTabWidget(this);
+
+ mainWidget->addTab(this->createAnalystTab(), tr("Analysis"));
+ mainWidget->addTab(this->createParserTab(), tr("Parser"));
+
+ // Buttons.
+ QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
+ buttonBox->setOrientation(Qt::Horizontal);
+ buttonBox->addButton(QDialogButtonBox::RestoreDefaults);
+ buttonBox->addButton(QDialogButtonBox::Cancel);
+ buttonBox->addButton(QDialogButtonBox::Save);
+ buttonBox->button(QDialogButtonBox::RestoreDefaults)->setAutoDefault(false);
+
+ // Layout.
+ QVBoxLayout * mainLayout = new QVBoxLayout();
+ this->setLayout(mainLayout);
+ mainLayout->addWidget(mainWidget);
+ mainLayout->addWidget(buttonBox);
+
+ // Connections.
+ connect(this->minSupport, SIGNAL(valueChanged(double)), SLOT(minSupportChanged(double)));
+ connect(this->minConfidence, SIGNAL(valueChanged(double)), SLOT(minConfidenceChanged(double)));
+ connect(this->patternTreeSupportErrorMargin, SIGNAL(valueChanged(double)), SLOT(patternTreeSupportErrorMarginChanged(double)));
+ connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), SLOT(buttonRestoreDefaults()));
+ connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(buttonCancel()));
+ connect(buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), SLOT(buttonSave()));
+}
+
+double SettingsDialog::errorMarginToAbsolute(double minSupport, double errorMargin) {
+ double sigma = minSupport / 100.0;
+ double e = errorMargin / 100.0;
+ return sigma * (1 - e) * 100.0;
+}
+
+double SettingsDialog::absoluteToErrorMargin(double minSupport, double minPatternTreeSupport) {
+ double sigma = minSupport / 100.0;
+ double epsilon = minPatternTreeSupport / 100.0;
+ return (1.0 - (epsilon / sigma)) * 100.0;
+}
+
+void SettingsDialog::minSupportChanged(double value) {
+ this->resultingParametersMinSupport->setText(QString("%1%").arg(QString::number(value, 'f', 2)));
+ this->resultingParametersMinPatternTreeSupport->setText(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(value, this->patternTreeSupportErrorMargin->value()), 'f', 2)));
+}
+
+void SettingsDialog::minConfidenceChanged(double value) {
+ this->resultingParametersMinConfidence->setText(QString("%1%").arg(QString::number(value, 'f', 2)));
+}
+
+void SettingsDialog::patternTreeSupportErrorMarginChanged(double value) {
+ this->resultingParametersMinPatternTreeSupport->setText(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), value), 'f', 2)));
+}
+
+void SettingsDialog::browseForFile() {
+ QString episodesDiscretizerCSVFile = QFileDialog::getOpenFileName(this, tr("Open Episodes Discretizer settings file"), "", tr("Episodes Discretizer settings file (*.csv)"), NULL, QFileDialog::ReadOnly);
+ if (!episodesDiscretizerCSVFile.isEmpty()) {
+ this->parserEpisodesDiscretizerFileLineEdit->setText(episodesDiscretizerCSVFile);
+ }
+}
+
+void SettingsDialog::buttonRestoreDefaults() {
QSettings settings;
+ settings.remove("analyst");
+ settings.remove("parser");
+
+ this->close();
+
+ emit this->settingsChanged();
+}
+
+void SettingsDialog::buttonCancel() {
+ this->close();
+}
+
+void SettingsDialog::buttonSave() {
+ QSettings settings;
+
+ settings.beginGroup("analyst");
+ settings.setValue("minimumSupport", this->minSupport->value() / 100.0);
+ settings.setValue("minimumPatternTreeSupport", SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), this->patternTreeSupportErrorMargin->value()) / 100.0);
+ settings.setValue("minimumConfidence", this->minConfidence->value() / 100.0);
+ settings.endGroup();
+
+ settings.beginGroup("parser");
+ settings.setValue("episodeDiscretizerCSVFile", this->parserEpisodesDiscretizerFileLineEdit->text());
+ settings.endGroup();
+
+ this->close();
+
+ emit this->settingsChanged();
+}
+
+QWidget * SettingsDialog::createAnalystTab() {
+ QSettings settings;
+
+ QWidget * tab = new QWidget();
QLabel * descriptionLabel = new QLabel(tr("Find causes for all problems that:"));
@@ -76,77 +171,37 @@ SettingsDialog::SettingsDialog(QWidget * parent) :
rpMinConfidenceLayout->addStretch();
resultingParametersLayout->addLayout(rpMinConfidenceLayout);
- // Buttons.
- QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
- buttonBox->setOrientation(Qt::Horizontal);
- buttonBox->addButton(QDialogButtonBox::RestoreDefaults);
- buttonBox->addButton(QDialogButtonBox::Cancel);
- buttonBox->addButton(QDialogButtonBox::Save);
- buttonBox->button(QDialogButtonBox::RestoreDefaults)->setAutoDefault(false);
-
// Layout.
QVBoxLayout * mainLayout = new QVBoxLayout();
- this->setLayout(mainLayout);
+ tab->setLayout(mainLayout);
mainLayout->addWidget(descriptionLabel);
mainLayout->addLayout(minSupLayout);
mainLayout->addLayout(minPatternTreeSupLayout);
mainLayout->addLayout(minConfidenceLayout);
mainLayout->addWidget(resultingParameters);
- mainLayout->addWidget(buttonBox);
- connect(this->minSupport, SIGNAL(valueChanged(double)), SLOT(minSupportChanged(double)));
- connect(this->minConfidence, SIGNAL(valueChanged(double)), SLOT(minConfidenceChanged(double)));
- connect(this->patternTreeSupportErrorMargin, SIGNAL(valueChanged(double)), SLOT(patternTreeSupportErrorMarginChanged(double)));
- connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), SLOT(buttonRestoreDefaults()));
- connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(buttonCancel()));
- connect(buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), SLOT(buttonSave()));
+ return tab;
}
-double SettingsDialog::errorMarginToAbsolute(double minSupport, double errorMargin) {
- double sigma = minSupport / 100.0;
- double e = errorMargin / 100.0;
- return sigma * (1 - e) * 100.0;
-}
-
-double SettingsDialog::absoluteToErrorMargin(double minSupport, double minPatternTreeSupport) {
- double sigma = minSupport / 100.0;
- double epsilon = minPatternTreeSupport / 100.0;
- return (1.0 - (epsilon / sigma)) * 100.0;
-}
-
-void SettingsDialog::minSupportChanged(double value) {
- this->resultingParametersMinSupport->setText(QString("%1%").arg(QString::number(value, 'f', 2)));
- this->resultingParametersMinPatternTreeSupport->setText(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(value, this->patternTreeSupportErrorMargin->value()), 'f', 2)));
-}
-
-void SettingsDialog::minConfidenceChanged(double value) {
- this->resultingParametersMinConfidence->setText(QString("%1%").arg(QString::number(value, 'f', 2)));
-}
-
-void SettingsDialog::patternTreeSupportErrorMarginChanged(double value) {
- this->resultingParametersMinPatternTreeSupport->setText(QString("%1%").arg(QString::number(SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), value), 'f', 2)));
-}
-
-void SettingsDialog::buttonRestoreDefaults() {
+QWidget * SettingsDialog::createParserTab() {
+ QSettings settings;
-}
+ QWidget * tab = new QWidget();
-void SettingsDialog::buttonCancel() {
- this->close();
-}
+ QHBoxLayout * mainLayout = new QHBoxLayout();
-void SettingsDialog::buttonSave() {
- QSettings settings;
+ mainLayout->addWidget(new QLabel(tr("Episodes discretizer settings")));
+ QString basePath = QCoreApplication::applicationDirPath();
+ QString defaultValue = basePath + "/config/EpisodesSpeeds.csv";
+ this->parserEpisodesDiscretizerFileLineEdit = new QLineEdit(settings.value("parser/episodeDiscretizerCSVFile", defaultValue).toString());
+ mainLayout->addWidget(this->parserEpisodesDiscretizerFileLineEdit);
+ QPushButton * browseButton = new QPushButton(tr("Browse"));
+ browseButton->setAutoDefault(false);
+ mainLayout->addWidget(browseButton);
- settings.beginGroup("analyst");
- settings.setValue("minimumSupport", this->minSupport->value() / 100.0);
- qDebug() << "epsilon" << SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), this->patternTreeSupportErrorMargin->value());
- settings.setValue("minimumPatternTreeSupport", SettingsDialog::errorMarginToAbsolute(this->minSupport->value(), this->patternTreeSupportErrorMargin->value()) / 100.0);
- settings.setValue("minimumConfidence", this->minConfidence->value() / 100.0);
- settings.endGroup();
+ connect(browseButton, SIGNAL(pressed()), SLOT(browseForFile()));
- settings.beginGroup("parser");
- settings.endGroup();
+ tab->setLayout(mainLayout);
- this->close();
+ return tab;
}
View
16 code/UI/SettingsDialog.h
@@ -9,7 +9,11 @@
#include <QDoubleSpinBox>
#include <QPushButton>
#include <QGroupBox>
+#include <QTableWidget>
+#include <QLineEdit>
+#include <QFileDialog>
#include <QSettings>
+#include <QApplication>
class SettingsDialog : public QDialog {
@@ -22,25 +26,33 @@ class SettingsDialog : public QDialog {
static double absoluteToErrorMargin(double minSupport, double minPatternTreeSupport);
signals:
-
-public slots:
+ void settingsChanged();
protected slots:
void minSupportChanged(double value);
void minConfidenceChanged(double value);
void patternTreeSupportErrorMarginChanged(double value);
+ void browseForFile();
+
void buttonRestoreDefaults();
void buttonCancel();
void buttonSave();
protected:
+ QWidget * createAnalystTab();
+ QWidget * createParserTab();
+
+ // Analyst settings tab.
QDoubleSpinBox * minSupport;
QDoubleSpinBox * minConfidence;
QDoubleSpinBox * patternTreeSupportErrorMargin;
QLabel * resultingParametersMinSupport;
QLabel * resultingParametersMinConfidence;
QLabel * resultingParametersMinPatternTreeSupport;
+
+ // Parser settings tab.
+ QLineEdit * parserEpisodesDiscretizerFileLineEdit;
};
#endif // SETTINGSDIALOG_H

0 comments on commit de9c048

Please sign in to comment.