<commit_before>var _ = require('lodash');
var React = require('react');
var Highcharts = require('react-highcharts/bundle/highcharts');
var userService = require('../services/user');

function getLabels(timestamps) {
    return _(timestamps)
    .reduce(function(memo, timestamp, i) {
        var isLast = i === (timestamps.length - 1);
        if (isLast) {
            return memo;
        }

        var nextTimestamp = timestamps[i + 1];
        var durationHours = (nextTimestamp - timestamp) / 1000 / 60 / 60;
        var hour = new Date(timestamp).getHours();

        if(durationHours > 2 && durationHours < 14 && (hour > 21 || hour < 6)) {
            memo.push({
                from: timestamp,
                to: nextTimestamp
            });
        }

        return memo;
    }, [])
    .map(function (interval, i, intervals) {
        var MIN_DAY_LENGTH = 12 * 3600 * 1000;
        var isLast = i === (intervals.length - 1);
        if (isLast || interval.delete) {
            return interval;
        }

        var nextInterval = intervals[i + 1];
        var awakeDuration = nextInterval.from - interval.to;
        if(awakeDuration < MIN_DAY_LENGTH) {
            var nextIntervalDuration = (nextInterval.to - nextInterval.from);
            var intervalDuration = (interval.to - interval.from);
            if(awakeDuration < 15 * 60 * 1000 && (nextIntervalDuration + intervalDuration) < 14 * 3600 * 1000) {
                interval.delete = true;
                nextInterval.from = interval.from;
            }else {
                var nextIsLarger = nextIntervalDuration > intervalDuration;
                if(nextIsLarger) {
                    interval.delete = true;
                } else {
                    nextInterval.delete = true;
                }
            }
        }

        return interval;
    }, [])
    .filter(function (interval) {
        return !interval.delete;
    })
    .map(function (sleep) {
        var yesterday = getYesterday(sleep.to);
        var duration = (sleep.to - sleep.from) / 1000 / 60 / 60;
        return {
          color: '#dfe3ee',
          from: sleep.from,
          to: sleep.to,
          label: {
            text: '<strong>' + yesterday + '</strong><br>' + duration.toFixed(1) + ' hrs.<br> of sleep',
            fontWeight: 'bold',
            verticalAlign: 'middle',
            y: 0
          }
        }
    });
}

function getYesterday(timestamp) {
    var days = ['Sun','Mon','Tue','Wed','Thur','Fri','Sat'];
    var d = new Date(timestamp);
    d.setDate(d.getDate() - 1)
    var day = d.getDay();
    return days[day];
}

function getConfig(timestamps) {
    if(_.isEmpty(timestamps)) {
        return {};
    }

    var labels = getLabels(timestamps);
    var labels = [];
    var data = timestamps.map(function(timestamp){
        return [timestamp, 1];
    });

    return {
        plotOptions: {
            series: {
                animation: false,
            },
        },
        legend: {
            enabled: false,
        },<commit_msg>Show labels<commit_after>var _ = require('lodash');
var React = require('react');
var Highcharts = require('react-highcharts/bundle/highcharts');
var userService = require('../services/user');

function getLabels(timestamps) {
    return _(timestamps)
    .reduce(function(memo, timestamp, i) {
        var isLast = i === (timestamps.length - 1);
        if (isLast) {
            return memo;
        }

        var nextTimestamp = timestamps[i + 1];
        var durationHours = (nextTimestamp - timestamp) / 1000 / 60 / 60;
        var hour = new Date(timestamp).getHours();

        if(durationHours > 2 && durationHours < 14 && (hour > 21 || hour < 6)) {
            memo.push({
                from: timestamp,
                to: nextTimestamp
            });
        }

        return memo;
    }, [])
    .map(function (interval, i, intervals) {
        var MIN_DAY_LENGTH = 12 * 3600 * 1000;
        var isLast = i === (intervals.length - 1);
        if (isLast || interval.delete) {
            return interval;
        }

        var nextInterval = intervals[i + 1];
        var awakeDuration = nextInterval.from - interval.to;
        if(awakeDuration < MIN_DAY_LENGTH) {
            var nextIntervalDuration = (nextInterval.to - nextInterval.from);
            var intervalDuration = (interval.to - interval.from);
            if(awakeDuration < 15 * 60 * 1000 && (nextIntervalDuration + intervalDuration) < 14 * 3600 * 1000) {
                interval.delete = true;
                nextInterval.from = interval.from;
            }else {
                var nextIsLarger = nextIntervalDuration > intervalDuration;
                if(nextIsLarger) {
                    interval.delete = true;
                } else {
                    nextInterval.delete = true;
                }
            }
        }

        return interval;
    }, [])
    .filter(function (interval) {
        return !interval.delete;
    })
    .map(function (sleep) {
        var yesterday = getYesterday(sleep.to);
        var duration = (sleep.to - sleep.from) / 1000 / 60 / 60;
        return {
          color: '#dfe3ee',
          from: sleep.from,
          to: sleep.to,
          label: {
            text: '<strong>' + yesterday + '</strong><br>' + duration.toFixed(1) + ' hrs.<br> of sleep',
            fontWeight: 'bold',
            verticalAlign: 'middle',
            y: 0
          }
        }
    });
}

function getYesterday(timestamp) {
    var days = ['Sun','Mon','Tue','Wed','Thur','Fri','Sat'];
    var d = new Date(timestamp);
    d.setDate(d.getDate() - 1)
    var day = d.getDay();
    return days[day];
}

function getConfig(timestamps) {
    if(_.isEmpty(timestamps)) {
        return {};
    }

    var labels = getLabels(timestamps);
    var data = timestamps.map(function(timestamp){
        return [timestamp, 1];
    });

    return {
        plotOptions: {
            series: {
                animation: false,
            },
        },
        legend: {
            enabled: false,
        },
{'fraction_non_alphanumeric': 0.12959604286892004, 'fraction_numerical': 0.019455894476504535, 'mean_word_length': 1.7128801431127012, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, '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': '2863507', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1681, 'n_words': 393}