Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating TestNominatim.py #929

Merged
merged 94 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
ceaddc7
Creating TestNominatim.py
nataliejschultz Jul 21, 2023
dbce159
Multiple changes for nominatim testing
nataliejschultz Aug 10, 2023
067158c
Cleaning up the PR to try out nominatim test.
nataliejschultz Aug 11, 2023
b7e77fb
Top of workflow edits
nataliejschultz Aug 14, 2023
0aed377
TestNominiatm Changes
nataliejschultz Aug 15, 2023
01a3b4d
Update TestNominatim.py
nataliejschultz Aug 15, 2023
fd453e6
Testing GH workflow file
nataliejschultz Aug 15, 2023
ce51ed8
Python command not found test + compose updates
nataliejschultz Aug 17, 2023
7efa164
Environment variables + prints
nataliejschultz Aug 17, 2023
f8e9512
Environment variable setup, small testing changes, removing TestNomin…
nataliejschultz Aug 21, 2023
6b9d98d
URL testing
nataliejschultz Aug 22, 2023
2bb9e66
URL Testing pt 2
nataliejschultz Aug 22, 2023
3b76ac1
Removing lsof
nataliejschultz Aug 22, 2023
927a6f7
Network naming change
nataliejschultz Aug 22, 2023
1ada684
"Universal" network removal
nataliejschultz Aug 22, 2023
c9135ed
Multiple network changes
nataliejschultz Aug 22, 2023
ccc1c46
Reverting; new ideas.
nataliejschultz Aug 22, 2023
ed91603
Health check + env variable moved
nataliejschultz Aug 22, 2023
b072a89
Remove restart on failure
nataliejschultz Aug 22, 2023
6794eae
Sleep command added
nataliejschultz Aug 22, 2023
93420dc
More sleep
nataliejschultz Aug 22, 2023
9af4e2e
Adding mock to bypass place_id.
nataliejschultz Aug 24, 2023
b6bb7cb
Implementing Dockerize
nataliejschultz Aug 28, 2023
867287d
Adding timeout
nataliejschultz Aug 28, 2023
bdc70ae
More timeout
nataliejschultz Aug 28, 2023
86d51e4
Fake place creation + geofabrik testing functionality
nataliejschultz Sep 14, 2023
eba9d4d
Query URL woes
nataliejschultz Sep 14, 2023
18ba878
Syntax error
nataliejschultz Sep 14, 2023
53c3e1e
Env variable testing + changing test_get_json_geo
nataliejschultz Sep 15, 2023
7c3fcbd
Temp change
nataliejschultz Sep 15, 2023
cc09fee
trying to get workflow to go on my nominatim branch
nataliejschultz Sep 15, 2023
dbdd359
Trying to get workflow unstuck
nataliejschultz Sep 15, 2023
4b1608d
Fixing workflow
nataliejschultz Sep 18, 2023
9b2ad65
Testing workflow yet again
nataliejschultz Sep 18, 2023
9f4f819
Removing schedule temporarily
nataliejschultz Sep 18, 2023
0283672
Trying to get this workflow to run!!!
nataliejschultz Sep 18, 2023
dbe4fa4
Still not succeeding
nataliejschultz Sep 18, 2023
e89ae7e
Removing tail
nataliejschultz Sep 18, 2023
5cf4a0d
Test worked! Now onto the variables.
nataliejschultz Sep 18, 2023
2c7418e
Get method test
nataliejschultz Sep 18, 2023
2b0c1e6
Test string
nataliejschultz Sep 19, 2023
1ddc01b
Formatting change
nataliejschultz Sep 19, 2023
72e4b77
Reinstating get method
nataliejschultz Sep 19, 2023
60d2b6b
Moving envs
nataliejschultz Sep 19, 2023
8f2c032
Moving env vars around
nataliejschultz Sep 19, 2023
f29c601
Trying to pass in environment variable
nataliejschultz Sep 19, 2023
fc5d0f7
Oops
nataliejschultz Sep 19, 2023
ed51883
Moving things around (again)
nataliejschultz Sep 19, 2023
e61066b
Removing brackets
nataliejschultz Sep 19, 2023
8e0c222
Moving (again!!)
nataliejschultz Sep 19, 2023
db2ea77
Only setting env var once
nataliejschultz Sep 20, 2023
182132f
Commenting out env
nataliejschultz Sep 20, 2023
aa11c5a
Geofabrik formatted!
nataliejschultz Sep 20, 2023
b9d500e
Modifying test_geofabrik_and_nominatim
nataliejschultz Sep 20, 2023
baa6bee
Fixing test_get_json_geo
nataliejschultz Sep 20, 2023
7a1974f
Modifying test_nominatim_aapi
nataliejschultz Sep 21, 2023
e941b5f
Constraining both results
nataliejschultz Sep 21, 2023
8377b59
Using new container with preloaded data
nataliejschultz Sep 26, 2023
ebb77f5
New image
nataliejschultz Sep 26, 2023
90b7063
Testing new docker image
nataliejschultz Sep 27, 2023
5fbf161
Testing entrypoint
nataliejschultz Sep 27, 2023
4c9c915
Testing 4.0 version
nataliejschultz Sep 27, 2023
ec73542
More edits
nataliejschultz Sep 28, 2023
4d46b20
Removing ground truth
nataliejschultz Sep 28, 2023
d1bdecb
Fixing print; removing db port
nataliejschultz Sep 28, 2023
8cc7187
Removing webserver
nataliejschultz Sep 28, 2023
88b0030
Removing port 8080!
nataliejschultz Sep 28, 2023
8a6d339
Re-adding port 8080
nataliejschultz Sep 29, 2023
1e90c65
createfakeplace.py + removing dockerize + setup_integrationtests.sh
nataliejschultz Oct 3, 2023
5050a66
Another whitespace
nataliejschultz Oct 3, 2023
518fdb3
Removing db.conf
nataliejschultz Oct 3, 2023
09e240f
The big one!
nataliejschultz Oct 9, 2023
80519bb
Cleanup
nataliejschultz Oct 9, 2023
d31df8c
Cleanup (2)
nataliejschultz Oct 11, 2023
efb963c
Emission network only
nataliejschultz Oct 11, 2023
a55a9ad
Workflow test
nataliejschultz Oct 11, 2023
3ce7e5b
Reverting workflow (final push?!)
nataliejschultz Oct 11, 2023
b779c1f
Pull on paths
nataliejschultz Oct 18, 2023
1c7cb3c
Removing port 8080 (again)
nataliejschultz Oct 18, 2023
693407e
Merge branch 'nominatim' of https://github.com/nataliejschultz/e-miss…
nataliejschultz Oct 18, 2023
70ff4ab
Re-Adding port 8080 (again)
nataliejschultz Oct 18, 2023
fa508ad
Pulling repo secret
nataliejschultz Oct 19, 2023
a6be71a
Replacing secret
nataliejschultz Oct 19, 2023
451a428
Setting secret as env var in workflow file
nataliejschultz Oct 19, 2023
b027485
Switching to using docker_user until I figure this out.
nataliejschultz Oct 19, 2023
2000144
Secret issues
nataliejschultz Oct 24, 2023
e3b93eb
Adding quotes
nataliejschultz Oct 24, 2023
0b9e455
Updating readme + Making sure the test still works (running on fork)
nataliejschultz Oct 26, 2023
ce2db01
Getting test to run on my branch again
nataliejschultz Oct 26, 2023
3bf52de
Removing port 8080 (yet again!!)
nataliejschultz Oct 30, 2023
8c2efb0
Re-adding port + setup changes
nataliejschultz Oct 31, 2023
b7e0165
Re-instating schedule (test will fail but that is expected)
nataliejschultz Oct 31, 2023
f5c35a0
Testing removing port export but still specifying 8080 in container url
nataliejschultz Oct 31, 2023
baf087a
Re-instating schedule (for the last time?!)
nataliejschultz Nov 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/nominatim-docker-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: nominatim-docker-test

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
# pull_request:
# branches:
# - master

schedule:
# Run every Sunday at 4:05 am
- cron: '5 4 * * 0'
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: Workflow test
run: echo Smoke test

- name: Test nominatim
run: docker-compose -f emission/integrationTests/docker-compose.yml up --exit-code-from web-server
1 change: 1 addition & 0 deletions bin/debug/save_ground_truth.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def save_ct_list(args):

parser_diary = subparsers.add_parser('diary', help='diary-based ground truth')
parser_diary.add_argument("date", help="date to retrieve ground truth (YYYY-MM-DD)")
parser_diary.add_argument("file_name", help="file name to store the result to")
shankari marked this conversation as resolved.
Show resolved Hide resolved
parser_diary.set_defaults(func=save_diary)

parser_obj_list = subparsers.add_parser('objects', help='download analysis objects directly')
Expand Down
54 changes: 54 additions & 0 deletions emission/individual_tests/TestNominatim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import *
import unittest
import os
from emission.core.wrapper.trip_old import Coordinate
import emission.net.ext_service.geocoder.nominatim as eco

#temporarily sets NOMINATIM_QUERY_URL to the environment variable for testing.
eco.NOMINATIM_QUERY_URL = os.environ.get("NOMINATIM_QUERY_URL")
# print("query URL:", eco.NOMINATIM_QUERY_URL)
shankari marked this conversation as resolved.
Show resolved Hide resolved

class NominatimTest(unittest.TestCase):

def test_make_url_geo(self):
expected_result = eco.NOMINATIM_QUERY_URL + "/search?q=Providence%2C+Rhode+Island&format=json"
actual_result = eco.Geocoder.make_url_geo("Providence, Rhode Island")
self.assertEqual(expected_result, actual_result)

def test_get_json_geo(self):
expected_result = [{'place_id': 133278818, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright', 'osm_type': 'way', 'osm_id': 121496393, 'lat': '41.824034499999996', 'lon': '-71.41290469687814', 'class': 'amenity', 'type': 'townhall', 'place_rank': 30, 'importance': 0.2257940944999783, 'addresstype': 'amenity', 'name': 'Providence City Hall', 'display_name': 'Providence City Hall, Dorrance Street, Downtown, Providence, Providence County, Rhode Island, 02902, United States', 'boundingbox': ['41.8237547', '41.8243153', '-71.4132816', '-71.4125278']}]
actual_result = eco.Geocoder.get_json_geo("Providence City Hall, Rhode Island")
self.assertEqual(expected_result, actual_result)

def test_geocode(self):
expected_result_lon = Coordinate(41.8239891, -71.4128343).get_lon()
expected_result_lat = Coordinate(41.8239891, -71.4128343).get_lat()
actual_result_lon = eco.Geocoder.geocode("Providence, Rhode Island").get_lon()
actual_result_lat = eco.Geocoder.geocode("Providence, Rhode Island").get_lat()
self.assertEqual(expected_result_lon, actual_result_lon)
self.assertEqual(expected_result_lat, actual_result_lat)


def test_make_url_reverse(self):
expected_result = eco.NOMINATIM_QUERY_URL + "/reverse?lat=41.8239891&lon=-71.4128343&format=json"
actual_result = (eco.Geocoder.make_url_reverse(41.8239891, -71.4128343))
self.assertEqual(expected_result, actual_result)

def test_get_json_reverse(self):
expected_result = {'place_id': 133278818, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright', 'osm_type': 'way', 'osm_id': 121496393, 'lat': '41.824034499999996', 'lon': '-71.41290469687814', 'class': 'amenity', 'type': 'townhall', 'place_rank': 30, 'importance': 0.2257940944999783, 'addresstype': 'amenity', 'name': 'Providence City Hall', 'display_name': 'Providence City Hall, Dorrance Street, Downtown, Providence, Providence County, Rhode Island, 02902, United States', 'address': {'amenity': 'Providence City Hall', 'road': 'Dorrance Street', 'neighbourhood': 'Downtown', 'city': 'Providence', 'county': 'Providence County', 'state': 'Rhode Island', 'ISO3166-2-lvl4': 'US-RI', 'postcode': '02902', 'country': 'United States', 'country_code': 'us'}, 'boundingbox': ['41.8237547', '41.8243153', '-71.4132816', '-71.4125278']}
actual_result = eco.Geocoder.get_json_reverse(41.8239891, -71.4128343)
self.assertEqual(expected_result, actual_result)

def test_reverse_geocode(self):
expected_result = "Providence City Hall, Dorrance Street, Downtown, Providence, Providence County, Rhode Island, 02902, United States"
actual_result = eco.Geocoder.reverse_geocode(41.8239891, -71.4128343)
self.assertEqual(expected_result, actual_result)

if __name__ == '__main__':
unittest.main()
13 changes: 13 additions & 0 deletions emission/integrationTests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# python 3
FROM ubuntu:latest

RUN apt-get update
RUN apt-get install -y curl

# CHANGEME: Create the files that correspond to your configuration in the conf directory
# COPY conf/net/auth/google_auth.json /usr/src/app/conf/net/auth/google_auth.json
COPY start_integration_tests.sh /start_integration_tests.sh

shankari marked this conversation as resolved.
Show resolved Hide resolved
ENV NOMINATIM_QUERY_URL='http://localhost:8080'
shankari marked this conversation as resolved.
Show resolved Hide resolved

CMD ["/bin/bash", "/start_integration_tests.sh"]
30 changes: 30 additions & 0 deletions emission/integrationTests/TestNominatimBeta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import urllib.request, urllib.parse
import json
import unittest
import os

NOMINATIM_QUERY_URL = os.environ.get("NOMINATIM_QUERY_URL")
print("query URL:", NOMINATIM_QUERY_URL)


class TestReverseGeocode(unittest.TestCase):
def testCompareResult(self):
#Didn't use the query in nominatim.json because it would change how we query nominatim regularly.
nominatim_reverse_query = NOMINATIM_QUERY_URL + "/reverse?"
params = {
"lat" : 41.831174,
"lon" : -71.414907,
"format" : "json"
}
encoded_params = urllib.parse.urlencode(params)
url = nominatim_reverse_query + encoded_params
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
parsed_response = json.loads(response.read())
# ndn = nominatim display name
ndn = str(parsed_response.get("display_name"))
#expected display name is a string
edn = "Rhode Island State Capitol Building, 82, Smith Street, Downtown, Providence, Providence County, 02903, United States"
self.assertEqual(ndn, edn)
if __name__ == '__main__':
unittest.main()
60 changes: 60 additions & 0 deletions emission/integrationTests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version: "3"
services:
web-server:
build:
context: .
depends_on:
- db
- nominatim
environment:
- DB_HOST=db
- WEB_SERVER_HOST=0.0.0.0
shankari marked this conversation as resolved.
Show resolved Hide resolved
volumes:
# specify the host directory where the source code should live
# If this is ~/e-mission-server-docker, then you can edit the files at
# ~/e-mission-server-docker/src/e-mission-server/emission/...
# - CHANGEME:/src/
- ..:/src/e-mission-server
networks:
- emission
db:
image: mongo:4.4.0
ports:
- "1234:1234"
shankari marked this conversation as resolved.
Show resolved Hide resolved
deploy:
replicas: 1
restart_policy:
condition: on-failure

#Volumes is the preferred way to persist data generated by a container. In this case we use a volume to persist the contents
#of the data base. Learn more about how to use volumes here: https://docs.docker.com/storage/volumes/
# And learn how to configure volumes in your compose file here: https://docs.docker.com/compose/compose-file/#volume-configuration-reference
volumes:
- mongo-data:/data/db
networks:
- emission
#adding section to incorporate nominatim server functionality
nominatim:
image: mediagis/nominatim
container_name: rhodeisland-nominatim
environment:
- PBF_URL=https://download.geofabrik.de/north-america/us/rhode-island-latest.osm.pbf
- REPLICATION_URL=https://download.geofabrik.de/north-america/us/rhode-island-updates/
- IMPORT_WIKIPEDIA=false
ports:
- "8080:8080"
shankari marked this conversation as resolved.
Show resolved Hide resolved
deploy:
replicas: 1
restart_policy:
condition: on-failure
volumes:
- nominatim-data:/var/lib/postgresql/14/main
networks:
- emission

networks:
emission:

volumes:
mongo-data:
nominatim-data:
24 changes: 24 additions & 0 deletions emission/integrationTests/start_integration_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Run the tests in the docker environment
# Using an automated install
cd /src/e-mission-server

#set database URL using environment variable
echo ${DB_HOST}
if [ -z ${DB_HOST} ] ; then
local_host=`hostname -i`
sed "s_localhost_${local_host}_" conf/storage/db.conf.sample > conf/storage/db.conf
else
sed "s_localhost_${DB_HOST}_" conf/storage/db.conf.sample > conf/storage/db.conf
fi
cat conf/storage/db.conf

echo "Setting up conda..."
source setup/setup_conda.sh Linux-x86_64

echo "Setting up the test environment..."
source setup/setup_tests.sh

echo "Running tests..."
source setup/activate_tests.sh

./runIntegrationTests.sh
47 changes: 11 additions & 36 deletions emission/net/ext_service/geocoder/nominatim.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@
import json

from emission.core.wrapper.trip_old import Coordinate
from pygeocoder import Geocoder as pyGeo ## We fall back on this if we have to

try:
googlemaps_key_file = open("conf/net/ext_service/googlemaps.json")
GOOGLE_MAPS_KEY = json.load(googlemaps_key_file)["api_key"]
googlemaps_key_file.close()
except:
print("google maps key not configured, falling back to nominatim")

try:
nominatim_file = open("conf/net/ext_service/nominatim.json")
NOMINATIM_QUERY_URL = json.load(nominatim_file)["query_url"]
nominatim_file.close()
shankari marked this conversation as resolved.
Show resolved Hide resolved

except:
print("nominatim not configured either, place decoding must happen on the client")

Expand Down Expand Up @@ -54,15 +47,10 @@ def get_json_geo(cls, address):

@classmethod
def geocode(cls, address):
# try:
# jsn = cls.get_json_geo(address)
# lat = float(jsn[0]["lat"])
# lon = float(jsn[0]["lon"])
# return Coordinate(lat, lon)
# except:
# print "defaulting"
return _do_google_geo(address) # If we fail ask the gods

jsn = cls.get_json_geo(address)
lat = float(jsn[0]["lat"])
lon = float(jsn[0]["lon"])
return Coordinate(lat, lon)

@classmethod
def make_url_reverse(cls, lat, lon):
Expand All @@ -73,6 +61,7 @@ def make_url_reverse(cls, lat, lon):
}

query_url = NOMINATIM_QUERY_URL + "/reverse?"
print("=====Query_URL:", query_url)
encoded_params = urllib.parse.urlencode(params)
url = query_url + encoded_params
logging.debug("For reverse geocoding, using URL %s" % url)
Expand All @@ -81,29 +70,15 @@ def make_url_reverse(cls, lat, lon):
@classmethod
def get_json_reverse(cls, lat, lng):
request = urllib.request.Request(cls.make_url_reverse(lat, lng))
print("======request", request)
print(cls.make_url_reverse(lat, lng))
response = urllib.request.urlopen(request)
parsed_response = json.loads(response.read())
logging.debug("parsed_response = %s" % parsed_response)
return parsed_response

@classmethod
def reverse_geocode(cls, lat, lng):
# try:
# jsn = cls.get_json_reverse(lat, lng)
# address = jsn["display_name"]
# return address

# except:
# print "defaulting"
return _do_google_reverse(lat, lng) # Just in case

## Failsafe section
def _do_google_geo(address):
geo = pyGeo(GOOGLE_MAPS_KEY)
results = geo.geocode(address)
return Coordinate(results[0].coordinates[0], results[0].coordinates[1])

def _do_google_reverse(lat, lng):
geo = pyGeo(GOOGLE_MAPS_KEY)
address = geo.reverse_geocode(lat, lng)
return address[0]
jsn = cls.get_json_reverse(lat, lng)
address = jsn["display_name"]
return address
Loading
Loading