Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.pyc
__pycache__/
*.dist-info/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ deploy:
cp -rf smarty "$(QGIS_PLUGINS_DIR)/smarty"

redeploy: deploy
osascript -e 'quit app "QGIS"'
killall QGIS > /dev/null 2>&1 || true
open -a QGIS

vendor:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
smartystreets-python-sdk==6.1.0
git+ssh://git@github.com/smarty/summary.git@v0.1.1
2 changes: 1 addition & 1 deletion smarty/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name=Smarty
qgisMinimumVersion=3.0
description=Smarty Geocoding QGIS Plugin
version=1.0.14
version=1.0.15
author=Smarty
email=osgeo-it@smarty.com

Expand Down
25 changes: 13 additions & 12 deletions smarty/smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from smartystreets_python_sdk import StaticCredentials, exceptions, ClientBuilder, SharedCredentials, Batch, Request
from smartystreets_python_sdk.us_street import Lookup as StreetLookup
from smartystreets_python_sdk.us_autocomplete_pro import Lookup as AutocompleteProLookup
from summary import summary
#########

# Initialize Qt resources from file resources.py
Expand Down Expand Up @@ -345,8 +346,8 @@ def smarty_single(self):
self.dlg.dst_result.setText(str(dst))

# Check if the candidate returned is good to plot.
success = Utils.handle_success(result)
if success == "No Match - The address is invalid.":
success = self.handle_success(result)
if success == "No Match":
self.dlg.resize(586, 532)
self.dlg.results.setVisible(True)
self.dlg.summary_result.setText(success)
Expand Down Expand Up @@ -623,7 +624,7 @@ def process_batch(self, batch_meta, id_column_name, address, city, state, zip, l
feature.setGeometry(QgsGeometry.fromPointXY(point_out))

# Handle success of address lookup
success = Utils.handle_success(candidates)
success = self.handle_success(candidates)

# Set attributes for associated layer
feature.setAttributes([lookup_id, address_result, longitude, latitude, city_result, state_result, zip_result, zip_4, precision, county,
Expand Down Expand Up @@ -1017,15 +1018,15 @@ def autocomplete_state(self):
self.dlg.single_address_lookup.setCompleter(None)

def handle_success(self, result): # Handle and determine the success of the API request
if Utils.is_valid(result):
return "valid_address"
if Utils.is_invalid(result):
return "invalid_address"
if Utils.is_missing_secondary(result):
return "missing_secondary"
if Utils.is_ambiguous(result):
return "ambiguous_address"
return "MAJOR ERROR"
enhanced_match = ""
dpv_match_code = ""
dpv_footnotes = ""
if len(result) > 0:
candidate = result[0]
enhanced_match = candidate.analysis.enhanced_match
dpv_match_code = candidate.analysis.dpv_match_code
dpv_footnotes = candidate.analysis.dpv_footnotes
return summary(enhanced_match, dpv_match_code, dpv_footnotes)

def output_csv(self, layer_out):
# Throw error if the file path has not been chosen
Expand Down
1 change: 0 additions & 1 deletion smarty/smartystreets_python_sdk-6.1.0.dist-info/INSTALLER

This file was deleted.

30 changes: 0 additions & 30 deletions smarty/smartystreets_python_sdk-6.1.0.dist-info/METADATA

This file was deleted.

171 changes: 0 additions & 171 deletions smarty/smartystreets_python_sdk-6.1.0.dist-info/RECORD

This file was deleted.

Empty file.
5 changes: 0 additions & 5 deletions smarty/smartystreets_python_sdk-6.1.0.dist-info/WHEEL

This file was deleted.

202 changes: 0 additions & 202 deletions smarty/smartystreets_python_sdk-6.1.0.dist-info/licenses/LICENSE.md

This file was deleted.

2 changes: 0 additions & 2 deletions smarty/smartystreets_python_sdk-6.1.0.dist-info/top_level.txt

This file was deleted.

63 changes: 63 additions & 0 deletions smarty/summary/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
MESSAGE_MATCH = 'Match'
MESSAGE_MATCH_WITH_EXCEPTION = 'Match With Exceptions'
MESSAGE_NO_MATCH = 'No Match'

ENHANCED_NO_MATCH = 'none'
ENHANCED_POSTAL_MATCH = 'postal-match'
ENHANCED_NON_POSTAL_MATCH = 'non-postal-match'
ENHANCED_MISSING_SECONDARY = 'missing-secondary'
ENHANCED_UNKNOWN_SECONDARY = 'unknown-secondary'
ENHANCED_IGNORED_INPUT = 'ignored-input'

DPV_MILITARY_MATCH = 'F1'
DPV_BOX_NUMBER_MISSING = 'P1'
DPV_CONFIRMED_PMB = 'RR'
DPV_CONFIRMED_WITHOUT_PMB = 'R1'
DPV_PHANTOM_CARRIER_ROUTE = 'R7'
DPV_UNIQUE_ZIP_CODE = 'U1'
DPV_TRAILING_ALPHA = 'TA'

_dpv_exception_set = {
DPV_MILITARY_MATCH,
DPV_BOX_NUMBER_MISSING,
DPV_CONFIRMED_PMB,
DPV_CONFIRMED_WITHOUT_PMB,
DPV_PHANTOM_CARRIER_ROUTE,
DPV_UNIQUE_ZIP_CODE,
DPV_TRAILING_ALPHA,
}


def _has_dpv_footnote_exceptions(dpv_footnotes: str) -> bool:
if dpv_footnotes is None:
return False
return any(dpv_footnotes[i:i+2] in _dpv_exception_set for i in range(0, len(dpv_footnotes) - 1, 2))


def _enhanced_match_summary(enhanced_match: str, dpv_footnotes: str) -> str:
is_postal_match = False
has_enhanced_exception = False
for val in enhanced_match.split(','):
if val in (ENHANCED_POSTAL_MATCH, ENHANCED_NON_POSTAL_MATCH):
is_postal_match = True
elif val in (ENHANCED_MISSING_SECONDARY, ENHANCED_UNKNOWN_SECONDARY, ENHANCED_IGNORED_INPUT):
has_enhanced_exception = True
if not is_postal_match:
return MESSAGE_NO_MATCH
if has_enhanced_exception or _has_dpv_footnote_exceptions(dpv_footnotes):
return MESSAGE_MATCH_WITH_EXCEPTION
return MESSAGE_MATCH


def _dpv_match_code_summary(dpv_match_code: str, dpv_footnotes: str) -> str:
if dpv_match_code == 'Y':
return MESSAGE_MATCH_WITH_EXCEPTION if _has_dpv_footnote_exceptions(dpv_footnotes) else MESSAGE_MATCH
if dpv_match_code in ('S', 'D'):
return MESSAGE_MATCH_WITH_EXCEPTION
return MESSAGE_NO_MATCH


def summary(enhanced_match: str, dpv_match_code: str, dpv_footnotes: str) -> str:
if enhanced_match:
return _enhanced_match_summary(enhanced_match, dpv_footnotes)
return _dpv_match_code_summary(dpv_match_code, dpv_footnotes)
Loading
Loading