<commit_before>var ContribBox = React.createClass({
    getInitialState: function() {
        return {
            loaded: false,
            totalContribs: 0,
            yearContribs: 0,
            monthContribs: 0,
            longestStreak: 0,
            currentStreak: 0,
        };
    },

    componentWillReceiveProps: function(props) {
        if(props.data !== null && props.data !== this.props.data) {
            // set state
            var self = this;
            this.setState({loaded: false});

            // start date (365 days ago)
            // first day of month
            var startDate = new Date(), firstDay = new Date();
            startDate.setDate(startDate.getDate() - 365);
            firstDay.setDate(1);

            // group items to calculate statistics
            var merged = $.map(props.data, function(obj) {return obj}).sort(function(a, b) {
                return a.when > b.when ? 1 : -1;
            });

            // calculate and apply
            this.setState({
                totalContribs: merged.length,
                yearContribs: $(merged).filter(function(_, obj) {
                    return obj.when > +startDate;
                }).length,
                monthContribs: $(merged).filter(function(_, obj) {
                    return obj.when > +firstDay;
                }).length,
            });

            // calculate streaks
            var _lastDay = null, _nextDay = null;
            var _longest = 0, _longestTemp = 0;
            $(merged).each(function(_, obj) {
                var date = moment(obj.when);
                if(date.isSame(_lastDay, 'day')) return;
                console.log(date.format('YYYYMMDD'), _lastDay);

                if(date.isSame(_nextDay, 'day')) {
                    _longestTemp++;
                    if(_longestTemp > _longest) {
                        _longest = _longestTemp;
                    }
                } else {
                    _longestTemp = 1;
                }

                _lastDay = date;
                _nextDay = moment(date).add(1, 'd');
            });
            this.setState({
                longestStreak: _longest,
            });

            // clear existing calendar
            cal = new CalHeatMap();
            $('#cal').html('');

            // re-arrange data
            var data = {};
            console.log(props.data)
            $.each(props.data, function(date, items) {
                date = +new Date(date) / 1000 | 0;
                data[date] = items.length;
            });

            // draw calendar
            cal.init({
                itemSelector: '#cal',
                domain: 'month',
                subDomain: 'day',
                range: 12,
                start: startDate,
                data: data,
                tooltip: true,
                legendHorizontalPosition: 'left',
                onComplete: function() {
                    setTimeout(function() {
                        $('#contrib, #cal').css('width', $('#cal > svg').width());
                        self.setState({loaded: true});
                    }, 0);
                },
                onClick: function(date, _) {
                    self.onClickDate(moment(date).format('YYYY-MM-DD'));
                },
            });
        }
    },

    onClickDate: function(date) {<commit_msg>Add current streak<commit_after>var ContribBox = React.createClass({
    getInitialState: function() {
        return {
            loaded: false,
            totalContribs: 0,
            yearContribs: 0,
            monthContribs: 0,
            longestStreak: 0,
            currentStreak: 0,
        };
    },

    componentWillReceiveProps: function(props) {
        if(props.data !== null && props.data !== this.props.data) {
            // set state
            var self = this;
            this.setState({loaded: false});

            // start date (365 days ago)
            // first day of month
            var startDate = new Date(), firstDay = new Date();
            startDate.setDate(startDate.getDate() - 365);
            firstDay.setDate(1);

            // group items to calculate statistics
            var merged = $.map(props.data, function(obj) {return obj}).sort(function(a, b) {
                return a.when > b.when ? 1 : -1;
            });

            // calculate and apply
            this.setState({
                totalContribs: merged.length,
                yearContribs: $(merged).filter(function(_, obj) {
                    return obj.when > +startDate;
                }).length,
                monthContribs: $(merged).filter(function(_, obj) {
                    return obj.when > +firstDay;
                }).length,
            });

            // calculate streaks
            // ye I know, too dirty code
            var _lastDay = null, _nextDay = null;
            var _longest = 0, _longestTemp = 0;
            $(merged).each(function(_, obj) {
                var date = moment(obj.when);
                if(date.isSame(_lastDay, 'day')) return;

                if(date.isSame(_nextDay, 'day')) {
                    _longestTemp++;
                    if(_longestTemp > _longest) {
                        _longest = _longestTemp;
                    }
                } else {
                    _longestTemp = 1;
                }

                _lastDay = date;
                _nextDay = moment(date).add(1, 'd');
            });
            var _lastDay = null, _yesterDay = null;
            var _current = 0, _break = false;
            $(merged.reverse()).each(function(_, obj) {
                if(_break) return;
                var date = moment(obj.when);
                if(_current == 0 && !date.isSame(moment(), 'day')) {
                    _break = true;
                    return;
                } else {
                    _current = 1;
                }
                if(date.isSame(_lastDay, 'day')) return;

                if(date.isSame(_yesterDay, 'day')) {
                    _current++;
                } else {
                    _break = true;
                    return;
                }

                _lastDay = date;
                _yesterDay = moment(date).add(-1, 'd');
            });

            this.setState({
                longestStreak: _longest,
                currentStreak: _current,
            });

            // clear existing calendar
            cal = new CalHeatMap();
            $('#cal').html('');

            // re-arrange data
            var data = {};
            console.log(props.data)
            $.each(props.data, function(date, items) {
                date = +new Date(date) / 1000 | 0;
                data[date] = items.length;
            });

            // draw calendar
            cal.init({
                itemSelector: '#cal',
                domain: 'month',
                subDomain: 'day',
                range: 13,
                start: startDate,
                data: data,
                tooltip: true,
                legendHorizontalPosition: 'left',
                onComplete: function() {
                    setTimeout(function() {
                        $('#contrib, #cal').css('width', $('#cal > svg').width());
                        self.setState({loaded: true});
                    }, 0);
                },
                onClick: function(date, _) {
                    self.onClickDate(moment(date).format('YYYY-MM-DD'));
                },
            });
        }
    },

    onClickDate: function(date) {
{'fraction_non_alphanumeric': 0.12013760254035459, 'fraction_numerical': 0.0074093675575549085, 'mean_word_length': 1.1263009845288325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1042746', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1884, 'n_words': 416}