Triage: If there are more than 100 results then pick 100 random warnings

This commit is contained in:
Daniel Marjamäki 2018-02-04 16:14:33 +01:00
parent 4998248501
commit 6ce9646ac6
1 changed files with 11 additions and 2 deletions

View File

@ -7,6 +7,7 @@
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QFileDialog> #include <QFileDialog>
#include <ctime>
const QString WORK_FOLDER(QDir::homePath() + "/triage"); const QString WORK_FOLDER(QDir::homePath() + "/triage");
@ -15,6 +16,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
qsrand(std::time(0));
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -33,13 +35,14 @@ void MainWindow::loadFile()
QTextStream textStream(&file); QTextStream textStream(&file);
QString url; QString url;
QString errorMessage; QString errorMessage;
QStringList allErrors;
while (true) { while (true) {
const QString line = textStream.readLine(); const QString line = textStream.readLine();
if (line.isNull()) if (line.isNull())
break; break;
if (line.startsWith("ftp://")) { if (line.startsWith("ftp://")) {
if (!url.isEmpty() && !errorMessage.isEmpty()) if (!url.isEmpty() && !errorMessage.isEmpty())
ui->results->addItem(url + "\n" + errorMessage); allErrors << (url + "\n" + errorMessage);
url = line; url = line;
errorMessage.clear(); errorMessage.clear();
} else if (!url.isEmpty() && QRegExp(".*: (error|warning|note):.*").exactMatch(line)) { } else if (!url.isEmpty() && QRegExp(".*: (error|warning|note):.*").exactMatch(line)) {
@ -49,7 +52,13 @@ void MainWindow::loadFile()
} }
} }
if (!url.isEmpty() && !errorMessage.isEmpty()) if (!url.isEmpty() && !errorMessage.isEmpty())
ui->results->addItem(url + "\n" + errorMessage); allErrors << (url + "\n" + errorMessage);
if (allErrors.size() > 100) {
std::random_shuffle(allErrors.begin(), allErrors.end());
ui->results->addItems(allErrors.mid(0,100));
} else {
ui->results->addItems(allErrors);
}
} }
void MainWindow::showResult(QListWidgetItem *item) void MainWindow::showResult(QListWidgetItem *item)