From b6c2f52169c8d1745c0fe873f6aa4a5e764eea43 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 19 Feb 2015 15:40:26 -0800 Subject: Switched to using pre-defined list of features --- src/node/examples/route_guide_server.js | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'src/node/examples/route_guide_server.js') diff --git a/src/node/examples/route_guide_server.js b/src/node/examples/route_guide_server.js index b21190d62e..a3fb079215 100644 --- a/src/node/examples/route_guide_server.js +++ b/src/node/examples/route_guide_server.js @@ -27,6 +27,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +var fs = require('fs'); var _ = require('underscore'); var grpc = require('..'); var examples = grpc.load(__dirname + '/route_guide.proto').examples; @@ -47,21 +48,6 @@ var COORD_FACTOR = 1e7; */ var feature_list = []; -/** - * Return a random "word" (alphabetic character sequence) of the given length. - * @param {number} length The length of the word to create - * @return {string} An alphabetic string with the given length. - */ -function randomWord(length) { - var alphabet = 'abcdefghijklmnopqrstuvwxyz'; - var word = ''; - for (var i = 0; i < length; i++) { - // Add a random character from the alphabet to the word - word += alphabet[_.random(0, alphabet.length - 1)]; - } - return word; -} - /** * Get a feature object at the given point, or creates one if it does not exist. * @param {point} point The point to check @@ -78,19 +64,11 @@ function checkFeature(point) { return feature; } } - // If not, create a new one with 50% chance of indicating "no feature present" - var name; - if (_.random(0,1) === 0) { - name = ''; - } else { - name = randomWord(5); - } + var name = ''; feature = { name: name, location: point }; - // Add the feature object to the list and return it - feature_list.push(feature); return feature; } @@ -253,7 +231,11 @@ if (require.main === module) { // If this is run as a script, start a server on an unused port var routeServer = getServer(); routeServer.bind('0.0.0.0:0'); - routeServer.listen(); + fs.readFile(__dirname + '/route_guide_db.json', function(err, data) { + if (err) throw err; + feature_list = JSON.parse(data); + routeServer.listen(); + }); } exports.getServer = getServer; -- cgit v1.2.3