<commit_before>React = require('react')
Accumulator = require('./accumulator')
Polynomial = require('./polynomial')
clockSkew = require('./clockSkew')
clock = require('./clock')

AccumulatorInspector = React.createClass({
    displayName: 'AccumulatorInspector'

    getInitialState: ->
        return {
            accumulator: {k: []}
            value: 0
        }

    componentWillMount: ->
        saveData = JSON.parse(localStorage.getItem(@props.saveKey))
        @accumulator = new Accumulator(saveData)
        @accumulator.onChange = =>
            @setStateFromAccumulator()
        clock.on('frame', @setStateFromAccumulator, @)
        @setStateFromAccumulator()

    componentWillUnmount: ->
        clearInterval(@updateInterval)
        @updateInterval = null

    setStateFromAccumulator: ->
        clockSkew.fetch((skew)=>
            t = Date.now() - skew
            @setState({
                accumulator: @accumulator
                t: t
                value: Math.floor(@accumulator.evaluateAtTime(t))
                rate: @accumulator.rateAtTime(t)
            })
        )

    shouldComponentUpdate: (nextProps, nextState)->
        if nextState.value isnt @state.value
            return true
        if nextState.rate isnt @state.rate
            return true
        for k_i, i in nextState.accumulator?.k or []
            if @state.accumulator.k[i] isnt k_i
                return true
        return false

    addOne: ->
        @accumulator.addPolynomial([1])

    addOnePerSecond: ->
        @accumulator.addPolynomial([0, 1])

    addOnePerSecondPerSecond: ->
        @accumulator.addPolynomial([0, 0, 1])

    toggleDiscrete: ->
        @accumulator.discrete = !@accumulator.discrete
        @setStateFromAccumulator()

    toggleBatched: ->
        @accumulator.batched = !@accumulator.batched
        @setStateFromAccumulator()

    reset: ->
        @accumulator.k = [0]
        @setStateFromAccumulator()

    save: ->
        localStorage.setItem(@props.saveKey, JSON.stringify(@accumulator))

    render: ->
        window.lastAI = this
        variable = 't'

        return <div>
            <p className="math">
                <var>t</var><sub>0</sub>
                {' = '}
                {(new Date(@state.accumulator.t_0)).toString()}
            </p>
            <p className="math">
                <var>t</var><sub>1</sub>
                {' = '}
                {(new Date()).toString()}
            </p>
            <p className="math">
                <var>t</var> = <var>t</var><sub>1</sub> &ndash; <var>t</var><sub>0</sub>
                {' = '}
                {(@state.t - @state.accumulator.t_0)/ @state.accumulator.scale} sec
            </p>
            <p className="math">
                <var>f</var>(<var>t</var>)
                {' = '}
                <Polynomial variable={variable} coefficients={@state.accumulator.k} />
                {' = '}
                {@state.value}
            </p>
            <p className="math">
                <var>f&prime;</var>(<var>t</var>)
                {' = '}
                {@state.rate} / sec
            </p>
            <button className="pure-button" onClick={@addOne}>Add 1</button>{' '}
            <button className="pure-button" onClick={@addOnePerSecond}>Add 1/sec</button>{' '}
            <button className="pure-button" onClick={@addOnePerSecondPerSecond}>Add 1/sec<sup>2</sup></button>{' '}
            <button className="pure-button" onClick={@reset}>Reset</button>{' '}
            <button className="pure-button" onClick={@save}>Save</button>
            <br/>
            <br/>
            <label className="pure-checkbox"><input type="checkbox" onChange={@toggleDiscrete} checked={@state.accumulator.discrete} /> discrete</label>{' '}
            <label className="pure-checkbox"><input type="checkbox" onChange={@toggleBatched} checked={@state.accumulator.batched} /> batched</label>
        </div>
})

module.exports = AccumulatorInspector
<commit_msg>show time scale<commit_after>React = require('react')
Accumulator = require('./accumulator')
Polynomial = require('./polynomial')
clockSkew = require('./clockSkew')
clock = require('./clock')

AccumulatorInspector = React.createClass({
    displayName: 'AccumulatorInspector'

    getInitialState: ->
        return {
            accumulator: {k: []}
            value: 0
        }

    componentWillMount: ->
        saveData = JSON.parse(localStorage.getItem(@props.saveKey))
        @accumulator = new Accumulator(saveData)
        @accumulator.onChange = =>
            @setStateFromAccumulator()
        clock.on('frame', @setStateFromAccumulator, @)
        @setStateFromAccumulator()

    componentWillUnmount: ->
        clearInterval(@updateInterval)
        @updateInterval = null

    setStateFromAccumulator: ->
        clockSkew.fetch((skew)=>
            t = Date.now() - skew
            @setState({
                accumulator: @accumulator
                t: t
                value: Math.floor(@accumulator.evaluateAtTime(t))
                rate: @accumulator.rateAtTime(t)
            })
        )

    # shouldComponentUpdate: (nextProps, nextState)->
    #     if nextState.value isnt @state.value
    #         return true
    #     if nextState.rate isnt @state.rate
    #         return true
    #     for k_i, i in nextState.accumulator?.k or []
    #         if @state.accumulator.k[i] isnt k_i
    #             return true
    #     return false

    addOne: ->
        @accumulator.addPolynomial([1])

    addOnePerSecond: ->
        @accumulator.addPolynomial([0, 1])

    addOnePerSecondPerSecond: ->
        @accumulator.addPolynomial([0, 0, 1])

    toggleDiscrete: ->
        @accumulator.discrete = !@accumulator.discrete
        @setStateFromAccumulator()

    toggleBatched: ->
        @accumulator.batched = !@accumulator.batched
        @setStateFromAccumulator()

    reset: ->
        @accumulator.k = [0]
        @setStateFromAccumulator()

    save: ->
        localStorage.setItem(@props.saveKey, JSON.stringify(@accumulator))

    render: ->
        window.lastAI = this
        variable = 't'

        return <div>
            <p className="math">
                <var>t</var><sub>0</sub>
                {' = '}
                {(new Date(@state.accumulator.t_0)).toString()}
            </p>
            <p className="math">
                <var>t</var><sub>1</sub>
                {' = '}
                {(new Date()).toString()}
            </p>
            <p className="math">
                Time scale: 1 tick = {@state.accumulator.scale} ms
            </p>
            <p className="math">
                <var>t</var> = <var>t</var><sub>1</sub> &ndash; <var>t</var><sub>0</sub>
                {' = '}
                {(@state.t - @state.accumulator.t_0)/ @state.accumulator.scale} ticks
            </p>
            <p className="math">
                Current value:{' '}
                <var>f</var>(<var>t</var>)
                {' = '}
                <Polynomial variable={variable} coefficients={@state.accumulator.k} />
                {' = '}
                {@state.value}
            </p>
            <p className="math">
                Current rate:{' '}
                <var>f&prime;</var>(<var>t</var>)
                {' = '}
                {@state.rate} per tick
            </p>
            <button className="pure-button" onClick={@addOne}>Add 1</button>{' '}
            <button className="pure-button" onClick={@addOnePerSecond}>Add 1/sec</button>{' '}
            <button className="pure-button" onClick={@addOnePerSecondPerSecond}>Add 1/sec<sup>2</sup></button>{' '}
            <button className="pure-button" onClick={@reset}>Reset</button>{' '}
            <button className="pure-button" onClick={@save}>Save</button>
            <br/>
            <br/>
            <label className="pure-checkbox"><input type="checkbox" onChange={@toggleDiscrete} checked={@state.accumulator.discrete} /> discrete</label>{' '}
            <label className="pure-checkbox"><input type="checkbox" onChange={@toggleBatched} checked={@state.accumulator.batched} /> batched</label>
        </div>
})

module.exports = AccumulatorInspector

{'fraction_non_alphanumeric': 0.15062812538114403, 'fraction_numerical': 0.00451274545676302, 'mean_word_length': 1.9140014214641081, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 153, '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': '5192266', 'n_tokens_mistral': 2499, 'n_tokens_neox': 2369, 'n_words': 378}