<commit_before>TrueColours = TrueColours || {};


TrueColours.Helpers = TrueColours.Helpers || {

    getCircularMean: function (listOfTimes) {
        'use strict';

        var bedTimes = [];

        _.each(listOfTimes, function (time) {
            bedTimes.push(new TrueColours.BedTime(time));
        }, this);

        return bedTimes;
    }

};<commit_msg>add sin, cos and atan for mean calculation<commit_after>TrueColours = TrueColours || {};


TrueColours.Helpers = TrueColours.Helpers || {

    getArctanMean: function (sinMean, cosMean) {
        'use strict';

        var arctanMean = Math.atan2(sinMean, cosMean);

        // if sin is +ve and cos is -ve (ie 2nd quadrant)
        if (sinMean > 0 && cosMean < 0) {
            return 180 - arctanMean;
        }

        // if sin is -ve and cos is -ve (ie 3rd quadrant)
        if (sinMean < 0 && cosMean < 0){
            return 180 + arctanMean;
        }

        // if sin is -ve and cos is +ve (ie 4th quadrant)
        if (sinMean < 0 && cosMean > 0){
            return 360 - arctanMean;
        }

        return arctanMean;
    },


    getCosMean: function (bedTimes) {
        'use strict';

        var X = 0;

        _.each(bedTimes, function (bedTime) {
            X += bedTime.getCos();
        }, this);

        return X / bedTimes.length;
    },

    getSinMean: function (bedTimes) {
        'use strict';

        var Y = 0;

        _.each(bedTimes, function (bedTime) {
            Y += bedTime.getSin();
        }, this);

        return Y / bedTimes.length;
    },

    getCircularMean: function (listOfTimes) {
        'use strict';

        var bedTimes = [];

        _.each(listOfTimes, function (time) {
            bedTimes.push(new TrueColours.BedTime(time));
        }, this);


        var cosMean = this.getCosMean(bedTimes); // X
        var sinMean = this.getSinMean(bedTimes); // Y

        var angleMean = this.getArctanMean(sinMean, cosMean);


        return angleMean;
    }

};
{'fraction_non_alphanumeric': 0.12072434607645875, 'fraction_numerical': 0.01056338028169014, 'mean_word_length': 1.8373751783166905, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5139799', 'n_tokens_mistral': 691, 'n_tokens_neox': 607, 'n_words': 160}