Add calculating stats with script
This commit is contained in:
+13
-10
@@ -1,5 +1,6 @@
|
|||||||
#include "batchprocessing.h"
|
#include "batchprocessing.h"
|
||||||
#include "ui_batchprocessing.h"
|
#include "ui_batchprocessing.h"
|
||||||
|
#include <functional>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
@@ -16,28 +17,30 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void scanDirectory(const QString &path, QStringList &files)
|
QStringList scanDirectories(const QStringList &paths)
|
||||||
|
{
|
||||||
|
QStringList files;
|
||||||
|
QStringList scannedDirs;
|
||||||
|
|
||||||
|
std::function<void(const QString &path)> scanDirectory = [&](const QString &path)
|
||||||
{
|
{
|
||||||
QFileInfo info(path);
|
QFileInfo info(path);
|
||||||
if(info.isDir())
|
if(info.isDir() && !scannedDirs.contains(info.canonicalPath()))
|
||||||
{
|
{
|
||||||
|
scannedDirs.append(info.canonicalPath());
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
QStringList entries = dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
QStringList entries = dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||||
for(QString &entry : entries)
|
for(QString &entry : entries)
|
||||||
scanDirectory(dir.absoluteFilePath(entry), files);
|
scanDirectory(dir.absoluteFilePath(entry));
|
||||||
}
|
}
|
||||||
else if(info.isFile())
|
else if(info.isFile())
|
||||||
{
|
{
|
||||||
files.append(path);
|
files.append(path);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
QStringList scanDirectories(const QStringList &paths)
|
|
||||||
{
|
|
||||||
QStringList files;
|
|
||||||
|
|
||||||
for(const QString &path : paths)
|
for(const QString &path : paths)
|
||||||
scanDirectory(path, files);
|
scanDirectory(path);
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
@@ -205,7 +208,7 @@ void BatchProcessing::scriptFinished()
|
|||||||
_ui->startButton->setEnabled(true);
|
_ui->startButton->setEnabled(true);
|
||||||
_ui->stopButton->setEnabled(false);
|
_ui->stopButton->setEnabled(false);
|
||||||
qDebug() << "script finished";
|
qDebug() << "script finished";
|
||||||
delete _engineThread;
|
_engineThread->deleteLater();
|
||||||
_engineThread = nullptr;
|
_engineThread = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -154,11 +154,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
|||||||
fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir()));
|
fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir()));
|
||||||
fileMenu->addAction(tr("Reindex files"), this, SLOT(reindex()));
|
fileMenu->addAction(tr("Reindex files"), this, SLOT(reindex()));
|
||||||
fileMenu->addAction(tr("Export database to CSV"), this, &MainWindow::exportCSV);
|
fileMenu->addAction(tr("Export database to CSV"), this, &MainWindow::exportCSV);
|
||||||
/*fileMenu->addAction(tr("Batch processing"), [this](){
|
fileMenu->addAction(tr("Batch processing"), [this](){
|
||||||
BatchProcessing *batchProcessing = new BatchProcessing(this);
|
BatchProcessing *batchProcessing = new BatchProcessing(this);
|
||||||
batchProcessing->exec();
|
batchProcessing->exec();
|
||||||
delete batchProcessing;
|
delete batchProcessing;
|
||||||
}, Qt::Key_B | Qt::CTRL);*/
|
}, Qt::Key_B | Qt::CTRL);
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
||||||
liveModeAction->setCheckable(true);
|
liveModeAction->setCheckable(true);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "loadrunable.h"
|
#include "loadrunable.h"
|
||||||
|
#include "rawimage.h"
|
||||||
|
|
||||||
namespace Script
|
namespace Script
|
||||||
{
|
{
|
||||||
@@ -63,6 +64,11 @@ bool ScriptEngine::isMarked(const File *file) const
|
|||||||
return _database->isMarked(file->absoluteFilePath());
|
return _database->isMarked(file->absoluteFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJSValue ScriptEngine::newObject()
|
||||||
|
{
|
||||||
|
return _jsEngine->newObject();
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptEngine::run()
|
void ScriptEngine::run()
|
||||||
{
|
{
|
||||||
QJSValue jsPaths = _jsEngine->newArray(_paths.size());
|
QJSValue jsPaths = _jsEngine->newArray(_paths.size());
|
||||||
@@ -73,7 +79,11 @@ void ScriptEngine::run()
|
|||||||
|
|
||||||
QFile scriptFile(_scriptPath);
|
QFile scriptFile(_scriptPath);
|
||||||
if(!scriptFile.open(QIODevice::ReadOnly))
|
if(!scriptFile.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
emit newMessage("Failed to open " + _scriptPath, true);
|
||||||
|
emit finished();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QTextStream stream(&scriptFile);
|
QTextStream stream(&scriptFile);
|
||||||
QString contents = stream.readAll();
|
QString contents = stream.readAll();
|
||||||
@@ -226,6 +236,26 @@ bool File::convertTo(const QString &format)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJSValue File::stats()
|
||||||
|
{
|
||||||
|
if(_stats.isUndefined())
|
||||||
|
{
|
||||||
|
ImageInfoData info;
|
||||||
|
std::shared_ptr<RawImage> rawImage;
|
||||||
|
loadImage(_path, info, rawImage);
|
||||||
|
rawImage->calcStats();
|
||||||
|
RawImage::Stats stats = rawImage->imageStats();
|
||||||
|
_stats = _engine->newObject();
|
||||||
|
_stats.setProperty("mean", stats.m_mean[0]);
|
||||||
|
_stats.setProperty("stddev", stats.m_stdDev[0]);
|
||||||
|
_stats.setProperty("median", stats.m_median[0]);
|
||||||
|
_stats.setProperty("min", stats.m_min[0]);
|
||||||
|
_stats.setProperty("max", stats.m_max[0]);
|
||||||
|
_stats.setProperty("mad", stats.m_mean[0]);
|
||||||
|
}
|
||||||
|
return _stats;
|
||||||
|
}
|
||||||
|
|
||||||
ScriptEngineThread::ScriptEngineThread(QObject *parent) : QObject(parent)
|
ScriptEngineThread::ScriptEngineThread(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
_thread = new QThread();
|
_thread = new QThread();
|
||||||
@@ -236,6 +266,7 @@ ScriptEngineThread::ScriptEngineThread(QObject *parent) : QObject(parent)
|
|||||||
connect(_engine, &ScriptEngine::newMessage, this, &ScriptEngineThread::newMessage);
|
connect(_engine, &ScriptEngine::newMessage, this, &ScriptEngineThread::newMessage);
|
||||||
connect(_thread, &QThread::started, _engine, &ScriptEngine::run);
|
connect(_thread, &QThread::started, _engine, &ScriptEngine::run);
|
||||||
connect(_thread, &QThread::finished, _engine, &ScriptEngine::deleteLater);
|
connect(_thread, &QThread::finished, _engine, &ScriptEngine::deleteLater);
|
||||||
|
connect(_engine, &ScriptEngine::destroyed, [this](){ _engine = nullptr; });
|
||||||
connect(_thread, &QThread::finished, _thread, &QThread::deleteLater);
|
connect(_thread, &QThread::finished, _thread, &QThread::deleteLater);
|
||||||
connect(_thread, &QThread::finished, this, &ScriptEngineThread::finished);
|
connect(_thread, &QThread::finished, this, &ScriptEngineThread::finished);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public:
|
|||||||
Q_INVOKABLE void mark(File *file);
|
Q_INVOKABLE void mark(File *file);
|
||||||
Q_INVOKABLE void unmark(File *file);
|
Q_INVOKABLE void unmark(File *file);
|
||||||
Q_INVOKABLE bool isMarked(const File *file) const;
|
Q_INVOKABLE bool isMarked(const File *file) const;
|
||||||
|
QJSValue newObject();
|
||||||
public slots:
|
public slots:
|
||||||
void run();
|
void run();
|
||||||
signals:
|
signals:
|
||||||
@@ -64,6 +65,7 @@ class File : public QObject
|
|||||||
QMap<QString, QString> _fitsKeywords;
|
QMap<QString, QString> _fitsKeywords;
|
||||||
void loadFitsKeywords();
|
void loadFitsKeywords();
|
||||||
bool mkpath(const QString &path) const;
|
bool mkpath(const QString &path) const;
|
||||||
|
QJSValue _stats;
|
||||||
public:
|
public:
|
||||||
explicit File(const QString &path, ScriptEngine *engine);
|
explicit File(const QString &path, ScriptEngine *engine);
|
||||||
Q_INVOKABLE QString fileName() const;
|
Q_INVOKABLE QString fileName() const;
|
||||||
@@ -79,6 +81,7 @@ public:
|
|||||||
Q_INVOKABLE bool copy(const QString &newpath) const;
|
Q_INVOKABLE bool copy(const QString &newpath) const;
|
||||||
Q_INVOKABLE bool move(const QString &newpath) const;
|
Q_INVOKABLE bool move(const QString &newpath) const;
|
||||||
Q_INVOKABLE bool convertTo(const QString &format);
|
Q_INVOKABLE bool convertTo(const QString &format);
|
||||||
|
Q_INVOKABLE QJSValue stats();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user