// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen // SPDX-FileCopyrightText: Copyright 2007 Sandia Corporation // SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov #include "StatsView.h" #include "ui_StatsView.h" // SQL includes #include "vtkRowQueryToTable.h" #include "vtkSQLDatabaseSchema.h" #include "vtkSQLQuery.h" #include "vtkSQLiteDatabase.h" // Stats includes #include "vtkCorrelativeStatistics.h" #include "vtkDescriptiveStatistics.h" #include "vtkOrderStatistics.h" #include "vtkPartitionedDataSetCollection.h" #include "vtkStatisticalModel.h" // QT includes #include #include #include #include #include #include #include #include #include #include #include #include "vtkSmartPointer.h" #include #define VTK_CREATE(type, name) vtkSmartPointer name = vtkSmartPointer::New() // Constructor StatsView::StatsView() { this->ui = new Ui_StatsView; this->ui->setupUi(this); this->RowQueryToTable = vtkSmartPointer::New(); this->TableView1 = vtkSmartPointer::New(); this->TableView2 = vtkSmartPointer::New(); this->TableView3 = vtkSmartPointer::New(); this->TableView4 = vtkSmartPointer::New(); this->TableView1->SetFieldType(vtkQtTableView::ROW_DATA); this->TableView2->SetFieldType(vtkQtTableView::ROW_DATA); this->TableView3->SetFieldType(vtkQtTableView::ROW_DATA); this->TableView4->SetFieldType(vtkQtTableView::ROW_DATA); // Set widgets for the tree and table views this->ui->tableFrame1->layout()->addWidget(this->TableView1->GetWidget()); this->ui->tableFrame2->layout()->addWidget(this->TableView2->GetWidget()); this->ui->tableFrame3->layout()->addWidget(this->TableView3->GetWidget()); this->ui->tableFrame4->layout()->addWidget(this->TableView4->GetWidget()); // Tweak the layout so we have a good out-of-box experience const int window_width = this->width(); int left_column = static_cast(window_width * 0.7); int right_column = static_cast(window_width * 0.3); this->ui->splitter->setSizes(QList() << left_column << right_column << 0); // Set up action signals and slots connect(this->ui->actionOpenSQLiteDB, SIGNAL(triggered()), this, SLOT(slotOpenSQLiteDB())); }; StatsView::~StatsView() {} // Action to be taken upon graph file open void StatsView::slotOpenSQLiteDB() { // Browse for and open the file QDir dir; // Open the text data file QString fileName = QFileDialog::getOpenFileName(this, "Select the SQLite database file", QDir::homePath(), "SQLite Files (*.db);;All Files (*.*)"); if (fileName.isNull()) { std::cerr << "Could not open file" << endl; return; } // Create SQLite reader QString fullName = "sqlite://" + fileName; vtkSQLiteDatabase* db = vtkSQLiteDatabase::SafeDownCast(vtkSQLDatabase::CreateFromURL(fullName.toUtf8().data())); bool status = db->Open(""); if (!status) { std::cerr << "Couldn't open database.\n"; return; } // Query database vtkSQLQuery* query = db->GetQueryInstance(); query->SetQuery("SELECT * from main_tbl"); this->RowQueryToTable->SetQuery(query); // Calculate descriptive statistics VTK_CREATE(vtkDescriptiveStatistics, descriptive); descriptive->SetInputConnection(0, this->RowQueryToTable->GetOutputPort()); descriptive->AddColumn("Temp1"); descriptive->AddColumn("Temp2"); descriptive->Update(); // Calculate order statistics -- quartiles VTK_CREATE(vtkOrderStatistics, order1); order1->SetInputConnection(0, this->RowQueryToTable->GetOutputPort()); order1->AddColumn("Temp1"); order1->AddColumn("Temp2"); order1->SetQuantileDefinition(vtkOrderStatistics::InverseCDFAveragedSteps); order1->Update(); // Calculate order statistics -- deciles VTK_CREATE(vtkOrderStatistics, order2); order2->SetInputConnection(0, this->RowQueryToTable->GetOutputPort()); order2->AddColumn("Temp1"); order2->AddColumn("Temp2"); order2->SetNumberOfIntervals(10); order2->Update(); // Calculate correlative statistics VTK_CREATE(vtkCorrelativeStatistics, correlative); correlative->SetInputConnection(0, this->RowQueryToTable->GetOutputPort()); correlative->AddColumnPair("Temp1", "Temp2"); correlative->SetAssessOption(true); correlative->Update(); // Assign tables to table views // FIXME: we should not have to make a shallow copy of the output auto* descriptiveModel = vtkStatisticalModel::SafeDownCast(descriptive->GetOutputDataObject(1)); VTK_CREATE(vtkTable, descriptiveC); descriptiveC->ShallowCopy(descriptiveModel->GetTable(vtkStatisticalModel::Derived, 0)); this->TableView1->SetRepresentationFromInput(descriptiveC); // FIXME: we should not have to make a shallow copy of the output auto* order1Model = vtkStatisticalModel::SafeDownCast(order1->GetOutputDataObject(1)); VTK_CREATE(vtkTable, order1C); order1C->ShallowCopy(order1Model->GetTable(vtkStatisticalModel::Derived, 0)); this->TableView2->SetRepresentationFromInput(order1C); // FIXME: we should not have to make a shallow copy of the output auto* order2Model = vtkStatisticalModel::SafeDownCast(order2->GetOutputDataObject(1)); VTK_CREATE(vtkTable, order2C); order2C->ShallowCopy(order2Model->GetTable(vtkStatisticalModel::Derived, 0)); this->TableView3->SetRepresentationFromInput(order2C); // FIXME: we should not have to make a shallow copy of the output auto* correlativeModel = vtkStatisticalModel::SafeDownCast(correlative->GetOutputDataObject(1)); VTK_CREATE(vtkTable, correlativeC); correlativeC->ShallowCopy(correlativeModel->GetTable(vtkStatisticalModel::Derived, 0)); this->TableView4->SetRepresentationFromInput(correlativeC); // All views need to be updated this->TableView1->Update(); this->TableView2->Update(); this->TableView3->Update(); this->TableView4->Update(); // Clean up query->Delete(); db->Delete(); }