<commit_before>import React from 'react'
import ReactHighcharts from 'react-highcharts'
import Content from './content'
import AppBarContainer from './appbarContainer'
import Error from './error'
import DropDownMenu from 'material-ui/lib/DropDownMenu'
import MenuItem from 'material-ui/lib/menus/menu-item'
import Loading from './loading'
import Highcharts from 'highcharts'

Highcharts.setOptions({
  global: {
    useUTC: false
  }
})

class Chart extends React.Component {
  constructor(props) {
    super(props)
    this.getTemperatures = this.getTemperatures.bind(this)
    this.getTemperatures('day')
    this.state = {
      dateRange: 'day'
    }
  }
  onDateRangeChange(value) {
    if (this.state.dateRange !== value) {
      this.setState({ dateRange: value })
      this.getTemperatures(value)
    }
  }
  getTemperatures(from, to = Date.now()) {
    const now = Date.now()
    switch (from) {
      case 'hours':
        return this.props.getTemperatures({
          from: now - 6 * 60 * 60 * 1000,
          to
        })
      case 'day':
        return this.props.getTemperatures({
          from: now - 24 * 60 * 60 * 1000,
          to
        })
      case 'week':
        return this.props.getTemperatures({
          from: now - 7 * 24 * 60 * 60 * 1000,
          to
        })
      case 'month':
        return this.props.getTemperatures({
          from: now - 30 * 24 * 60 * 60 * 1000,
          to
        })
      default:
        return this.props.getTemperatures({ from, to })
    }
  }
  renderContent() {
    if (this.props.temperatures.loading) {
      return <Loading />
    }

    if (this.props.temperatures.error) {
      return <Error message='Failed to retrieve temperatures' />
    }

    const temperatures = this.props.temperatures.data
    const temperatureReadings = temperatures.map(({ temperature }) => temperature)
    const minTemperature = Math.min(...temperatureReadings) - 2
    const maxTemperature = Math.max(...temperatureReadings) + 1

    // add empty data poins between too large intervals to make highchart not connect series between those points
    const missing = []
    this.props.temperatures.data.forEach((temperature, index) => {
      const nextTemperature = temperatures.length > index + 1 ? temperatures[index + 1] : null
      if (nextTemperature && nextTemperature.createdAt > temperature.createdAt + 5 * 60 * 1000) {
        missing.push({
          createdAt: temperature.createdAt + 1000
        })
      }
    })
    const temperaturesWithMissingData = temperatures.concat(missing).sort((a, b) => a.createdAt < b.createdAt ? -1 : 1)

    const config = {
      chart: {
        zoomType: 'x',
        spacingLeft: 0,
        spacingRight: 0
      },
      title: {
        text: false
      },
      xAxis: {
        type: 'datetime'
      },
      yAxis: {
        title: {
          text: null
        },
        labels: {
          format: '{value} °C'
        },
        tickInterval: 1,
        allowDecimals: false,
        startOnTick: false,
        min: minTemperature,
        max: maxTemperature
      },
      series: [
        {
          name: 'Target',
          type: 'area',
          fillOpacity: 0.5,
          turboThreshold: 1,
          color: '#90A4AE',
          data: temperatures.map(({ createdAt, targetTemperature }) => {
            return [createdAt, parseFloat(targetTemperature.toFixed(1))]
          })
        },
        {
          name: 'Actual',
          type: 'area',
          fillOpacity: 0.5,
          turboThreshold: 1,
          color: '#FFD54F',
          data: temperaturesWithMissingData.map(({ createdAt, temperature }) => {
            return [createdAt, temperature ? parseFloat(temperature.toFixed(1)) : null]
          })
        },
        {
          name: 'Controlled',
          type: 'line',
          turboThreshold: 1,
          color: '#81C784',
          linecap: 'square',
          lineWidth: 5,
          data: temperatures
          .map(({ createdAt, controlled }) => {
            return [createdAt, controlled ? maxTemperature : null]
          })
        },
        {
          name: 'Cooling',
          type: 'line',
          turboThreshold: 1,
          color: '#4FC3F7',
          linecap: 'square',
          lineWidth: 20,
          data: temperatures.map(({ createdAt, status }) => {
            return [createdAt, status === 2 ? minTemperature : null]
          })
        }
      ]
    }

    return (
      <div>
        <div style={{ textAlign: 'center' }}>
          <DropDownMenu
            value={this.state.dateRange}
            onChange={(event, index, value) => this.onDateRangeChange(value)}
            style={{ minWidth: 100 }}
            >
            <MenuItem
              value={'hours'}
              primaryText='6 Hours'
              />
            <MenuItem<commit_msg>chart: shared tooltip<commit_after>import React from 'react'
import ReactHighcharts from 'react-highcharts'
import Content from './content'
import AppBarContainer from './appbarContainer'
import Error from './error'
import DropDownMenu from 'material-ui/lib/DropDownMenu'
import MenuItem from 'material-ui/lib/menus/menu-item'
import Loading from './loading'
import Highcharts from 'highcharts'

Highcharts.setOptions({
  global: {
    useUTC: false
  }
})

class Chart extends React.Component {
  constructor(props) {
    super(props)
    this.getTemperatures = this.getTemperatures.bind(this)
    this.getTemperatures('day')
    this.state = {
      dateRange: 'day'
    }
  }
  onDateRangeChange(value) {
    if (this.state.dateRange !== value) {
      this.setState({ dateRange: value })
      this.getTemperatures(value)
    }
  }
  getTemperatures(from, to = Date.now()) {
    const now = Date.now()
    switch (from) {
      case 'hours':
        return this.props.getTemperatures({
          from: now - 6 * 60 * 60 * 1000,
          to
        })
      case 'day':
        return this.props.getTemperatures({
          from: now - 24 * 60 * 60 * 1000,
          to
        })
      case 'week':
        return this.props.getTemperatures({
          from: now - 7 * 24 * 60 * 60 * 1000,
          to
        })
      case 'month':
        return this.props.getTemperatures({
          from: now - 30 * 24 * 60 * 60 * 1000,
          to
        })
      default:
        return this.props.getTemperatures({ from, to })
    }
  }
  renderContent() {
    if (this.props.temperatures.loading) {
      return <Loading />
    }

    if (this.props.temperatures.error) {
      return <Error message='Failed to retrieve temperatures' />
    }

    const temperatures = this.props.temperatures.data
    const temperatureReadings = temperatures.map(({ temperature }) => temperature)
    const minTemperature = Math.min(...temperatureReadings) - 2
    const maxTemperature = Math.max(...temperatureReadings) + 1

    // add empty data poins between too large intervals to make highchart not connect series between those points
    const missing = []
    this.props.temperatures.data.forEach((temperature, index) => {
      const nextTemperature = temperatures.length > index + 1 ? temperatures[index + 1] : null
      if (nextTemperature && nextTemperature.createdAt > temperature.createdAt + 5 * 60 * 1000) {
        missing.push({
          createdAt: temperature.createdAt + 1000
        })
      }
    })
    const temperaturesWithMissingData = temperatures.concat(missing).sort((a, b) => a.createdAt < b.createdAt ? -1 : 1)

    const config = {
      chart: {
        zoomType: 'x',
        spacingLeft: 0,
        spacingRight: 0
      },
      title: {
        text: false
      },
      tooltip: {
        shared: true,
        valueDecimals: 1
      },
      xAxis: {
        type: 'datetime'
      },
      yAxis: {
        title: {
          text: null
        },
        labels: {
          format: '{value} °C'
        },
        tickInterval: 1,
        allowDecimals: false,
        startOnTick: false,
        min: minTemperature,
        max: maxTemperature
      },
      series: [
        {
          name: 'Target',
          type: 'area',
          fillOpacity: 0.5,
          turboThreshold: 1,
          color: '#90A4AE',
          data: temperatures.map(({ createdAt, targetTemperature }) => {
            return [createdAt, parseFloat(targetTemperature.toFixed(1))]
          })
        },
        {
          name: 'Actual',
          type: 'area',
          fillOpacity: 0.5,
          turboThreshold: 1,
          color: '#FFD54F',
          data: temperaturesWithMissingData.map(({ createdAt, temperature }) => {
            return [createdAt, temperature ? parseFloat(temperature.toFixed(1)) : null]
          })
        },
        {
          name: 'Controlled',
          type: 'line',
          turboThreshold: 1,
          enableMouseTracking: false,
          color: '#81C784',
          linecap: 'square',
          lineWidth: 5,
          data: temperatures
          .map(({ createdAt, controlled }) => {
            return [createdAt, controlled ? maxTemperature : null]
          })
        },
        {
          name: 'Cooling',
          type: 'line',
          turboThreshold: 1,
          enableMouseTracking: false,
          color: '#4FC3F7',
          linecap: 'square',
          lineWidth: 20,
          data: temperatures.map(({ createdAt, status }) => {
            return [createdAt, status === 2 ? minTemperature : null]
          })
        }
      ]
    }

    return (
      <div>
        <div style={{ textAlign: 'center' }}>
          <DropDownMenu
            value={this.state.dateRange}
            onChange={(event, index, value) => this.onDateRangeChange(value)}
            style={{ minWidth: 100 }}
            >
            <MenuItem
              value={'hours'}
              primaryText='6 Hours'
              />
            <MenuItem
{'fraction_non_alphanumeric': 0.11940298507462686, 'fraction_numerical': 0.01898669915727485, 'mean_word_length': 1.8402537485582469, 'pattern_counts': {'":': 0, '<': 19, '<?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': '4522431', 'n_tokens_mistral': 2985, 'n_tokens_neox': 2791, 'n_words': 670}