Skip to content

Commit

Permalink
Enhanced Makefile and narrowed down version in package.json.
Browse files Browse the repository at this point in the history
  • Loading branch information
ypid committed Jan 24, 2015
1 parent 2c5ca71 commit f2a326b
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 74 deletions.
159 changes: 111 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,80 +1,143 @@
NODE?= node
SEARCH?= opening_hours
## Variables {{{
SHELL ?= /bin/sh
NODE ?= node
SEARCH ?= opening_hours

.PHONY : default check build clean test test-normal test-min diff-test diff-test-min download-dependencies release
default: test
WGET_OPTIONS ?= --no-verbose
## }}}

build: opening_hours.min.js
.PHONY : default
default: check

download-dependencies:
.PHONY : dependencies-get
dependencies-get:
npm install

clean:
.PHONY : build
build: opening_hours.min.js

.PHONY : check
check: check-diff-all

.PHONY : benchmark
benchmark: benchmark-opening_hours.js

README.html: README.md

.PHONY : release
release: check-all
editor package.json
$(MAKE) test-package.json
git commit --all
git tag --sign --local-user=EE88E1F0 "v`json -f package.json version`"
git push --tags
npm publish
$(MAKE) publish-website-on-all-servers

.PHONY : clean
clean: osm-tag-data-rm
rm -f *.min.js
rm -f export.*.json
rm -f README.html
rm -f taginfo_sources.json

test-dev: diff-test
## Publish {{{

fulltest: real_test test-dev diff-test-min benchmark
.PHONY : publish-website-on-all-servers
publish-website-on-all-servers: publish-website-on-ypid.de publish-website-on-openingh.openstreetmap.de

test: opening_hours.js test.js
${NODE} test.js "./$<"
.PHONY : publish-website-on-openingh.openstreetmap.de
publish-website-on-openingh.openstreetmap.de:
ssh gauss.osm.de './update'

test-min: opening_hours.min.js test.js
${NODE} test.js "./$<"
.PHONY : publish-website-on-ypid.de
publish-website-on-ypid.de:
ssh [email protected] './update'

%.min.js: %.js
uglifyjs "$<" --output "$@" --comments '/ypid\/opening_hours\.js/' --lint
## }}}

## command line programs {{{
.PHONY : run-regex_search
run-regex_search: export.$(SEARCH).json interactive_testing.js regex_search.py
$(NODE) ./regex_search.py "$<"

.PHONY : run-interactive_testing
run-interactive_testing: interactive_testing.js
$(NODE) "$<"
## }}}

## software testing {{{

.PHONY : check-all
check-all: check-package.json check-test check-diff-all osm-tag-data-update-check

.SILENT: diff-test
diff-test: opening_hours.js test.js
.PHONY : check-diff-all
check-diff-all: check-diff check-diff-opening_hours.min.js

.PHONY : check-diff
check-diff: check-diff-opening_hours.js

.PHONY : check-test
check-test: check-opening_hours.js

# .PHONY : check-opening_hours.js
## Does not work
check-%.js: %.js test.js
-$(NODE) test.js "./$<"

.SILENT: check-diff-opening_hours.js check-diff-opening_hours.min.js
check-diff-%.js: %.js test.js
git checkout HEAD -- test.log
# git checkout master -- test.log
# git checkout 9f323b9d06720b6efffc7420023e746ff8f1b309 -- test.log
${NODE} test.js 1> test.log 2>&1 || echo "Test results for $< are exactly the same as on developemt system. So far, so good ;)"
$(NODE) test.js 1> test.log 2>&1 || echo "Test results for $< are exactly the same as on developemt system. So far, so good ;)"
# git --no-pager diff --color-words test.log
git --no-pager diff test.log

.SILENT: diff-test-min
diff-test-min: opening_hours.min.js test.js
git checkout HEAD -- test.log
${NODE} test.js "./$<" 1> test.log 2>&1 || echo "Test results for $< are exactly the same as on developemt system. So far, so good ;)"
# git --no-pager diff --color-words test.log
git --no-pager diff test.log
.PHONY : osm-tag-data-check
osm-tag-data-check: real_test.js opening_hours.js osm-tag-data-get-all
$(NODE) "$<"

.PHONY : osm-tag-data-update-check
.SILENT : osm-tag-data-update-check
osm-tag-data-update-check:
-$(MAKE) --quiet osm-tag-data-update-all 2>/dev/null
$(MAKE) --quiet osm-tag-data-check

# .PHONY : benchmark
benchmark-%.js: %.js benchmark.js
$(NODE) ./benchmark.js "$<"

.PHONY : check-package.json
check-package.json: package.json
pjv --warnings --recommendations --filename "$<"

benchmark: opening_hours.js benchmark.js
${NODE} benchmark.js
## }}}

real_test: opening_hours.js real_test.js all-osm-tags
${NODE} real_test.js
## OSM data from taginfo {{{

## See real_test.js
real_test-stats: real_test.opening_hours.stats.csv
${NODE} check_for_new_taginfo_data.js
make clean
make real_test
.PHONY : osm-tag-data-gen-stats
osm-tag-data-gen-stats: real_test.opening_hours.stats.csv osm-tag-data-update-check

.PHONY : regex_search
regex_search: export.$(SEARCH).json interactive_testing.js
./regex_search.py $<
.PHONY : osm-tag-data-rm
osm-tag-data-rm:
rm -f export.*.json

interactive_testing: interactive_testing.js
${NODE} interactive_testing.js
.PHONY : osm-tag-data-update-all
osm-tag-data-update-all:
$(NODE) ./check_for_new_taginfo_data.js
$(MAKE) osm-tag-data-rm
$(MAKE) osm-tag-data-get-all

all-osm-tags: export.opening_hours.json export.lit.json export.opening_hours\:kitchen.json export.opening_hours\:warm_kitchen.json export.smoking_hours.json export.collection_times.json export.service_times.json export.fee.json export.happy_hours.json export.delivery_hours.json export.opening_hours\:delivery.json
.PHONY : osm-tag-data-get-all
osm-tag-data-get-all: export.opening_hours.json export.lit.json export.opening_hours\:kitchen.json export.opening_hours\:warm_kitchen.json export.smoking_hours.json export.collection_times.json export.service_times.json export.fee.json export.happy_hours.json export.delivery_hours.json export.opening_hours\:delivery.json

export.%.json:
wget -O "$(shell echo "$@" | sed 's/\\//g' )" "http://taginfo.openstreetmap.org/api/4/key/values?key=$(shell echo "$@" | sed 's/^export\.\(.*\)\.json/\1/;s/\\//g' )"
wget $(WGET_OPTIONS) --output-document="$(shell echo "$@" | sed 's/\\//g' )" "http://taginfo.openstreetmap.org/api/4/key/values?key=$(shell echo "$@" | sed 's/^export\.\(.*\)\.json/\1/;s/\\//g' )" 2>&1
## }}}

release: clean fulltest
editor package.json
git commit --all
git tag --sign --local-user=EE88E1F0 "v`npm view opening_hours version |head --lines 1`"
git push --tags
npm publish

README.html: README.md
%.min.js: %.js
uglifyjs "$<" --output "$@" --comments '/ypid\/opening_hours\.js/' --lint

%.html: %.md
pandoc --from markdown_github --to html --standalone $< --output $@
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,21 +470,21 @@ This project has become so complex that development without extensive testing wo

### Regression testing

Simple node.js based test framework is bundled. You can run it with `node test.js` or with `make test`.
Simple node.js based test framework is bundled. You can run it with `node test.js` or with `make check`.

The current results of this test are also tracked in the repository and can be viewed [here](/test.log). Run `make test-dev` to compare the test results with the results from the last commit. Note that this file uses [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code) which can be interpreted by cat in the terminal.
The current results of this test are also tracked in the repository and can be viewed [here](/test.log). Run `make check-test` to compare the test results with the results from the last commit. Note that this file uses [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code) which can be interpreted by cat in the terminal.

### Testing with real data

#### Large scale

To see how this library performances in the real OpenStreetMap world you can run `make real_test` or `node real_test.js` (data needs to be exported first) to try to process every value which uses the opening_hours syntax from [taginfo][] with this library.
To see how this library performances in the real OpenStreetMap world you can run `make osm-tag-data-check` or `node real_test.js` (data needs to be exported first) to try to process every value which uses the opening_hours syntax from [taginfo][] with this library.

Currently (March 2014) this library can parse 97 % (245639/253588) of all opening_hours values in OSM. If identical values appear multiple times then each value counts.

#### Small scale

Python script to search with regular expressions over OSM opening_hours style tags is bundled. You can run it with `make regex_search` or `./regex_search.py` which will search on the opening_hours tag. To search over different tags either use `make regex_search SEARCH=$tagname` (this also makes sure that the tag you would like to search on will be downloaded if necessary) or run `./regex_search.py $path_to_downloaded_taginfo_json_file`.
Python script to search with regular expressions over OSM opening_hours style tags is bundled. You can run it with `make run-regex_search` or `./regex_search.py` which will search on the opening_hours tag. To search over different tags either use `make run-regex_search "SEARCH=$tagname"` (this also makes sure that the tag you would like to search on will be downloaded if necessary) or run `./regex_search.py $path_to_downloaded_taginfo_json_file`.

This script not only shows you if the found value can be processed with this library or not, it also indicates using different colors if the facility is currently open (open: green, unknown: magenta, closed: blue).

Expand All @@ -497,7 +497,7 @@ To improve the speed of fixing errors, a [feature](https://github.com/ypid/openi

### Test it yourself (the geeky way)

You want to try some opening_hours yourself? Just run `make interactive_testing` or `node interactive_testing.js` which will open an primitive interpreter. Just write your opening_hours value and hit enter and you will see if it can be processed (with current state) or not (with error message). The answer is JSON encoded.
You want to try some opening_hours yourself? Just run `make run-interactive_testing` or `node interactive_testing.js` which will open an primitive interpreter. Just write your opening_hours value and hit enter and you will see if it can be processed (with current state) or not (with error message). The answer is JSON encoded.

Testing is much easier by now. Have a look at the [evaluation tool][ohlib.evaluation-tooldemohtml]. The reason why this peace of code was written is to have an interface which can be accessed from other programming languages. It is used by the python module [pyopening\_hours][].

Expand Down
8 changes: 8 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#!/usr/bin/env node

/* Required modules {{{ */
var opening_hours = require('./opening_hours.js');
var opening_hours_lib = process.argv[2];
if (typeof opening_hours_lib !== 'string')
opening_hours_lib = './opening_hours.js';
var opening_hours = require(opening_hours_lib);
/* }}} */

var tests = 3;
var iterations = 40000;
Expand Down
23 changes: 12 additions & 11 deletions check_for_new_taginfo_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,33 @@ function get_dump_creation_time_from_file(file) {
}
/* }}} */

var previous_dump_creation_time = get_dump_creation_time_from_file('taginfo_sources.json');
var local_dump_creation_time = get_dump_creation_time_from_file('taginfo_sources.json');

/* Download source file and compare {{{ */
console.log('Loading file ' + taginfo_api_url + 'site/sources');
var taginfo_api_url_source = taginfo_api_url + 'site/sources';
console.log('Loading file ' + taginfo_api_url_source + ' to check if new data is availale.');
var file = fs.createWriteStream('taginfo_sources.json');
var request = http.get(taginfo_api_url + 'site/sources', function(response) {
var request = http.get(taginfo_api_url_source, function(response) {
response.pipe(file);

response.on('error', function(err) {
throw("Got error: " + err.message);
});

response.on('end', function() {
var current_dump_creation_time = get_dump_creation_time_from_file('taginfo_sources.json');
var upstream_dump_creation_time = get_dump_creation_time_from_file('taginfo_sources.json');

if (typeof previous_dump_creation_time == 'object')
console.log("Previous creation time: " + previous_dump_creation_time);
if (typeof local_dump_creation_time == 'object')
console.log("Local taginfo data was generated on: " + local_dump_creation_time);

if (typeof previous_dump_creation_time == 'object'
&& previous_dump_creation_time.getTime() == current_dump_creation_time.getTime()) {
if (typeof local_dump_creation_time == 'object'
&& local_dump_creation_time.getTime() == upstream_dump_creation_time.getTime()) {

console.log("Nothing new.");
console.log("Not newer then local data.");
process.exit(1);
} else {
console.log("New data available.");
console.log("Current creation time: " + current_dump_creation_time.toISOString());
console.log("New data available");
console.log("Taginfo data was generated on: " + upstream_dump_creation_time.toISOString());
process.exit(0);
}
});
Expand Down
2 changes: 1 addition & 1 deletion hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ git stash -q --keep-index
# # Redirect output to stderr.
# exec 1>&2

make diff-test NODE=nodejs
make check-diff-all
git add test.log

git stash pop -q
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,26 @@
"doc": "./doc"
},
"scripts": {
"test" : "make test",
"real_test" : "make real_test",
"benchmark" : "make benchmark",
"build" : "make clean && make build",
"interactive_testing": "make interactive_testing"
"build" : "make build",
"test" : "make check",
"osm-tag-data-check" : "make osm-tag-data-check",
"benchmark" : "make benchmark",
"interactive_testing" : "make run-interactive_testing",
"regex_search" : "make run-regex_search"
},
"dependencies": {
"suncalc": ">=1.2.1"
"suncalc": "1.2.1"
},
"optionalDependencies": {
"i18next": ">=1.6.3",
"moment" : "2.7.x"
},
"devDependencies": {
"colors" : ">=0.6.2",
"uglify-js" : ">=2.0.0",
"sprintf-js": ">=0.0.7"
"colors" : "0.6.*",
"uglify-js" : ">=2.0.0",
"sprintf-js" : ">=0.0.7",
"json" : ">=9.0.3",
"package-json-validator" : ">=0.1.8"
},
"engines": {
"node": ">=0.8"
Expand Down

0 comments on commit f2a326b

Please sign in to comment.