Skip to content

Commit

Permalink
update accuracy_test
Browse files Browse the repository at this point in the history
  • Loading branch information
nandiheath committed Jan 12, 2019
1 parent a91c7c3 commit 1da3acc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
3 changes: 3 additions & 0 deletions accuracy_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ The main test program written in node.js.
# Simply install the required packages
npm install
# Transpile the javascript from ./../web to dist to run with nodejs
npm run build
# And run the program
node main.js
Expand Down
19 changes: 14 additions & 5 deletions accuracy_test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const csv = require('fast-csv');
const fs = require('fs');
const { spawn } = require('child_process');
const async = require('async');

const moment = require('moment');


// default logger
Expand Down Expand Up @@ -114,13 +114,18 @@ async function runTest(program, file, address) {
}


async function main({ mode = 3, limit = Infinity, outputFile = './result.json' }) {
async function main({ mode = 3, limit = Infinity, outputFile = './result.json', tag}) {
return new Promise(async (resolve, reject) => {
const allTestData = await readTestCases('./data/testcases_ogcio_searchable.csv');
const result = {
total: 0
}


result.date = moment().format('YYYY-MM-DD hh:mm:ss');
if (typeof(tag) === 'string' && tag.length > 0) {
result.tag = tag;
}
if (mode & 2) {
result.py_success = 0;
result.py_failed = [];
Expand Down Expand Up @@ -166,7 +171,8 @@ async function main({ mode = 3, limit = Infinity, outputFile = './result.json' }
if (mode & 1) {
result.js_success_rate = `${result.js_success / result.total}`;
}
fs.writeFileSync(outputFile, JSON.stringify(result, null, 4));

fs.appendFileSync(outputFile, JSON.stringify(result) + '\n');
log(result);
resolve();
})
Expand Down Expand Up @@ -196,14 +202,17 @@ program
program
.description('Run the test cases')
.option('-o, --output [file]', 'Output the test result to the file')
.option('-c, --ci [file]', 'Running in CI mode, will append the percentage to the file')
.option('-l, --limit [n]', 'Limit the number of test cases to run')
.option('-p, --python', 'Running only the python test')
.option('-j, --js', 'Running only the javascript test')
.option('-t, --tag [tag]', 'Save the tag with the result')
.parse(process.argv);


const outputFile = program.output || './results.json';
const ciOutputFile = program.ci || null;
const tag = program.tag;

// bitwise flag: | python | node |
const mode = !program.python | !program.js << 1;
const limit = program.limit || Infinity;
Expand All @@ -214,7 +223,7 @@ if (mode === 0) {
end();
}

main({ mode, limit, outputFile })
main({ mode, limit, outputFile, ciOutputFile, tag })
.then((end) => {
log('Done');
})
Expand Down
5 changes: 5 additions & 0 deletions accuracy_test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions accuracy_test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"es6-promise": "^4.2.5",
"fast-csv": "^2.4.1",
"isomorphic-fetch": "^2.2.1",
"moment": "^2.23.0",
"proj4": "^2.5.0",
"request": "^2.88.0"
},
Expand Down
8 changes: 6 additions & 2 deletions accuracy_test/run_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ if (process.argv.length < 2) {
console.log('{}');
}

const address = encodeURI(process.argv[2]);
const address = process.argv[2];
const n = 100;
const URL = 'https://www.als.ogcio.gov.hk/lookup';



addressResolver.default.queryAddress(address).then(results => {
const result = results[0];
const obj = { geo: result.coordinates().map(coord => ({Latitude: coord.lat + '', Longitude: coord.lng + ''})) };
const obj = {
eng: result.fullAddress('eng'),
chi: result.fullAddress('chi'),
geo: result.coordinates().map(coord => ({Latitude: coord.lat + '', Longitude: coord.lng + ''}))
};
console.log(JSON.stringify(obj));
}).catch(error => {
console.log(error.stack);
Expand Down

0 comments on commit 1da3acc

Please sign in to comment.