<commit_before>/** Change dwell times */

import React, { Component, PropTypes } from 'react'
import uuid from 'uuid'

import SelectRouteAndPatterns from './select-route-and-patterns'
import SelectStops from './select-stops'
import colors from './colors'

const selectedStopStyle = {
  radius: 4,
  color: colors.MODIFIED
}

export default class AdjustDwellTime extends Component {
  static propTypes = {
    modification: PropTypes.object.isRequired,
    replaceModification: PropTypes.func.isRequired
  };

  constructor (props) {
    super(props)

    this.onNameChange = this.onNameChange.bind(this)
    this.onPatternSelectorChange = this.onPatternSelectorChange.bind(this)
    this.onStopSelectorChange = this.onStopSelectorChange.bind(this)
    this.setScale = this.setScale.bind(this)
    this.setSpeed = this.setSpeed.bind(this)
    this.setValue = this.setValue.bind(this)
  }

  onNameChange (e) {
    this.props.replaceModification(Object.assign({}, this.props.modification, { name: e.target.value }))
  }

  onPatternSelectorChange (value) {
    let { feed, routes, trips } = value
    let modification = Object.assign({}, this.props.modification, { feed, routes, trips, stops: null })
    this.props.replaceModification(modification)
  }

  onStopSelectorChange (stops) {
    this.props.replaceModification(Object.assign({}, this.props.modification, { stops }))
  }

  /** we are setting a scale for existing speeds, not an actual speed */
  setScale (e) {
    if (e.target.checked) this.props.replaceModification(Object.assign({}, this.props.modification, { scale: true }))
  }

  /** we are setting a brand-new speed, throwing out any existing variation in speed */
  setSpeed (e) {
    if (e.target.checked) this.props.replaceModification(Object.assign({}, this.props.modification, { scale: false }))
  }

  /** set the factor by which we are scaling, or the speed which we are replacing */
  setValue (e) {
    this.props.replaceModification(Object.assign({}, this.props.modification, { value: e.target.value }))
  }

  render () {
    return <div>
      <input type='text' placeholder='name' value={this.props.modification.name} onChange={this.onNameChange} />

      <SelectRouteAndPatterns routes={this.props.modification.routes} feed={this.props.modification.feed} trips={this.props.modification.trips} onChange={this.onPatternSelectorChange}
        addLayer={this.props.addLayer} removeLayer={this.props.removeLayer} addControl={this.props.addControl} removeControl={this.props.removeControl} />

      {(() => {
        if (this.props.modification.routes != null) {
          return <SelectStops routes={this.props.modification.routes} feed={this.props.modification.feed} trips={this.props.modification.trips} 
             stops={this.props.modification.stops} nullIsWildcard={true} onChange={this.onStopSelectorChange}
             addLayer={this.props.addLayer} removeLayer={this.props.removeLayer} addControl={this.props.addControl} removeControl={this.props.removeControl} />
        } else return <span/>
      })()}

      <label><input type='radio' value='scale' checked={this.props.modification.scale} onChange={this.setScale} />Scale existing dwell times by</label>
      <label><input type='radio' value='speed' checked={!this.props.modification.scale} onChange={this.setSpeed} />Set new dwell time to</label>

      <label><input type='number' step='any' value={this.props.modification.value} onChange={this.setValue} />{ this.props.modification.scale ? 'x' : 'seconds' }</label>
    </div>
  }
}

export function create () {
  return {
    id: uuid.v4(),
    type: 'adjust-dwell-time',
    feed: null,
    routes: null,
    trips: null,
    stops: null,
    value: 30,<commit_msg>make adjust dwell time use unified data fetching, #23.<commit_after>/** Change dwell times */

import React, { Component, PropTypes } from 'react'
import uuid from 'uuid'

import SelectRouteAndPatterns from './select-route-and-patterns'
import SelectStops from './select-stops'
import colors from './colors'

const selectedStopStyle = {
  radius: 4,
  color: colors.MODIFIED
}

export default class AdjustDwellTime extends Component {
  static propTypes = {
    modification: PropTypes.object.isRequired,
    replaceModification: PropTypes.func.isRequired
  };

  constructor (props) {
    super(props)

    this.onNameChange = this.onNameChange.bind(this)
    this.onPatternSelectorChange = this.onPatternSelectorChange.bind(this)
    this.onStopSelectorChange = this.onStopSelectorChange.bind(this)
    this.setScale = this.setScale.bind(this)
    this.setSpeed = this.setSpeed.bind(this)
    this.setValue = this.setValue.bind(this)
  }

  onNameChange (e) {
    this.props.replaceModification(Object.assign({}, this.props.modification, { name: e.target.value }))
  }

  onPatternSelectorChange (value) {
    let { feed, routes, trips } = value
    let modification = Object.assign({}, this.props.modification, { feed, routes, trips, stops: null })
    this.props.replaceModification(modification)
  }

  onStopSelectorChange (stops) {
    this.props.replaceModification(Object.assign({}, this.props.modification, { stops }))
  }

  /** we are setting a scale for existing speeds, not an actual speed */
  setScale (e) {
    if (e.target.checked) this.props.replaceModification(Object.assign({}, this.props.modification, { scale: true }))
  }

  /** we are setting a brand-new speed, throwing out any existing variation in speed */
  setSpeed (e) {
    if (e.target.checked) this.props.replaceModification(Object.assign({}, this.props.modification, { scale: false }))
  }

  /** set the factor by which we are scaling, or the speed which we are replacing */
  setValue (e) {
    this.props.replaceModification(Object.assign({}, this.props.modification, { value: e.target.value }))
  }

  render () {
    return <div>
      <input type='text' placeholder='name' value={this.props.modification.name} onChange={this.onNameChange} />

      <SelectRouteAndPatterns routes={this.props.modification.routes} feed={this.props.modification.feed} trips={this.props.modification.trips} onChange={this.onPatternSelectorChange}
        addLayer={this.props.addLayer} removeLayer={this.props.removeLayer} addControl={this.props.addControl} removeControl={this.props.removeControl} data={this.props.data} />

      {(() => {
        if (this.props.modification.routes != null) {
          return <SelectStops routes={this.props.modification.routes} feed={this.props.modification.feed} trips={this.props.modification.trips} 
             stops={this.props.modification.stops} nullIsWildcard={true} onChange={this.onStopSelectorChange} data={this.props.data}
             addLayer={this.props.addLayer} removeLayer={this.props.removeLayer} addControl={this.props.addControl} removeControl={this.props.removeControl} />
        } else return <span/>
      })()}

      <label><input type='radio' value='scale' checked={this.props.modification.scale} onChange={this.setScale} />Scale existing dwell times by</label>
      <label><input type='radio' value='speed' checked={!this.props.modification.scale} onChange={this.setSpeed} />Set new dwell time to</label>

      <label><input type='number' step='any' value={this.props.modification.value} onChange={this.setValue} />{ this.props.modification.scale ? 'x' : 'seconds' }</label>
    </div>
  }
}

export function create () {
  return {
    id: uuid.v4(),
    type: 'adjust-dwell-time',
    feed: null,
    routes: null,
    trips: null,
    stops: null,
    value: 30,
{'fraction_non_alphanumeric': 0.13810979662368736, 'fraction_numerical': 0.0013292569453675395, 'mean_word_length': 4.090663058186739, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, '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': '3185831', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2269, 'n_words': 473}