<commit_before>/* global sauce, jQuery, Strava, pageView, Backbone, d3 */

// NOTE: Must be assigned to self and have matching name for FF
self.saucePreloaderInit = function saucePreloaderInit() {
    'use strict';

    self.sauce = self.sauce || {};

    const cacheRefreshThreshold = 120 * 1000;
    const maybeRequestIdleCallback = self.requestIdleCallback || (fn => fn());  // Safari


    sauce.propDefined('pageView', view => {
        const assembleSave = view.assemble;
        view.assemble = function(_, weight) {
            sauce.stravaAthleteWeight = weight;
            return assembleSave.apply(this, arguments);
        };
        const addCustomRoutes = view.addCustomRoutes;
        view.addCustomRoutes = menuRouter => {
            addCustomRoutes.call(view, menuRouter);
            // Fix for reload hang on /analysis page
            if (!('route:analysis' in menuRouter._events)) {
                menuRouter.addRoute('/analysis', 'analysis');
                menuRouter.on('route:analysis', () => {
                    view.handleAnalysisClicked();
                    view.menuView.handleRouteChange('analysis');
                });
            }
        };
        if (!document.querySelector('#pagenav li [data-menu="analysis"]')) {
            // Create stub element for analysis menu, but hide it until analysis
            // can do the right thing with it.  It needs to exist early so initial
            // routes can set classes on this element.
            const pageNav = document.querySelector('#pagenav');
            const overview = pageNav && pageNav.querySelector('[data-menu="overview"]');
            // Some indoor workouts for non-premium members don't have pageNav (ie. peleton)
            if (overview) {
                const li = document.createElement('li');
                li.style.display = 'none';
                li.classList.add('sauce-stub');
                li.innerHTML = `<a data-menu="analysis"></a>`;
                pageNav.insertBefore(li, overview.closest('li').nextSibling);
            }
        }
        if (view.activity) {
            const activity = view.activity();
            let _supportsGap;
            const supportsGap = (v) => {
                // Ignore explicit false value and instead infer gap support from activity type.
                if (v) {
                    _supportsGap = true;
                } else if (!_supportsGap) {
                    return !!(
                        activity.isRun() &&
                        !activity.isTrainer() &&
                        activity.get('distance') &&
                        activity.get('elev_gain')
                    );
                }
                return _supportsGap;
            };
            supportsGap(view.supportsGap());
            view.supportsGap = supportsGap;
            if (activity) {
                supportsGap(activity.supportsGap());
                activity.supportsGap = supportsGap;
            } else {
                let _activity;
                view.activity = function(a) {
                    if (a) {
                        _activity = a;
                        supportsGap(a.supportsGap());
                        a.supportsGap = supportsGap;
                    }
                    return _activity;
                };
            }
        }
    }, {once: true});


    sauce.propDefined('Strava.Charts.Activities.BasicAnalysisElevation', Klass => {
        // Monkey patch analysis views so we can react to selection changes.
        const saveFn = Klass.prototype.displayDetails;
        Klass.prototype.displayDetails = function(start, end) {
            start = start === undefined ? start : Number(start);
            end = end === undefined ? end : Number(end);
            if (sauce.analysis) {
                sauce.analysis.schedUpdateAnalysisStats(start, end);
            } else {
                sauce.analysisStatsIntent = {start, end};
            }
            return saveFn.apply(this, arguments);
        };
    }, {once: true});


    sauce.propDefined('Strava.Charts.Activities.LabelBox', Klass => {
        // This is called when zoom selections change or are unset in the profile graph.
        const saveHandleStreamHoverFn = Klass.prototype.handleStreamHover;
        Klass.prototype.handleStreamHover = function(_, start, end) {
            start = start === undefined ? start : Number(start);
            end = end === undefined ? end : Number(end);
            if (sauce.analysis) {
                sauce.analysis.schedUpdateAnalysisStats(start, end);
            } else {
                sauce.analysisStatsIntent = {start, end};
            }
            try {
                return saveHandleStreamHoverFn.apply(this, arguments);
            } finally {
                const tweaks = this.container._streamTweaks;
                const labelBox = this;
                this.groups.selectAll('text.static-label-box.max-js').text(function(x) {
                    const labeler = (tweaks[x.streamType] || {}).maxLabel;
                    return labeler ? labeler(x, labelBox, start, end) : this.textContent;
                });
            }
        };

        const saveBuildFn = Klass.prototype.build;
        Klass.prototype.build = function() {
            // Leave a ref to ourselves on the container so it can be used by us later.
            this.container._labelBox = this;
            return saveBuildFn.apply(this, arguments);
        };
    }, {once: true});


    sauce.propDefined('Strava.Charts.Activities.BasicAnalysisStacked', Klass => {
        let minLocale = 'Min';
        sauce.locale.getMessage('analysis_min').then(x => minLocale = x);
        const paceMaxLabel = (data, labelBox, start, end) => {<commit_msg>Wait for locale availability in preloader<commit_after>/* global sauce, jQuery, Strava, pageView, Backbone, d3 */

// NOTE: Must be assigned to self and have matching name for FF
self.saucePreloaderInit = function saucePreloaderInit() {
    'use strict';

    self.sauce = self.sauce || {};

    const cacheRefreshThreshold = 120 * 1000;
    const maybeRequestIdleCallback = self.requestIdleCallback || (fn => fn());  // Safari


    sauce.propDefined('pageView', view => {
        const assembleSave = view.assemble;
        view.assemble = function(_, weight) {
            sauce.stravaAthleteWeight = weight;
            return assembleSave.apply(this, arguments);
        };
        const addCustomRoutes = view.addCustomRoutes;
        view.addCustomRoutes = menuRouter => {
            addCustomRoutes.call(view, menuRouter);
            // Fix for reload hang on /analysis page
            if (!('route:analysis' in menuRouter._events)) {
                menuRouter.addRoute('/analysis', 'analysis');
                menuRouter.on('route:analysis', () => {
                    view.handleAnalysisClicked();
                    view.menuView.handleRouteChange('analysis');
                });
            }
        };
        if (!document.querySelector('#pagenav li [data-menu="analysis"]')) {
            // Create stub element for analysis menu, but hide it until analysis
            // can do the right thing with it.  It needs to exist early so initial
            // routes can set classes on this element.
            const pageNav = document.querySelector('#pagenav');
            const overview = pageNav && pageNav.querySelector('[data-menu="overview"]');
            // Some indoor workouts for non-premium members don't have pageNav (ie. peleton)
            if (overview) {
                const li = document.createElement('li');
                li.style.display = 'none';
                li.classList.add('sauce-stub');
                li.innerHTML = `<a data-menu="analysis"></a>`;
                pageNav.insertBefore(li, overview.closest('li').nextSibling);
            }
        }
        if (view.activity) {
            const activity = view.activity();
            let _supportsGap;
            const supportsGap = (v) => {
                // Ignore explicit false value and instead infer gap support from activity type.
                if (v) {
                    _supportsGap = true;
                } else if (!_supportsGap) {
                    return !!(
                        activity.isRun() &&
                        !activity.isTrainer() &&
                        activity.get('distance') &&
                        activity.get('elev_gain')
                    );
                }
                return _supportsGap;
            };
            supportsGap(view.supportsGap());
            view.supportsGap = supportsGap;
            if (activity) {
                supportsGap(activity.supportsGap());
                activity.supportsGap = supportsGap;
            } else {
                let _activity;
                view.activity = function(a) {
                    if (a) {
                        _activity = a;
                        supportsGap(a.supportsGap());
                        a.supportsGap = supportsGap;
                    }
                    return _activity;
                };
            }
        }
    }, {once: true});


    sauce.propDefined('Strava.Charts.Activities.BasicAnalysisElevation', Klass => {
        // Monkey patch analysis views so we can react to selection changes.
        const saveFn = Klass.prototype.displayDetails;
        Klass.prototype.displayDetails = function(start, end) {
            start = start === undefined ? start : Number(start);
            end = end === undefined ? end : Number(end);
            if (sauce.analysis) {
                sauce.analysis.schedUpdateAnalysisStats(start, end);
            } else {
                sauce.analysisStatsIntent = {start, end};
            }
            return saveFn.apply(this, arguments);
        };
    }, {once: true});


    sauce.propDefined('Strava.Charts.Activities.LabelBox', Klass => {
        // This is called when zoom selections change or are unset in the profile graph.
        const saveHandleStreamHoverFn = Klass.prototype.handleStreamHover;
        Klass.prototype.handleStreamHover = function(_, start, end) {
            start = start === undefined ? start : Number(start);
            end = end === undefined ? end : Number(end);
            if (sauce.analysis) {
                sauce.analysis.schedUpdateAnalysisStats(start, end);
            } else {
                sauce.analysisStatsIntent = {start, end};
            }
            try {
                return saveHandleStreamHoverFn.apply(this, arguments);
            } finally {
                const tweaks = this.container._streamTweaks;
                const labelBox = this;
                this.groups.selectAll('text.static-label-box.max-js').text(function(x) {
                    const labeler = (tweaks[x.streamType] || {}).maxLabel;
                    return labeler ? labeler(x, labelBox, start, end) : this.textContent;
                });
            }
        };

        const saveBuildFn = Klass.prototype.build;
        Klass.prototype.build = function() {
            // Leave a ref to ourselves on the container so it can be used by us later.
            this.container._labelBox = this;
            return saveBuildFn.apply(this, arguments);
        };
    }, {once: true});


    sauce.propDefined('Strava.Charts.Activities.BasicAnalysisStacked', Klass => {
        let minLocale = 'Min';
        let afterLocaleReady;
        if (!sauce.locale || !sauce.locale.getMessage) {
            afterLocaleReady = new Promise(resolve =>
                document.addEventListener('sauceLocaleReady', resolve, {once: true}));
        } else {
            afterLocaleReady = Promise.resolve();
        }
        afterLocaleReady.then(async () =>
            void (minLocale = await sauce.locale.getMessage('analysis_min')));
        const paceMaxLabel = (data, labelBox, start, end) => {
{'fraction_non_alphanumeric': 0.10833753572028912, 'fraction_numerical': 0.0013447638258530846, 'mean_word_length': 1.6817669596574263, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, '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': '621587', 'n_tokens_mistral': 3067, 'n_tokens_neox': 3024, 'n_words': 718}