<commit_before>import { endOfMonth, format, startOfMonth } from 'date-fns'
import React from 'react'
import { connect } from 'react-redux'
import {
   Bar, BarChart, ResponsiveContainer, Tooltip, XAxis, YAxis
} from 'recharts'

import { getStats } from '../../actions/stats'
import { activityColors, formatDuration, formatStats } from '../../utils'


class Statistics extends React.Component {
  constructor(props, context) {
    super(props, context)
    const date = new Date()
    this.state = {
      start: startOfMonth(date),
      end: endOfMonth(date),
      displayedData: 'distance'
    }
  }

  componentDidMount() {
    this.props.loadMonthActivities(
      this.props.user.id,
      this.state.start,
      this.state.end,
    )
  }

  handleRadioChange (changeEvent) {
    this.setState({
      displayedData: changeEvent.target.name
    })
  }

  render() {
    const { sports, statistics } = this.props
    const { displayedData, end, start } = this.state
    const stats = formatStats(statistics, sports, start, end)
    return (
      <div className="card activity-card">
        <div className="card-header">
          This month
        </div>
        <div className="card-body">
          {Object.keys(statistics).length === 0 ? (
            'No workouts'
          ) : (
            <div className="chart-month">
              <div className="row chart-radio">
                <label className="radioLabel col">
                  <input
                    type="radio"
                    name="distance"
                    checked={displayedData === 'distance'}
                    onChange={e => this.handleRadioChange(e)}
                  />
                  distance
                </label>
                <label className="radioLabel col">
                  <input
                    type="radio"
                    name="duration"
                    checked={displayedData === 'duration'}
                    onChange={e => this.handleRadioChange(e)}
                  />
                  duration
                </label>
                <label className="radioLabel col">
                  <input
                    type="radio"
                    name="activities"
                    checked={displayedData === 'activities'}
                    onChange={e => this.handleRadioChange(e)}
                  />
                  activities
                </label>
              </div>
              <ResponsiveContainer height={300}>
                <BarChart
                  data={stats[displayedData]}
                  margin={{ top: 15, bottom: 0 }}
                >
                  <XAxis
                    dataKey="date"
                    interval={0} // to force to display all ticks
                  />
                  <YAxis
                    tickFormatter={value => displayedData === 'distance'
                      ? `${value} km`
                      : displayedData === 'duration'
                        ? format(formatDuration(value), 'HH:mm')
                        : value
                    }
                  />
                  <Tooltip />
                  {sports.map((s, i) => (
                    <Bar
                      key={s.id}
                      dataKey={s.label}
                      formatter={value => displayedData === 'duration'
                        ? format(formatDuration(value), 'HH:mm')
                        : value
                      }
                      stackId="a"
                      fill={activityColors[i]}
                      unit={displayedData === 'distance' ? ' km' : ''}
                    />
                  ))}
                </BarChart>
              </ResponsiveContainer>
            </div>
            )}
        </div>
      </div>
    )
  }
}

export default connect(
  state => ({
    sports: state.sports.data,
    statistics: state.statistics.data,
    user: state.user,
  }),
  dispatch => ({
    loadMonthActivities: (userId, start, end) => {
      const dateFormat = 'YYYY-MM-DD'
      const params = {
        from: format(start, dateFormat),
        to: format(end, dateFormat),
        time: 'week'
      }<commit_msg>display only 3 decimals for distance on month statistics - fix #24<commit_after>import { endOfMonth, format, startOfMonth } from 'date-fns'
import React from 'react'
import { connect } from 'react-redux'
import {
   Bar, BarChart, ResponsiveContainer, Tooltip, XAxis, YAxis
} from 'recharts'

import { getStats } from '../../actions/stats'
import { activityColors, formatDuration, formatStats } from '../../utils'


class Statistics extends React.Component {
  constructor(props, context) {
    super(props, context)
    const date = new Date()
    this.state = {
      start: startOfMonth(date),
      end: endOfMonth(date),
      displayedData: 'distance'
    }
  }

  componentDidMount() {
    this.props.loadMonthActivities(
      this.props.user.id,
      this.state.start,
      this.state.end,
    )
  }

  handleRadioChange (changeEvent) {
    this.setState({
      displayedData: changeEvent.target.name
    })
  }

  render() {
    const { sports, statistics } = this.props
    const { displayedData, end, start } = this.state
    const stats = formatStats(statistics, sports, start, end)
    return (
      <div className="card activity-card">
        <div className="card-header">
          This month
        </div>
        <div className="card-body">
          {Object.keys(statistics).length === 0 ? (
            'No workouts'
          ) : (
            <div className="chart-month">
              <div className="row chart-radio">
                <label className="radioLabel col">
                  <input
                    type="radio"
                    name="distance"
                    checked={displayedData === 'distance'}
                    onChange={e => this.handleRadioChange(e)}
                  />
                  distance
                </label>
                <label className="radioLabel col">
                  <input
                    type="radio"
                    name="duration"
                    checked={displayedData === 'duration'}
                    onChange={e => this.handleRadioChange(e)}
                  />
                  duration
                </label>
                <label className="radioLabel col">
                  <input
                    type="radio"
                    name="activities"
                    checked={displayedData === 'activities'}
                    onChange={e => this.handleRadioChange(e)}
                  />
                  activities
                </label>
              </div>
              <ResponsiveContainer height={300}>
                <BarChart
                  data={stats[displayedData]}
                  margin={{ top: 15, bottom: 0 }}
                >
                  <XAxis
                    dataKey="date"
                    interval={0} // to force to display all ticks
                  />
                  <YAxis
                    tickFormatter={value => displayedData === 'distance'
                      ? `${value} km`
                      : displayedData === 'duration'
                        ? format(formatDuration(value), 'HH:mm')
                        : value
                    }
                  />
                  <Tooltip />
                  {sports.map((s, i) => (
                    <Bar
                      key={s.id}
                      dataKey={s.label}
                      formatter={value => displayedData === 'duration'
                        ? format(formatDuration(value), 'HH:mm')
                        : displayedData === 'distance'
                          ? value.toFixed(3)
                          : value
                      }
                      stackId="a"
                      fill={activityColors[i]}
                      unit={displayedData === 'distance' ? ' km' : ''}
                    />
                  ))}
                </BarChart>
              </ResponsiveContainer>
            </div>
            )}
        </div>
      </div>
    )
  }
}

export default connect(
  state => ({
    sports: state.sports.data,
    statistics: state.statistics.data,
    user: state.user,
  }),
  dispatch => ({
    loadMonthActivities: (userId, start, end) => {
      const dateFormat = 'YYYY-MM-DD'
      const params = {
        from: format(start, dateFormat),
        to: format(end, dateFormat),
        time: 'week'
      }
{'fraction_non_alphanumeric': 0.11522633744855967, 'fraction_numerical': 0.0023515579071134627, 'mean_word_length': 1.2466983623877443, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 75, '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': '6644278', 'n_tokens_mistral': 2178, 'n_tokens_neox': 2061, 'n_words': 441}