Skip to content
Snippets Groups Projects
Commit 0acb6f70 authored by Nathaniel Manista's avatar Nathaniel Manista
Browse files

Cosmetic tweaks to Python Route Guide

parent 191628f3
No related branches found
No related tags found
No related merge requests found
...@@ -39,10 +39,9 @@ _TIMEOUT_SECONDS = 30 ...@@ -39,10 +39,9 @@ _TIMEOUT_SECONDS = 30
def make_route_note(message, latitude, longitude): def make_route_note(message, latitude, longitude):
route_note = route_guide_pb2.RouteNote(message=message) return route_guide_pb2.RouteNote(
route_note.location.latitude = latitude message=message,
route_note.location.longitude = longitude location=route_guide_pb2.Point(latitude=latitude, longitude=longitude))
return route_note
def guide_get_one_feature(stub, point): def guide_get_one_feature(stub, point):
...@@ -63,11 +62,11 @@ def guide_get_feature(stub): ...@@ -63,11 +62,11 @@ def guide_get_feature(stub):
def guide_list_features(stub): def guide_list_features(stub):
rect = route_guide_pb2.Rectangle() rect = route_guide_pb2.Rectangle(
rect.lo.latitude = 400000000 lo=route_guide_pb2.Point(
rect.lo.longitude = -750000000 latitude=400000000, longitude = -750000000),
rect.hi.latitude = 420000000 hi=route_guide_pb2.Point(
rect.hi.longitude = -730000000 latitude = 420000000, longitude = -730000000))
print "Looking for features between 40, -75 and 42, -73" print "Looking for features between 40, -75 and 42, -73"
features = stub.ListFeatures(rect, _TIMEOUT_SECONDS) features = stub.ListFeatures(rect, _TIMEOUT_SECONDS)
......
...@@ -73,20 +73,16 @@ class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer): ...@@ -73,20 +73,16 @@ class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer):
def GetFeature(self, request, context): def GetFeature(self, request, context):
feature = get_feature(self.db, request) feature = get_feature(self.db, request)
if not feature: if feature is None:
feature = route_guide_pb2.Feature( return route_guide_pb2.Feature(name="", location=request)
name="", else:
location=route_guide_pb2.Point( return feature
latitude=request.latitude, longitude=request.longitude))
return feature
def ListFeatures(self, request, context): def ListFeatures(self, request, context):
lo = request.lo left = min(request.lo.longitude, request.hi.longitude)
hi = request.hi right = max(request.lo.longitude, request.hi.longitude)
left = min(lo.longitude, hi.longitude) top = max(request.lo.latitude, request.hi.latitude)
right = max(lo.longitude, hi.longitude) bottom = min(request.lo.latitude, request.hi.latitude)
top = max(lo.latitude, hi.latitude)
bottom = min(lo.latitude, hi.latitude)
for feature in self.db: for feature in self.db:
if (feature.location.longitude >= left and if (feature.location.longitude >= left and
feature.location.longitude <= right and feature.location.longitude <= right and
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment