Skip to content

Commit

Permalink
server
Browse files Browse the repository at this point in the history
  • Loading branch information
philipperemy committed Nov 7, 2023
1 parent 8f4c1bc commit 01e992b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def country_codes():
try:
req = request
alpha_2 = _str2bool(req.args.get('alpha_2', False))
result = nd.get_country_codes(alpha_2=alpha_2)
result = nd.get_country_codes(alpha_2=alpha_2, cache=True)
return _generate_output({'result': result})
except Exception as e:
return _generate_output({'error': str(e)})
Expand Down
12 changes: 7 additions & 5 deletions names_dataset/nd_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def _fuzzy_search(
if country_alpha2 is not None:
if country_alpha2 not in ranks:
continue
measure = ranks[country_alpha2]
rank = ranks[country_alpha2]
else:
measure = int(sum(ranks.values()) / len(ranks))
result.append({'name': name[0], 'measure': measure})
result = sorted(result, key=lambda x: x['measure'])[0:n]
rank = int(sum(ranks.values()) / len(ranks))
result.append({'name': name[0], 'rank': rank})
result = sorted(result, key=lambda x: x['rank'])[0:n]
return result


Expand Down Expand Up @@ -186,7 +186,9 @@ def search(self, name: str):
ln = self._post_process(self.last_names.get(key)) if self.last_names is not None else None
return {'first_name': fn, 'last_name': ln}

def get_country_codes(self, alpha_2=False):
def get_country_codes(self, alpha_2=False, cache: bool = False):
if cache and alpha_2:
return self.country_codes
lookup_table = self.first_names if self.first_names is not None else self.last_names
countries_list = [list(a['country'].keys()) for a in lookup_table.values()]
countries = set()
Expand Down

0 comments on commit 01e992b

Please sign in to comment.