Can download multiple images from GitHub.

This commit is contained in:
NissimHadar 2018-03-02 16:08:14 -08:00
parent 07267f9fe6
commit d29adcd000
4 changed files with 81 additions and 22 deletions

View file

@ -188,36 +188,43 @@ void Test::evaluateTests(bool interactiveMode, QProgressBar* progressBar) {
return; return;
} }
// Leave if test results folder could not be created // Quit if test results folder could not be created
if (!createTestResultsFolderPathIfNeeded(pathToTestResultsDirectory)) { if (!createTestResultsFolderPathIfNeeded(pathToTestResultsDirectory)) {
return; return;
} }
// Create two lists. The first is the test results, the second is the expected images // Create two lists. The first is the test results, the second is the expected images
// The expected images are represented as a URL to enabel download from GitHub
// Images that are in the wrong format are ignored. // Images that are in the wrong format are ignored.
QStringList sortedTestResultsFilenames = createListOfAllJPEGimagesInDirectory(pathToTestResultsDirectory); QStringList sortedTestResultsFilenames = createListOfAllJPEGimagesInDirectory(pathToTestResultsDirectory);
QStringList expectedImages; QStringList expectedImages;
QStringList resultImages; QStringList resultImages;
const QString URLPrefix("https://raw.githubusercontent.com");
const QString githubUser("NissimHadar");
const QString testsRepo("hifi_tests");
const QString branch("addRecursionToAutotester");
foreach(QString currentFilename, sortedTestResultsFilenames) { foreach(QString currentFilename, sortedTestResultsFilenames) {
QString fullCurrentFilename = pathToTestResultsDirectory + "/" + currentFilename; QString fullCurrentFilename = pathToTestResultsDirectory + "/" + currentFilename;
if (isInSnapshotFilenameFormat(currentFilename)) { if (isInSnapshotFilenameFormat(currentFilename)) {
resultImages << fullCurrentFilename; resultImages << fullCurrentFilename;
QString expectedImageDirectory = getExpectedImageDestinationDirectory(currentFilename); QString expectedImagePartialSourceDirectory = getExpectedImagePartialSourceDirectory(currentFilename);
// extract the digits at the end of the filename (exluding the file extension) // extract the digits at the end of the filename (exluding the file extension)
QString expectedImageFilenameTail = currentFilename.left(currentFilename.length() - 4).right(NUM_DIGITS); QString expectedImageFilenameTail = currentFilename.left(currentFilename.length() - 4).right(NUM_DIGITS);
QString expectedImageFilename = EXPECTED_IMAGE_PREFIX + expectedImageFilenameTail + EXPECTED_IMAGE_TYPE; QString expectedImageFilename = EXPECTED_IMAGE_PREFIX + expectedImageFilenameTail + EXPECTED_IMAGE_TYPE;
expectedImages << (expectedImageDirectory + "/" + expectedImageFilename);
QString imageURLString(URLPrefix + "/" + githubUser + "/" + testsRepo + "/" + branch + "/" + expectedImagePartialSourceDirectory + "/" + expectedImageFilename);
expectedImages << imageURLString;
} }
} }
////autoTester->downloadImage(QUrl("http://ribafreixo.com/wp-content/uploads/2017/03/Order-Now-Button-300x113.png")); //autoTester->downloadImage(QUrl("https://raw.githubusercontent.com/NissimHadar/hifi_tests/addRecursionToAutotester/tests/content/entity/zone/ambientLightInheritance/ExpectedImage_00000.jpg"));
////autoTester->downloadImage(QUrl("https://github.com/NissimHadar/hifi_tests/blob/addRecursionToAutotester/tests/content/entity/zone/ambientLightInheritance/ExpectedImage_00000.jpg?raw=true"));
autoTester->downloadImage(QUrl("https://hifi-content.s3.amazonaws.com/nissim/autoTester/resources/ColourBox.jpg")); autoTester->downloadImages(expectedImages);
////bool success = compareImageLists(expectedImages, resultImages, pathToImageDirectory, interactiveMode, progressBar);
////if (success) { ////if (success) {
//// messageBox.information(0, "Success", "All images are as expected"); //// messageBox.information(0, "Success", "All images are as expected");
@ -386,7 +393,7 @@ void Test::createRecursiveScriptsRecursively() {
} }
void Test::createTest() { void Test::createTest() {
// Rename files sequentially, as ExpectedResult_1.jpeg, ExpectedResult_2.jpg and so on // Rename files sequentially, as ExpectedResult_00000.jpeg, ExpectedResult_00001.jpg and so on
// Any existing expected result images will be deleted // Any existing expected result images will be deleted
QString imageSourceDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly); QString imageSourceDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly);
if (imageSourceDirectory == "") { if (imageSourceDirectory == "") {
@ -404,9 +411,9 @@ void Test::createTest() {
exit(-1); exit(-1);
} }
} else if (isInSnapshotFilenameFormat(currentFilename)) { } else if (isInSnapshotFilenameFormat(currentFilename)) {
const int MAX_IMAGES = 100000; const int maxImages = pow(10, NUM_DIGITS);
if (i >= MAX_IMAGES) { if (i >= maxImages) {
messageBox.critical(0, "Error", "More than 100,000 images not supported"); messageBox.critical(0, "Error", "More than " + QString::number(maxImages) + " images not supported");
exit(-1); exit(-1);
} }
QString newFilename = "ExpectedImage_" + QString::number(i - 1).rightJustified(5, '0') + ".jpg"; QString newFilename = "ExpectedImage_" + QString::number(i - 1).rightJustified(5, '0') + ".jpg";
@ -491,7 +498,6 @@ bool Test::isInSnapshotFilenameFormat(QString filename) {
// For a file named "D_GitHub_hifi-tests_tests_content_entity_zone_create_0.jpg", the test directory is // For a file named "D_GitHub_hifi-tests_tests_content_entity_zone_create_0.jpg", the test directory is
// D:/GitHub/hifi-tests/tests/content/entity/zone/create // D:/GitHub/hifi-tests/tests/content/entity/zone/create
// This method assumes the filename is in the correct format // This method assumes the filename is in the correct format
// The final part of the filename is the image number. This is checked for sanity
QString Test::getExpectedImageDestinationDirectory(QString filename) { QString Test::getExpectedImageDestinationDirectory(QString filename) {
QString filenameWithoutExtension = filename.split(".")[0]; QString filenameWithoutExtension = filename.split(".")[0];
QStringList filenameParts = filenameWithoutExtension.split("_"); QStringList filenameParts = filenameWithoutExtension.split("_");
@ -505,6 +511,28 @@ QString Test::getExpectedImageDestinationDirectory(QString filename) {
return result; return result;
} }
// For a file named "D_GitHub_hifi-tests_tests_content_entity_zone_create_0.jpg", the source directory on GitHub
// is ...tests/content/entity/zone/create
// This is used to create the full URL
// This method assumes the filename is in the correct format
QString Test::getExpectedImagePartialSourceDirectory(QString filename) {
QString filenameWithoutExtension = filename.split(".")[0];
QStringList filenameParts = filenameWithoutExtension.split("_");
int i { 0 };
while (filenameParts[i] != "tests") {
++i;
}
QString result = filenameParts[i];
for (int j = i + 1; j < filenameParts.length() - 1; ++j) {
result += "/" + filenameParts[j];
}
return result;
}
bool Test::isInExpectedImageFilenameFormat(QString filename) { bool Test::isInExpectedImageFilenameFormat(QString filename) {
return (expectedImageFilenameFormat.match(filename).hasMatch()); return (expectedImageFilenameFormat.match(filename).hasMatch());
} }

View file

@ -47,6 +47,7 @@ public:
bool isAValidDirectory(QString pathname); bool isAValidDirectory(QString pathname);
QString getExpectedImageDestinationDirectory(QString filename); QString getExpectedImageDestinationDirectory(QString filename);
QString getExpectedImagePartialSourceDirectory(QString filename);
private: private:
const QString TEST_FILENAME { "test.js" }; const QString TEST_FILENAME { "test.js" };

View file

@ -16,6 +16,8 @@ AutoTester::AutoTester(QWidget *parent) : QMainWindow(parent) {
ui.progressBar->setVisible(false); ui.progressBar->setVisible(false);
test = new Test(); test = new Test();
signalMapper = new QSignalMapper();
} }
void AutoTester::on_evaluateTestsButton_clicked() { void AutoTester::on_evaluateTestsButton_clicked() {
@ -50,15 +52,35 @@ void AutoTester::on_closeButton_clicked() {
} }
void AutoTester::downloadImage(QUrl url) { void AutoTester::downloadImage(QUrl url) {
downloader = new Downloader(url, this); downloaders.emplace_back(new Downloader(url, this));
connect(downloaders[_index], SIGNAL (downloaded()), signalMapper, SLOT (map()));
connect(downloader, SIGNAL (downloaded()), this, SLOT (saveImage())); signalMapper->setMapping(downloaders[_index], _index);
++_index;
} }
void AutoTester::saveImage() { void AutoTester::downloadImages(QStringList listOfURLs) {
_numberOfImagesToDownload = listOfURLs.size();
_numberOfImagesDownloaded = 0;
_index = 0;
for (int i = 0; i < _numberOfImagesToDownload; ++i) {
QUrl imageURL(listOfURLs[i]);
downloadImage(imageURL);
}
connect(signalMapper, SIGNAL (mapped(int)), this, SLOT (saveImage(int)));
}
void AutoTester::saveImage(int index) {
QPixmap image; QPixmap image;
image.loadFromData(downloader->downloadedData()); image.loadFromData(downloaders[index]->downloadedData());
int er = image.width();
int df = image.height(); int w = image.width();
image.save("D:/Dicom/lll.jpg"); int h = image.height();
++_numberOfImagesDownloaded;
image.save("D:/Dicom/lll_" + QString::number(index) + ".jpg");
} }

View file

@ -11,6 +11,7 @@
#define hifi_AutoTester_h #define hifi_AutoTester_h
#include <QtWidgets/QMainWindow> #include <QtWidgets/QMainWindow>
#include <QSignalMapper>
#include "ui_AutoTester.h" #include "ui_AutoTester.h"
#include "../Downloader.h" #include "../Downloader.h"
@ -22,6 +23,7 @@ class AutoTester : public QMainWindow {
public: public:
AutoTester(QWidget *parent = Q_NULLPTR); AutoTester(QWidget *parent = Q_NULLPTR);
void downloadImage(QUrl url); void downloadImage(QUrl url);
void downloadImages(QStringList listOfURLs);
private slots: private slots:
void on_evaluateTestsButton_clicked(); void on_evaluateTestsButton_clicked();
@ -32,13 +34,19 @@ private slots:
void on_deleteOldSnapshotsButton_clicked(); void on_deleteOldSnapshotsButton_clicked();
void on_closeButton_clicked(); void on_closeButton_clicked();
void saveImage(); void saveImage(int index);
private: private:
Ui::AutoTesterClass ui; Ui::AutoTesterClass ui;
Test* test; Test* test;
Downloader* downloader; std::vector<Downloader*> downloaders;
QSignalMapper* signalMapper;
int _numberOfImagesToDownload;
int _numberOfImagesDownloaded;
int _index;
}; };
#endif // hifi_AutoTester_h #endif // hifi_AutoTester_h