<commit_before>/**
 * Dependencies
 */

var convert = require('convert');
var domify = require('domify');
var d3 = require('d3');
var reactive = require('reactive');
var session = require('session');
var svg = require('svg-icons');
var view = require('view');

/**
 * Significant Ratio
 */

var SRATIO = 1 / 10;

/**
 * Create black to red color conversion
 */

var diffcolor = d3.scale.linear()
  .domain([0, 60])
  .range(['#333333', '#d9534f']);

/**
 * Expose `View`
 */

var View = module.exports = view(require('./template.html'), function(view,
  model) {

  // get max
  var max = maxTripLength();
  var width = function(t) {
    return t / max * 100 + '%';
  };

  var segments = significantSegments(model);

  d3.select(view.el)
    .select('.summary-segments')
    .selectAll('.segment')
    .data(segments)
    .enter()
    .append('div')
    .attr('class', function(d) {
      var name = 'segment';
      if (d.type === 'bus' || d.type === 'train') name += ' white';
      return name;
    })
    .style('width', function() {
      return 1 / segments.length * 100 + '%';
    })
    .style('color', function(d) {
      return d.color;
    })
    .style('background-color', function(d) {
      if (d.type === 'train') {
        return convert.toBSColor(d.bg);
      } else if (d.type === 'bus') {
        return 'gray';
      }
      return d.bg;
    })
    .html(function(d) {
      var html = svg(d.type);
      if (d.type === 'bus') html += '<span class="name">' + d.text.toUpperCase() +
        '</span>';
      html += '<div class="clearfix"></div>';
      return html;
    });

  d3.select(view.el)
    .on('mouseover', function() {
      window.transitive.focusJourney(model.id);
    })
    .on('mouseout', function() {
      window.transitive.focusJourney();
    });
});

/**
 * Show / Hide Details
 */

View.prototype.showHideDetails = function() {
  var $details = this.find('.details');
  if ($details.classList.contains('hidden')) $details.classList.remove('hidden');
  else $details.classList.add('hidden');
};

/**
 * Average Time
 */

View.prototype.average = function() {
  return Math.round(this.model.stats.avg / 60);
};

/**
 * Total Walk Distance
 */

View.prototype.totalWalkDistance = function() {
  if (this.model.summary === 'Car' || this.model.summary === 'Bicycle') {
    return false;
  }

  return convert.metersToMiles(this.model.segments.reduce(function(memo,
    segment) {
    return memo + segment.walkTime;
  }, this.model.finalWalkTime) * 1.4);
};

/**
 * Detail template
 */

var template = require('./detail.html');
var detail = function(obj) {
  return reactive(domify(template), obj).el;
};

/**
 * Details
 */

View.prototype.details = function() {
  var segments = this.model.segments;
  var from = session.plan().from().split(',')[0];
  var to = session.plan().to().split(',')[0];
  var details = document.createDocumentFragment();

  // Add a detail
  function addDetail(d) {
    details.appendChild(detail(d));
  }

  // Starting Address
  addDetail({
    description: from,
    icon: '<i class="icon from fa fa-fw fa-dot-circle-o"></i>',
    type: 'address'
  });

  // Add transit segments
  var length = segments.length;
  for (var i = 0; i < length; i++) {
    var segment = segments[i];

    // Check for a walking distance
    if (segment.walkTime === 0) {
      // Add transfer
      addDetail({
        description: 'Transfer at station',
        icon: '',
        time: Math.round(segment.waitStats.avg / 60),
      });
    } else {
      addDetail({
        description: 'Walk to ' + segment.fromName,
        icon: svg('pedestrian'),
        time: Math.round(segment.walkTime / 60),
        type: 'pedestrian'
      });
    }

    var color = segment.type === 'train' ? convert.toBSColor(segment.routeShortName) :
      'gray';

    var description = '<p>' + segment.fromName + '</p>' + '<p>&nbsp;</p>' +
      '<p>' + segment.toName + '</p>';

    addDetail({
      description: description,
      icon: svg(segment.type),
      name: segment.routeShortName.toUpperCase(),
      style: 'color: #fff;fill: #fff; background-color: ' + color + ';',
      time: Math.round(segment.rideStats.avg / 60),
      type: segment.type
    });
  }

  if (segments.length === 0) {<commit_msg>Fix for when routeShortNames don't exist<commit_after>/**
 * Dependencies
 */

var convert = require('convert');
var domify = require('domify');
var d3 = require('d3');
var reactive = require('reactive');
var session = require('session');
var svg = require('svg-icons');
var view = require('view');

/**
 * Significant Ratio
 */

var SRATIO = 1 / 10;

/**
 * Create black to red color conversion
 */

var diffcolor = d3.scale.linear()
  .domain([0, 60])
  .range(['#333333', '#d9534f']);

/**
 * Expose `View`
 */

var View = module.exports = view(require('./template.html'), function(view,
  model) {

  // get max
  var max = maxTripLength();
  var width = function(t) {
    return t / max * 100 + '%';
  };

  var segments = significantSegments(model);

  d3.select(view.el)
    .select('.summary-segments')
    .selectAll('.segment')
    .data(segments)
    .enter()
    .append('div')
    .attr('class', function(d) {
      var name = 'segment';
      if (d.type === 'bus' || d.type === 'train') name += ' white';
      return name;
    })
    .style('width', function() {
      return 1 / segments.length * 100 + '%';
    })
    .style('color', function(d) {
      return d.color;
    })
    .style('background-color', function(d) {
      if (d.type === 'train') {
        return convert.toBSColor(d.bg);
      } else if (d.type === 'bus') {
        return 'gray';
      }
      return d.bg;
    })
    .html(function(d) {
      var html = svg(d.type);
      if (d.type === 'bus' && d.text) {
        html += '<span class="name">' + d.text.toUpperCase() + '</span>';
      }
      html += '<div class="clearfix"></div>';
      return html;
    });

  d3.select(view.el)
    .on('mouseover', function() {
      window.transitive.focusJourney(model.id);
    })
    .on('mouseout', function() {
      window.transitive.focusJourney();
    });
});

/**
 * Show / Hide Details
 */

View.prototype.showHideDetails = function() {
  var $details = this.find('.details');
  if ($details.classList.contains('hidden')) $details.classList.remove('hidden');
  else $details.classList.add('hidden');
};

/**
 * Average Time
 */

View.prototype.average = function() {
  return Math.round(this.model.stats.avg / 60);
};

/**
 * Total Walk Distance
 */

View.prototype.totalWalkDistance = function() {
  if (this.model.summary === 'Car' || this.model.summary === 'Bicycle') {
    return false;
  }

  return convert.metersToMiles(this.model.segments.reduce(function(memo,
    segment) {
    return memo + segment.walkTime;
  }, this.model.finalWalkTime) * 1.4);
};

/**
 * Detail template
 */

var template = require('./detail.html');
var detail = function(obj) {
  return reactive(domify(template), obj).el;
};

/**
 * Details
 */

View.prototype.details = function() {
  var segments = this.model.segments;
  var from = session.plan().from().split(',')[0];
  var to = session.plan().to().split(',')[0];
  var details = document.createDocumentFragment();

  // Add a detail
  function addDetail(d) {
    details.appendChild(detail(d));
  }

  // Starting Address
  addDetail({
    description: from,
    icon: '<i class="icon from fa fa-fw fa-dot-circle-o"></i>',
    type: 'address'
  });

  // Add transit segments
  var length = segments.length;
  for (var i = 0; i < length; i++) {
    var segment = segments[i];

    // Check for a walking distance
    if (segment.walkTime === 0) {
      // Add transfer
      addDetail({
        description: 'Transfer at station',
        icon: '',
        time: Math.round(segment.waitStats.avg / 60),
      });
    } else {
      addDetail({
        description: 'Walk to ' + segment.fromName,
        icon: svg('pedestrian'),
        time: Math.round(segment.walkTime / 60),
        type: 'pedestrian'
      });
    }

    var color = segment.type === 'train' ? convert.toBSColor(segment.routeShortName) :
      'gray';

    var description = '<p>' + segment.fromName + '</p>' + '<p>&nbsp;</p>' +
      '<p>' + segment.toName + '</p>';

    addDetail({
      description: description,
      icon: svg(segment.type),
      name: (segment.routeShortName ? segment.routeShortName.toUpperCase() : ''),
      style: 'color: #fff;fill: #fff; background-color: ' + color + ';',
      time: Math.round(segment.rideStats.avg / 60),
      type: segment.type
    });
  }

  if (segments.length === 0) {
{'fraction_non_alphanumeric': 0.18889277797223195, 'fraction_numerical': 0.010033835025084587, 'mean_word_length': 2.7367044463818657, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, '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': '5756388', 'n_tokens_mistral': 2887, 'n_tokens_neox': 2790, 'n_words': 615}