<commit_before>
import React, { Component } from 'react'
import { Link, browserHistory } from 'react-router'
import firebase from 'APP/fire'
import store from '../store'
const auth = firebase.auth()
const db = firebase.database()

export default class WeatherLocation extends Component {
  constructor(props) {
    super(props)
    this.state = {
      celsius: false,
      locationName: '',
      locationExists: false,
      showHourly1: false,
      showHourly2: false,
      showHourly3: false,
      showHourly4: false,
      hourly1: [],
      hourly2: [],
      hourly3: [],
      hourly4: []
    }

    this.changeUnits = this.changeUnits.bind(this)
    this.saveData = this.saveData.bind(this)
    this.showModal = this.showModal.bind(this)
    this.closeModal = this.closeModal.bind(this)
    this.handleChange = this.handleChange.bind(this)
    this.showHourly = this.showHourly.bind(this)
  }

  handleChange = (e) => {
    e.preventDefault()
    this.setState({
      locationName: e.target.value
    })
  }

  changeUnits = () => {
    this.setState({celsius: !this.state.celsius})
  }

  showModal = () => {
    if (auth && auth.currentUser && auth.currentUser.isAnonymous) {
      window.alert('You must be signed in to save data!')
    } else {
      document.getElementById('saveLocationModal').style.display = 'block'
    }
  }

  closeModal = () => {
    // reset input modal to empty
    this.refs.input.value = ''
    document.getElementById('saveLocationModal').style.display = 'none'
  }

  showHourly = (e) => {
    const whichWell = e.target.getAttribute('data-item')
    let param
    switch (whichWell) {
    case '1':
      param = this.props.routeParams.location1
      break
    case '2':
      param = this.props.routeParams.location2
      break
    case '3':
      param = this.props.routeParams.location3
      break
    case '4':
      param = this.props.routeParams.location4
      break
    }

    db.ref(`usage/${Date()} API Calls:1`).set({
      name: auth.currentUser.displayName || 'Guest',
      userId: auth.currentUser.uid,
      route: param,
      type: 'Hourly Data'
    })

    this.props.getHourly(param)
      .then(() => {
        store.getState()
      })
      .then(() => {
        switch (whichWell) {
        case '1':
          this.setState({hourly1: this.props.hourlyData.hourly})
          this.setState({showHourly1: true})
          break
        case '2':
          this.setState({hourly2: this.props.hourlyData.hourly})
          this.setState({showHourly2: true})
          break
        case '3':
          this.setState({hourly3: this.props.hourlyData.hourly})
          this.setState({showHourly3: true})
          break
        case '4':
          this.setState({hourly4: this.props.hourlyData.hourly})
          this.setState({showHourly4: true})
          break
        }
      })
  }

  saveData = () => {
    let route1, route2, route3, route4, loc1, loc2, loc3, loc4
    if (!this.props.params.location1) {
      route1 = 'empty'
      loc1 = 'empty'
    } else {
      route1 = this.props.params.location1
      loc1 = this.props.currData.location1
    }
    if (!this.props.params.location2) {
      route2 = 'empty'
      loc2 = 'empty'
    } else {
      route2 = this.props.params.location2
      loc2 = this.props.currData.location2<commit_msg>turned hourly button into a toggle<commit_after>
import React, { Component } from 'react'
import { Link, browserHistory } from 'react-router'
import firebase from 'APP/fire'
import store from '../store'
const auth = firebase.auth()
const db = firebase.database()

export default class WeatherLocation extends Component {
  constructor(props) {
    super(props)
    this.state = {
      celsius: false,
      locationName: '',
      locationExists: false,
      showHourly1: false,
      showHourly2: false,
      showHourly3: false,
      showHourly4: false,
      hourly1: [],
      hourly2: [],
      hourly3: [],
      hourly4: []
    }

    this.changeUnits = this.changeUnits.bind(this)
    this.saveData = this.saveData.bind(this)
    this.showModal = this.showModal.bind(this)
    this.closeModal = this.closeModal.bind(this)
    this.handleChange = this.handleChange.bind(this)
    this.showHourly = this.showHourly.bind(this)
  }

  handleChange = (e) => {
    e.preventDefault()
    this.setState({
      locationName: e.target.value
    })
  }

  changeUnits = () => {
    this.setState({celsius: !this.state.celsius})
  }

  showModal = () => {
    if (auth && auth.currentUser && auth.currentUser.isAnonymous) {
      window.alert('You must be signed in to save data!')
    } else {
      document.getElementById('saveLocationModal').style.display = 'block'
    }
  }

  closeModal = () => {
    // reset input modal to empty
    this.refs.input.value = ''
    document.getElementById('saveLocationModal').style.display = 'none'
  }

  showHourly = (e) => {
    const whichWell = e.target.getAttribute('data-item')
    let param
    let alreadyHaveHourly = false
    debugger
    switch (whichWell) {
    case '1':
      param = this.props.routeParams.location1
      if (this.state.hourly1.length) {
        this.setState({hourly1: []})
        this.setState({showHourly1: false})
        alreadyHaveHourly = true
      }
      break 
    case '2':
      param = this.props.routeParams.location2
      if (this.state.hourly2.length) {
        this.setState({hourly2: []})
        this.setState({showHourly2: false})
        alreadyHaveHourly = true
      }
      break
    case '3':
      param = this.props.routeParams.location3
      if (this.state.hourly3.length) {
        this.setState({hourly3: []})
        this.setState({showHourly3: false})
        alreadyHaveHourly = true
      }
      break
    case '4':
      param = this.props.routeParams.location4
      if (this.state.hourly4.length) {
        this.setState({hourly4: []})
        this.setState({showHourly4: false})
        alreadyHaveHourly = true
      }
      break
    }

    if (alreadyHaveHourly) {

    } else {
      db.ref(`usage/${Date()} API Calls:1`).set({
        name: auth.currentUser.displayName || 'Guest',
        userId: auth.currentUser.uid,
        route: param,
        type: 'Hourly Data'
      })

      this.props.getHourly(param)
        .then(() => {
          store.getState()
        })
        .then(() => {
          switch (whichWell) {
          case '1':
            this.setState({hourly1: this.props.hourlyData.hourly})
            this.setState({showHourly1: true})
            break
          case '2':
            this.setState({hourly2: this.props.hourlyData.hourly})
            this.setState({showHourly2: true})
            break
          case '3':
            this.setState({hourly3: this.props.hourlyData.hourly})
            this.setState({showHourly3: true})
            break
          case '4':
            this.setState({hourly4: this.props.hourlyData.hourly})
            this.setState({showHourly4: true})
            break
          }
        })
    }
  }

  saveData = () => {
    let route1, route2, route3, route4, loc1, loc2, loc3, loc4
    if (!this.props.params.location1) {
      route1 = 'empty'
      loc1 = 'empty'
    } else {
      route1 = this.props.params.location1
      loc1 = this.props.currData.location1
    }
    if (!this.props.params.location2) {
      route2 = 'empty'
      loc2 = 'empty'
    } else {
      route2 = this.props.params.location2
      loc2 = this.props.currData.location2
{'fraction_non_alphanumeric': 0.13179020604763178, 'fraction_numerical': 0.015252876639015252, 'mean_word_length': 2.252828546562228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5609204', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2420, 'n_words': 449}