Skip to content

Commit

Permalink
Remove google maps dependencies (codeforboston#209)
Browse files Browse the repository at this point in the history
* Remove google maps dependencies
  • Loading branch information
jmartini authored Feb 27, 2019
1 parent c2207bd commit 4dd4a8d
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 316 deletions.
21 changes: 0 additions & 21 deletions mycity/mycity/test/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,6 @@
"postalCode": "02138"
}

# gis_utils.get_closest_feature
GOOGLE_MAPS_JSON = [
{
'Driving distance': 2458,
'Driving distance text': '1.5 mi',
'Driving time': 427,
'Driving time text': '7 mins',
'test': '94 Sawyer Ave Boston, MA'
},
{
'Driving distance': 692625,
'Driving distance text': '430 mi',
'Driving time': 24533,
'Driving time text': '6 hours 49 mins',
'test': '4 Olivewood Ct Greenbelt, MD'
}
]


# gis_utils._get_dest_addresses_from_features
PARKING_LOT_FEATURES = [
[
Expand Down Expand Up @@ -270,7 +251,6 @@
'opts': {
'app_search_desc': None,
'notification_days': None,
'disable_google_geocoder': True,
'disable_social': None,
'app_search_title': None,
'forced_widget_page': None,
Expand All @@ -282,7 +262,6 @@
'disable_print_download': None,
'arcgis_geocoder': None,
'pdf_header_center_html': None,
'google_geocoder': None,
'app_navigation_page2': 'app_navigation_tabs',
'pdf_show_zones': None,
'require_explicit_consent': None,
Expand Down
3 changes: 0 additions & 3 deletions mycity/mycity/test/test_data/google_maps_json_response

This file was deleted.

6 changes: 2 additions & 4 deletions mycity/mycity/test/unit_tests/test_finder_csv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import mycity.utilities.google_maps_utils as g_maps_utils
import mycity.test.unit_tests.base as base
from mycity.utilities.finder.FinderCSV import FinderCSV

Expand All @@ -13,7 +12,7 @@ def test_prep_func(keys):
fake_url = "www.fake.com"
address_key = "Address"
output_speech = "Trying to get {name}, {" + address_key + "}, " \
+ "{" + g_maps_utils.DRIVING_DISTANCE_TEXT_KEY + "}."
+ "{Driving distance text}."
self.request.session_attributes['currentAddress'] = \
'1000 Dorchester Ave'
self.finder = FinderCSV(self.request, fake_url, address_key,
Expand All @@ -24,11 +23,10 @@ def tearDown(self):
super().tearDown()

def test_get_output_speech_with_success(self):
distance = g_maps_utils.DRIVING_DISTANCE_TEXT_KEY
self.finder.set_output_speech({
'Address': '123 Fake St Boston, MA',
'name': 'The Place',
distance: '100 miles away'
'Driving distance text': '100 miles away'
})
self.assertEqual(
"Trying to get The Place, 123 Fake St Boston, MA, 100 miles away.",
Expand Down
34 changes: 0 additions & 34 deletions mycity/mycity/test/unit_tests/test_gis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,10 @@
import mycity.test.test_constants as test_constants
import mycity.test.unit_tests.base as base
import mycity.utilities.gis_utils as gis_utils
import mycity.utilities.google_maps_utils as g_maps_utils


class GISUtilitiesTestCase(base.BaseTestCase):

@mock.patch(
'mycity.utilities.google_maps_utils._get_driving_info',
return_value=test_constants.GOOGLE_MAPS_JSON
)
def test_get_closest_feature(self, mock_get_driving_info):
test_origin = "46 Everdean St Boston, MA"
test_features = [
['close', '94 Sawyer Ave Boston, MA'],
['far', '4 Olivewood Ct Greenbelt, MD']
]
feature_address_index = 1
feature_type = "test"
error_message = "Test error message"
result = gis_utils.get_closest_feature(
test_origin,
feature_address_index,
feature_type,
error_message,
test_features
)
self.assertEqual(
"94 Sawyer Ave Boston, MA",
result[feature_type]
)
self.assertEqual(
'7 mins',
result[g_maps_utils.DRIVING_TIME_TEXT_KEY]
)
self.assertEqual(
'1.5 mi',
result[g_maps_utils.DRIVING_DISTANCE_TEXT_KEY]
)

def test_get_dest_addresses_from_features(self):
to_test = \
gis_utils._get_dest_addresses_from_features(
Expand Down
34 changes: 0 additions & 34 deletions mycity/mycity/test/unit_tests/test_google_maps_utils.py

This file was deleted.

2 changes: 1 addition & 1 deletion mycity/mycity/utilities/finder/Finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def set_output_speech(self, format_keys):

def get_all_destinations(self, records):
"""
Return a list of all destinations to pass to Google Maps API
Return a list of all destinations in the records
:param records: a list of all location records, records are stored as
dictionaries
Expand Down
2 changes: 1 addition & 1 deletion mycity/mycity/utilities/finder/FinderCSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
and modify fields in the returned record for output_speech
formatted string
:param filter: filter that we can use to remove records from csv
file before using google_maps to find distances and
file before using a service to find distances and
driving_times
"""

Expand Down
54 changes: 0 additions & 54 deletions mycity/mycity/utilities/gis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,12 @@
from arcgis.gis import *
from arcgis.features import FeatureLayer
from arcgis.geocoding import geocode
import mycity.utilities.google_maps_utils as g_maps_utils
import logging

logger = logging.getLogger(__name__)

dev_gis = GIS() # this is needed to use geocoding

def get_closest_feature(origin, feature_address_index,
feature_type, error_message, features):
"""
Calculates the nearest feature given an origin
:param origin: String containing starting address we calculate
shortest distance from
:param feature_address_index: index where address in features
is stored
:param feature_type: string describing the type of feature we are
calculating the shortest distance to
:param error_message: string to print if we fail to find a closest feature
:param features: list of features fetched from FeatureServer
:return: dictionary with address, distance, and
driving time for closest feature
"""
logger.debug(
'origin received: ' + str(origin) +
', feature_address_index received:' + str(feature_address_index) +
', feature_type received: ' + str(feature_type) +
', error_message received:' + str(error_message) +
', features received (printing first five):' + str(features[:5]) +
', count(features): ' + str(len(features))
)

dest_addresses = _get_dest_addresses_from_features(
feature_address_index,
features
)
location_driving_info = g_maps_utils._get_driving_info(
origin,
feature_type,
dest_addresses
)
if len(location_driving_info) > 0:
closest_location_info = min(
location_driving_info,
key=lambda x: x[g_maps_utils.DRIVING_DISTANCE_VALUE_KEY]
)
else:
logger.debug(error_message)
closest_location_info = {
feature_type: False,
g_maps_utils.DRIVING_DISTANCE_TEXT_KEY: False,
g_maps_utils.DRIVING_TIME_TEXT_KEY: False
}
closest_location_info = g_maps_utils.parse_closest_location_info(
feature_type,
closest_location_info
)
return closest_location_info


def get_features_from_feature_server(url, query):
"""
Given a url to a City of Boston Feature Server, return a list
Expand Down
Loading

0 comments on commit 4dd4a8d

Please sign in to comment.