<commit_before>var analytics = require('analytics');
var convert = require('convert');
var formatProfile = require('format-otp-profile');
var log = require('log')('plan:update-routes');
var otp = require('otp');
var Route = require('route');

/**
 * Expose `updateRoutes`
 */

module.exports = updateRoutes;

/**
 * Update routes
 */

function updateRoutes(plan, opts, callback) {
  opts = opts || {};

  var done = function(err, res) {
    plan.emit('updating options complete', {
      err: err,
      res: res
    });

    plan.loading(false);
    plan.saveURL();

    if (callback) callback.apply(null, arguments);
  };

  // Check for valid locations
  if (!plan.validCoordinates()) {
    plan.set({
      options: [],
      journey: {
        places: plan.generatePlaces()
      }
    });
    return done('Invalid coordinates.');
  }

  // For event handlers
  plan.loading(true);
  plan.emit('updating options');

  var query = plan.generateQuery();
  var scorer = plan.scorer();

  otp(query, function(err, data) {
    if (err || !data || data.options.length < 1) {
      plan.set({
        options: [],
        journey: {
          places: plan.generatePlaces()
        }
      });
      done(err, data);
    } else {
      // Track the commute
      analytics.track('commute', {
        query: query,
        results: data.options.length
      });

      data.options.forEach(function(o, i) {
        // Add ids to options
        if (o.transit && o.transit.length > 0) {
          o.id = i + '_transit';
        } else {
          o.id = i;
        }
        o = formatProfile.option(o);

        // Filter access modes if they're not reasonable
        filterMode(o, 'CAR', function(a) {
          return a.time < 600;
        });
        filterMode(o, 'BICYCLE', function(a) {
          return a.time < 300;
        });
        filterMode(o, 'WALK', function(a) {
          return a.time > 3600;
        });
      });

      // Score the results
      data.options = scorer.processOptions(data.options);

      // Get the car data
      var driveOption = data.options.filter(function(o) {
        return o.access[0].mode === 'CAR' && (!o.transit || o.transit.length < 1);
      })[0];

      // Populate segments
      populateSegments(data.options, data.journey);

      // Create a new Route object for each option
      for (var i = 0; i < data.options.length; i++) {
        data.options[i] = new Route(data.options[i]);

        if (driveOption) {
          data.options[i].setCarData({
            cost: driveOption.cost,
            emissions: driveOption.emissions,
            time: driveOption.time<commit_msg>Save the direct drive option but dont show it if car is off<commit_after>var analytics = require('analytics');
var convert = require('convert');
var formatProfile = require('format-otp-profile');
var log = require('log')('plan:update-routes');
var otp = require('otp');
var Route = require('route');

/**
 * Expose `updateRoutes`
 */

module.exports = updateRoutes;

/**
 * Update routes
 */

function updateRoutes(plan, opts, callback) {
  opts = opts || {};

  var done = function(err, res) {
    plan.emit('updating options complete', {
      err: err,
      res: res
    });

    plan.loading(false);
    plan.saveURL();

    if (callback) callback.apply(null, arguments);
  };

  // Check for valid locations
  if (!plan.validCoordinates()) {
    plan.set({
      options: [],
      journey: {
        places: plan.generatePlaces()
      }
    });
    return done('Invalid coordinates.');
  }

  // For event handlers
  plan.loading(true);
  plan.emit('updating options');

  var query = plan.generateQuery();
  var scorer = plan.scorer();

  otp(query, function(err, data) {
    if (err || !data || data.options.length < 1) {
      plan.set({
        options: [],
        journey: {
          places: plan.generatePlaces()
        }
      });
      done(err, data);
    } else {
      // Track the commute
      analytics.track('commute', {
        query: query,
        results: data.options.length
      });

      data.options.forEach(function(o, i) {
        // Add ids to options
        if (o.transit && o.transit.length > 0) {
          o.id = i + '_transit';
        } else {
          o.id = i;
        }
        o = formatProfile.option(o);

        // Filter access modes if they're not reasonable
        filterMode(o, 'CAR', function(a) {
          return a.time < 600;
        });
        filterMode(o, 'BICYCLE', function(a) {
          return a.time < 300;
        });
        filterMode(o, 'WALK', function(a) {
          return a.time > 3600;
        });
      });

      // Score the results
      data.options = scorer.processOptions(data.options);

      // Get the car data
      var driveOption = data.options.filter(function(o) {
        return o.access[0].mode === 'CAR' && (!o.transit || o.transit.length < 1);
      })[0];

      // Remove the car option if car is turned off
      if (!plan.car()) {
        data.options = data.options.filter(function(o) {
          return o.access[0].mode !== 'CAR';
        });
      }

      // Populate segments
      populateSegments(data.options, data.journey);

      // Create a new Route object for each option
      for (var i = 0; i < data.options.length; i++) {
        data.options[i] = new Route(data.options[i]);

        if (driveOption) {
          data.options[i].setCarData({
            cost: driveOption.cost,
            emissions: driveOption.emissions,
            time: driveOption.time
{'fraction_non_alphanumeric': 0.1489477503628447, 'fraction_numerical': 0.005986937590711176, 'mean_word_length': 2.1059154929577466, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5081512', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1666, 'n_words': 407}