Пример #1
0
    def _download_results(self, job_id):
        result_r = self.session.get("{}/{}/all".format(self.BATCH_URL, job_id),
                                    params=self.credentials_params,
                                    timeout=(self.connect_timeout, self.read_timeout))
        root_zip = zipfile.ZipFile(io.BytesIO(result_r.content))

        results = []
        for name in root_zip.namelist():
            if name.endswith('_out.txt'):
                reader = csv.DictReader(root_zip.open(name), delimiter='|')
                for row in reader:
                    if row['SeqNumber'] == '1':  # First per requested data
                        precision = self.PRECISION_BY_MATCH_TYPE.get(
                            row.get('matchType'), PRECISION_INTERPOLATED)
                        match_type = self.MATCH_TYPE_BY_MATCH_LEVEL.get(row['matchLevel'], None)
                        results.append((row['recId'],
                                        [row['displayLongitude'], row['displayLatitude']],
                                        geocoder_metadata(
                                            float(row['relevance']),
                                            precision,
                                            [match_type] if match_type else []
                                        )))
                    elif row['matchLevel'] == 'NOMATCH':
                        results.append((row['recId'], [], {}))
                    elif row['matchLevel'] == 'FAILED':
                        results.append((row['recId'], [], {'error': 'Bulk geocoder failed'}))
        return results
Пример #2
0
 def _extract_metadata_from_result(self, result):
     # See https://stackoverflow.com/questions/51285622/missing-matchtype-at-here-geocoding-responses
     precision = self.PRECISION_BY_MATCH_TYPE.get(result.get('MatchType'),
                                                  PRECISION_INTERPOLATED)
     match_type = self.MATCH_TYPE_BY_MATCH_LEVEL.get(
         result['MatchLevel'], None)
     return geocoder_metadata(result['Relevance'], precision,
                              [match_type] if match_type else [])
Пример #3
0
 def _extract_metadata_from_result(self, result):
     score = self._normalize_score(result['score'])
     match_type = MATCH_TYPE_BY_MATCH_LEVEL.get(result['type'], None)
     return geocoder_metadata(
         score,
         self._precision_from_score(score),
         [match_type] if match_type else []
     )
Пример #4
0
 def _extract_metadata_from_result(self, result):
     location_type = result['geometry']['location_type']
     base_relevance = RELEVANCE_BY_LOCATION_TYPE[location_type]
     partial_match = result.get('partial_match', False)
     partial_factor = PARTIAL_FACTOR if partial_match else 1
     match_types = [
         MATCH_TYPE_BY_MATCH_LEVEL.get(match_level, None)
         for match_level in result['types']
     ]
     return geocoder_metadata(base_relevance * partial_factor,
                              PRECISION_BY_LOCATION_TYPE[location_type],
                              filter(None, match_types))
Пример #5
0
    def _extract_metadata_from_result(self, result):
        if result[ENTRY_GEOMETRY].get('interpolated', False):
            precision = PRECISION_INTERPOLATED
        else:
            precision = PRECISION_PRECISE

        match_types = [MATCH_TYPE_BY_MATCH_LEVEL.get(match_level, None)
                       for match_level in result['place_type']]
        return geocoder_metadata(
            self._normalize_relevance(float(result['relevance'])),
            precision,
            filter(None, match_types)
        )