Skip to content

Commit

Permalink
created router for job title normalize endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmundy committed Jul 1, 2016
1 parent 4241450 commit 3b7fc8d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 17 deletions.
6 changes: 3 additions & 3 deletions api/router/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
api.add_resource(AllJobsEndpoint, '/jobs')
api.add_resource(AllSkillsEndpoint, '/skills')
api.add_resource(JobTitleAutocompleteEndpoint, '/jobs/autocomplete')
api.add_resource(JobTitleNormalizeEndpoint, '/2')
api.add_resource(JobTitleFromONetCodeEndpoint, '/3')
api.add_resource(SkillNameAutocompleteEndpoint, '/4')
api.add_resource(SkillNameAutocompleteEndpoint, '/skills/autocomplete')
api.add_resource(JobTitleNormalizeEndpoint, '/jobs/normalize')
api.add_resource(NormalizeSkillNameEndpoint, '/5')
api.add_resource(JobTitleFromONetCodeEndpoint, '/3')
api.add_resource(NormalizedSkillUUIDFromONetCodeEndpoint, '/6')
api.add_resource(AssociatedSkillsForJobEndpoint, '/7')
api.add_resource(AssociatedJobsForJobEndpoint, '/8')
Expand Down
10 changes: 5 additions & 5 deletions api/router/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class JobTitleAutocompleteEndpoint(Resource):
def get(self):
return route_api('jobtitleautocompleteendpoint')

class JobTitleNormalizeEndpoint(Resource):
class SkillNameAutocompleteEndpoint(Resource):
def get(self):
pass
return route_api('skillnameautocompleteendpoint')

class JobTitleFromONetCodeEndpoint(Resource):
class JobTitleNormalizeEndpoint(Resource):
def get(self):
pass
return route_api('jobtitlenormalizeendpoint')

class SkillNameAutocompleteEndpoint(Resource):
class JobTitleFromONetCodeEndpoint(Resource):
def get(self):
pass

Expand Down
6 changes: 3 additions & 3 deletions api/v1_0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
from . endpoints import *

# endpoints go here
api.add_resource(JobTitleNormalizeEndpoint, '/2')
api.add_resource(JobTitleFromONetCodeEndpoint, '/3')
api.add_resource(SkillNameAutocompleteEndpoint, '/4')
api.add_resource(NormalizeSkillNameEndpoint, '/5')
api.add_resource(NormalizedSkillUUIDFromONetCodeEndpoint, '/6')
api.add_resource(AssociatedSkillsForJobEndpoint, '/7')
Expand All @@ -33,4 +31,6 @@
api.add_resource(JobNameFromUUIDEndpoint, '/11')
api.add_resource(AllJobsEndpoint, '/jobs')
api.add_resource(AllSkillsEndpoint, '/skills')
api.add_resource(JobTitleAutocompleteEndpoint, '/jobs/autocomplete')
api.add_resource(JobTitleAutocompleteEndpoint, '/jobs/autocomplete')
api.add_resource(SkillNameAutocompleteEndpoint, '/skills/autocomplete')
api.add_resource(JobTitleNormalizeEndpoint, '/jobs/normalize')
78 changes: 72 additions & 6 deletions api/v1_0/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from . models.jobs_master import JobMaster
from . models.skills_master import SkillMaster
from . models.jobs_alternate_titles import JobAlternateTitle
from . models.jobs_unusual_titles import JobUnusualTitle
from collections import OrderedDict

class AllJobsEndpoint(Resource):
Expand Down Expand Up @@ -63,7 +64,7 @@ def get(self):
search_string = str(args['ends_with'])
query_mode = 'ends_with'
else:
return create_error({'message': 'Invalid query mode specified for autocomplete'}, 400)
return create_error({'message': 'Invalid query mode specified for job title autocomplete'}, 400)

search_string = search_string.replace('"','').strip()
all_suggestions = []
Expand Down Expand Up @@ -91,18 +92,83 @@ def get(self):
else:
return create_error({'message': 'No job title suggestions found'}, 404)

class SkillNameAutocompleteEndpoint(Resource):
def get(self):
args = request.args

query_mode = ''
if args is not None:
if 'begins_with' in args.keys():
search_string = str(args['begins_with'])
query_mode = 'begins_with'
elif 'contains' in args.keys():
search_string = str(args['contains'])
query_mode = 'contains'
elif 'ends_with' in args.keys():
search_string = str(args['ends_with'])
query_mode = 'ends_with'
else:
return create_error({'message': 'Invalid query mode specified for skill name autocomplete'}, 400)

search_string = search_string.replace('"','').strip()
all_suggestions = []

if query_mode == 'begins_with':
results = SkillMaster.query.filter(SkillMaster.skill_name.startswith(search_string)).all()

if query_mode == 'contains':
results = SkillMaster.query.filter(SkillMaster.skill_name.contains(search_string)).all()

if query_mode == 'ends_with':
results = SkillMaster.query.filter(SkillMaster.skill_name.endswith(search_string)).all()

if len(results) == 0:
return create_error({'message': 'No skill name suggestions found'}, 404)

for result in results:
suggestion = {}
suggestion['suggestion'] = result.skill_name
suggestion['uuid'] = result.uuid
all_suggestions.append(suggestion)

return create_response(all_suggestions, 200)
else:
return create_error({'message': 'No skill name suggestions found'}, 404)

class JobTitleNormalizeEndpoint(Resource):
def get(self):
return "endpoint 2"
args = request.args

if args is not None:
if 'title' in args.keys():
search_string = str(args['title'])
else:
return create_error({'message': 'Invalid parameter specified for job normalization'}, 400)

search_string = search_string.replace('"','').strip()
all_suggestions = []

results = JobUnusualTitle.query.filter(JobUnusualTitle.title.contains(search_string)).all()

if len(results) == 0:
return create_error({'message': 'No normalized job title found'}, 404)

for result in results:
suggestion = {}
suggestion['title'] = result.title
suggestion['uuid'] = result.uuid
suggestion['parent_uuid'] = result.job_uuid
suggestion['description'] = result.description
all_suggestions.append(suggestion)

return create_response(all_suggestions, 200)
else:
return create_error({'message': 'No job title suggestions found'}, 404)

class JobTitleFromONetCodeEndpoint(Resource):
def get(self):
return "endpoint 3"

class SkillNameAutocompleteEndpoint(Resource):
def get(self):
return "endpoint 4"

class NormalizeSkillNameEndpoint(Resource):
def get(self):
return "endpoint 5"
Expand Down

0 comments on commit 3b7fc8d

Please sign in to comment.