Skip to content

Commit

Permalink
Merge pull request o2r-project#1 from nuest/dev
Browse files Browse the repository at this point in the history
Dev suggestions
  • Loading branch information
Timmimim authored Jul 12, 2017
2 parents 0d0d320 + 7669f4d commit 0fac8a3
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 77 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ If both HTML papers contain an equal number of images, erc-checker writes a new
### Command Line Interface

#### Installation
1. Navigate to the erc-checker base directory
2. run `npm install -g` (you will need to be root)
1. Navigate to the erc-checker base directory
2. Run `npm install -g` (you will need to be root) to use the checker tool from CLI, or just run `npm install`

#### Usage

#### Usage
``` bash
erc-checker [options] <originalHTML> <reproducedHTML> [-o <output>]
```
Expand All @@ -56,7 +57,9 @@ erc-checker [options] <originalHTML> <reproducedHTML> [-o <output>]
<originalHTML> Relative or absolute location of the Original HTML file to be compared.
<reproducedHTML> Relative or absolute location of the Reproduced HTML file to be compared.
```

##### Options:

``` bash
-h, --help output usage information

Expand All @@ -68,6 +71,7 @@ erc-checker [options] <originalHTML> <reproducedHTML> [-o <output>]
```

##### Debug

To _debug_ this tool, set a environment variable **DEBUG**.

Example:
Expand Down Expand Up @@ -104,6 +108,7 @@ However, in the current version, there is no status code returned on successful
This will be fixed in the future.

##### Debug

To receive command line outputs from the erc-checker's node module, please set the environment variable DEBUG first.
E.g. if your project uses the module, start it as such:
``` bash
Expand All @@ -116,8 +121,8 @@ E.g. if your project uses the module, start it as such:

## Debug Loggers


Available DEBUG loggers are:

* index:checkRequestHandling *
* index:ERROR *
* checker:general *
Expand All @@ -131,6 +136,7 @@ Available DEBUG loggers are:
----------------------------------------------------

## License

o2r checker is licensed under Apache License, Version 2.0, see file LICENSE.

Copyright (C) 2016 - o2r project.
Expand Down
171 changes: 98 additions & 73 deletions checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ var boolArrayImageDiffOrdered = [];


function stringifyHTMLandCompare(originalPaperHTML, reproducedPaperHTML, outputName) {

// promises ALL:
// - read file 1
// - read file 2
// ALL:
// - compare image 1
// - compare image 2
// - compare image 3
// THEN:
// -
// - ...

fs.readFile(originalPaperHTML, 'utf-8', function (err, dataOriginal) {
if (err) {
debugERROR("\t\tFileReader for original paper: Unable to read the first (original) file as String. Something has gone wrong.\nMaybe check your input path.".red, err.message);
Expand Down Expand Up @@ -97,7 +109,6 @@ function stringifyHTMLandCompare(originalPaperHTML, reproducedPaperHTML, outputN
setTimeout( function() { checkIfEncodedImagesAreExtracted() }, 20);
}
}


function writeBase64Files() {
if (base64ImagesOriginal.length != base64ImagesReproduced.length) {
Expand Down Expand Up @@ -189,97 +200,111 @@ function stringifyHTMLandCompare(originalPaperHTML, reproducedPaperHTML, outputN
}

function compareImagesQuickNaive(k) {
debugComp("comparing %s", k);

exec("diff tmp_img_Original_" + k + ".png tmp_img_Reproduced_" + k + ".png -s", function (stderr, stdout) {
if(stderr == null) {
// no comparison required, images are equal
boolArrayImageDiffOrdered[k] = false;
if( k == base64ImagesOriginal.length-1) {
setTimeout( function () {
debugComp("\tFinished comparison.".magenta)
reassembleHTMLfromComparedImagesAndText();
}, 5);
}

return;
}

if (stderr != null) {

differingImagePositions[differingImagesCount] = k;
differingImagesCount += 1;
debugComp("\tImage #" + k +": " + stdout);

differingImagePositions[differingImagesCount] = k;
differingImagesCount += 1;

var originalImgWidth, originalImgHeight, reproducedImgWidth, reproducedImgHeight;
var gotImageSizes = false;
var originalImgWidth, originalImgHeight, reproducedImgWidth, reproducedImgHeight;

boolArrayImageDiffOrdered[k] = true;
boolArrayImageDiffOrdered[k] = true;

var get_Original_k_width = new Promise ( function (resolve, reject) {
exec("convert tmp_img_Original_" + k + ".png -ping -format %w info:", function (err, stdout, stderr) {
if (err) {
reject("Getting width of original image #" + k + " failed: " + err + "".red);
} else {
originalImgWidth = stdout;
resolve();
}
});
let get_Original_k_width = new Promise ( function (resolve, reject) {
exec("convert tmp_img_Original_" + k + ".png -ping -format %w info:", function (err, stdout, stderr) {
if (err) {
reject("Getting width of original image #" + k + " failed: " + err + "".red);
} else {
originalImgWidth = stdout;
resolve();
}
});
var get_Original_k_height = new Promise ( function (resolve, reject) {
exec("convert tmp_img_Original_" + k + ".png -ping -format %h info:", function (err, stdout, stderr) {
if (err) {
reject("Getting height of original image #" + k + " failed: " + err + "".red);
} else {
originalImgHeight = stdout;
resolve();
}
});
});
let get_Original_k_height = new Promise ( function (resolve, reject) {
exec("convert tmp_img_Original_" + k + ".png -ping -format %h info:", function (err, stdout, stderr) {
if (err) {
reject("Getting height of original image #" + k + " failed: " + err + "".red);
} else {
originalImgHeight = stdout;
resolve();
}
});
var get_Reproduced_k_width = new Promise ( function (resolve, reject) {
exec("convert tmp_img_Reproduced_" + k + ".png -ping -format %w info:", function (err, stdout, stderr) {
if (err) {
reject("Getting width of reproduced image #" + k + " failed: " + err + "".red);
} else {
reproducedImgWidth = stdout;
resolve();
}
});
});
let get_Reproduced_k_width = new Promise ( function (resolve, reject) {
exec("convert tmp_img_Reproduced_" + k + ".png -ping -format %w info:", function (err, stdout, stderr) {
if (err) {
reject("Getting width of reproduced image #" + k + " failed: " + err + "".red);
} else {
reproducedImgWidth = stdout;
resolve();
}
});
var get_Reproduced_k_height = new Promise ( function (resolve, reject) {
exec("convert tmp_img_Reproduced_" + k + ".png -ping -format %h info:", function (err, stdout, stderr) {
if (err) {
reject("Getting height of reproduced image #" + k + " failed: " + err + "");
} else {
reproducedImgHeight = stdout;
resolve();
}
});
});
let get_Reproduced_k_height = new Promise ( function (resolve, reject) {
exec("convert tmp_img_Reproduced_" + k + ".png -ping -format %h info:", function (err, stdout, stderr) {
if (err) {
reject("Getting height of reproduced image #" + k + " failed: " + err + "");
} else {
reproducedImgHeight = stdout;
resolve();
}
});
});

Promise.all(
get_Original_k_width,
get_Original_k_height,
get_Reproduced_k_width,
get_Reproduced_k_height)
.then(null,
function (reason) {
debugERROR("\t\t"+ reason.red) }
)
.then(resizeImages())
.catch(debugERROR.bind(console));

function resizeImages() {
if((originalImgHeight+originalImgWidth) <= (reproducedImgHeight+reproducedImgWidth)) {
exec("convert tmp_img_Original_" + k + ".png -resize " + reproducedImgWidth + "x" + reproducedImgWidth + "! -quality 100 tmp_img_Original_" + k + ".png")
}
else {
exec("convert tmp_img_Reproduced_" + k + ".png -resize " + originalImgHeight + "x" + originalImgWidth + "! -quality 100 tmp_img_Reproduced_" + k + ".png")
}

Promise.all(get_Original_k_width, get_Original_k_height, get_Reproduced_k_width, get_Reproduced_k_height).then(null, function (reason) { debugERROR("\t\t"+ reason.red) }).then(resizeImages()).catch(debugERROR.bind(console));

function resizeImages() {
if((originalImgHeight+originalImgWidth) <= (reproducedImgHeight+reproducedImgWidth)) {
exec("convert tmp_img_Original_" + k + ".png -resize " + reproducedImgWidth + "x" + reproducedImgWidth + "! -quality 100 tmp_img_Original_" + k + ".png")
}
else {
exec("convert tmp_img_Reproduced_" + k + ".png -resize " + originalImgHeight + "x" + originalImgWidth + "! -quality 100 tmp_img_Reproduced_" + k + ".png")
}
setTimeout( function () {
exec("compare tmp_img_Original_" + k + ".png tmp_img_Reproduced_" + k + ".png tmp_comp_imgOrigRep_" + k +".png",
function (err, stdout, stderr) {
debugComp("Visually compared Image #%s: \nstdout: %s \nstderr: %s \nerr: %s", k, stdout, stderr, err);

setTimeout( function () {
exec("compare tmp_img_Original_" + k + ".png tmp_img_Reproduced_" + k + ".png tmp_comp_imgOrigRep_" + k +".png", function (stdout, stderr, err) {
debugComp("\tVisually compared Image #" + k + "; "+ stdout + "" + stderr + "" + err);
if(err) {
debugERROR("%s", err.message);
return;
}

exec("base64 tmp_comp_imgOrigRep_" + k +".png > tmp_comp_base64_" + k + ".txt", function (stdout, stderr, err) {
debugComp("\tWriting base64 file for Image #" + k + ": " + stdout + "" + stderr + "" + err);
exec("base64 tmp_comp_imgOrigRep_" + k +".png > tmp_comp_base64_" + k + ".txt", function (err, stdout, stderr) {
debugComp("Writing base64 file for Image #%s: \nstdout: %s \nstderr: %s \nerr: %s", k, stdout, stderr, err);
if (k == base64ImagesOriginal.length-1) {
checkIfAllImagesAreDoneComparing();
}
});
})
},5);
}

}

else {
boolArrayImageDiffOrdered[k] = false;
if( k == base64ImagesOriginal.length-1) {
setTimeout( function () {
debugComp("\tFinished comparison.".magenta)
reassembleHTMLfromComparedImagesAndText();
}, 5);
}
}
if (stdout) {
debugComp("\tImage #" + k +": " + stdout);
}, 5);
}
})
}
Expand Down

0 comments on commit 0fac8a3

Please sign in to comment.