<commit_before>var TUJ_Item = function ()
{
    var params;
    var lastResults = [];
    var itemId;
    var levels;
    var level;
    var urlLevel;

    this.load = function (inParams)
    {
        params = {};
        for (var p in inParams) {
            if (inParams.hasOwnProperty(p)) {
                params[p] = inParams[p];
            }
        }

        itemId = '' + params.id;
        urlLevel = false;

        if (itemId.indexOf('.') > 0) {
            itemId = ('' + params.id).substr(0, ('' + params.id).indexOf('.'));
            urlLevel = ('' + params.id).substr(('' + params.id).indexOf('.') + 1);
        }

        var qs = {
            house: tuj.realms[params.realm].house,
            item: itemId
        };
        var hash = JSON.stringify(qs);

        for (var x = 0; x < lastResults.length; x++) {
            if (lastResults[x].hash == hash) {
                ItemResult(false, lastResults[x].data);
                return;
            }
        }

        var itemPage = $('#item-page')[0];
        if (!itemPage) {
            itemPage = libtuj.ce();
            itemPage.id = 'item-page';
            itemPage.className = 'page';
            $('#main').append(itemPage);
        }

        $('#progress-page').show();

        var ajaxTries = 0;
        var ajaxSettings = {
            data: qs,
            success: function (d)
            {
                if (d.captcha) {
                    tuj.AskCaptcha(d.captcha);
                }
                else {
                    ItemResult(hash, d);
                }

                $('#progress-page').hide();
            },
            error: function (xhr, stat, er)
            {
                if (xhr.status == 429 && xhr.responseJSON && xhr.responseJSON.concurrent_retry) {
                    if (++ajaxTries >= 10) {
                        $('#progress-page').hide();

                        alert('Too many concurrent requests, please reload to try again.');
                    } else {
                        var delay = 2500 + Math.round(Math.random() * 1000) + 1000 * ajaxTries;
                        console.log('Other concurrent requests currently being processed, will retry after ' + delay + 'ms');

                        window.setTimeout(
                            function () {
                                $.ajax(ajaxSettings);
                            }, delay);
                    }

                    return;
                }

                $('#progress-page').hide();

                if ((xhr.status == 503) && xhr.responseJSON && xhr.responseJSON.maintenance) {
                    tuj.APIMaintenance(xhr.responseJSON.maintenance);
                } else {
                    alert('Error fetching page data: ' + xhr.status + ' ' + stat + ' ' + er);
                }
            },
            url: 'api/item.php'
        };

        $.ajax(ajaxSettings);
    };

    function ItemResult(hash, dta)
    {
        if (hash) {
            lastResults.push({hash: hash, data: dta});
            while (lastResults.length > 10) {
                lastResults.shift();
            }
        }

        var itemPage = $('#item-page');
        itemPage.empty();
        itemPage.show();

        if (!dta.stats) {
            $('#page-title').empty().append(document.createTextNode(tuj.lang.item + ': ' + itemId));
            tuj.SetTitle(tuj.lang.item + ': ' + itemId);

            var h2 = libtuj.ce('h2');
            itemPage.append(h2);
            h2.appendChild(document.createTextNode(libtuj.sprintf(tuj.lang.notFound, tuj.lang.item + ' ' + itemId)));

            return;
        }

        levels = [];
        var foundLevel = false;

        for (var lvl in dta.stats) {
            if (!dta.stats.hasOwnProperty(lvl)) {
                continue;
            }
            levels.push(parseInt(lvl,10));
            foundLevel |= urlLevel == lvl;
        }
        levels.sort(function (a, b)
        {
            return a - b;
        });
        if (!foundLevel) {
            if (urlLevel === false) {
                // url didn't specify a level
                if (dta.stats.hasOwnProperty(dta.stats[levels[0]].baselevel)) {
                    // use the base level
                    level = dta.stats[levels[0]].baselevel;
                } else {
                    // no stats for the real base level, use the first level for which we have stats
                    tuj.SetParams({page: 'item', id: '' + itemId + '.' + levels[0]});
                    return;
                }
            } else {
                // didn't find the level specified in the URL in the list of levels for this house
                tuj.SetParams({page: 'item', id: '' + itemId});
                return;
            }
        } else if (!urlLevel) {
            // level === false
            level = 0; // so array indexes work
        } else if (dta.stats[level].baselevel == urlLevel) {
            // the level specified in the URL is the base level, which makes it redundant. remove it.
            tuj.SetParams({page: 'item', id: '' + itemId});
            return;
        }

        var fullItemName = '[' + dta.stats[level]['name_' + tuj.locale] + ']';

        var ta = libtuj.ce('a');
        ta.href = 'http://' + tuj.lang.wowheadDomain + '.wowhead.com/item=' + itemId;
        ta.target = '_blank';
        ta.rel = 'noopener noreferrer';
        ta.className = 'item';
        if (level != dta.stats[level].baselevel || levels.length > 1) {<commit_msg>replace level usage<commit_after>var TUJ_Item = function ()
{
    var params;
    var lastResults = [];
    var itemId;
    var levels;
    var level;
    var urlLevel;

    this.load = function (inParams)
    {
        params = {};
        for (var p in inParams) {
            if (inParams.hasOwnProperty(p)) {
                params[p] = inParams[p];
            }
        }

        itemId = '' + params.id;
        urlLevel = false;

        if (itemId.indexOf('.') > 0) {
            itemId = ('' + params.id).substr(0, ('' + params.id).indexOf('.'));
            urlLevel = ('' + params.id).substr(('' + params.id).indexOf('.') + 1);
        }

        var qs = {
            house: tuj.realms[params.realm].house,
            item: itemId
        };
        var hash = JSON.stringify(qs);

        for (var x = 0; x < lastResults.length; x++) {
            if (lastResults[x].hash == hash) {
                ItemResult(false, lastResults[x].data);
                return;
            }
        }

        var itemPage = $('#item-page')[0];
        if (!itemPage) {
            itemPage = libtuj.ce();
            itemPage.id = 'item-page';
            itemPage.className = 'page';
            $('#main').append(itemPage);
        }

        $('#progress-page').show();

        var ajaxTries = 0;
        var ajaxSettings = {
            data: qs,
            success: function (d)
            {
                if (d.captcha) {
                    tuj.AskCaptcha(d.captcha);
                }
                else {
                    ItemResult(hash, d);
                }

                $('#progress-page').hide();
            },
            error: function (xhr, stat, er)
            {
                if (xhr.status == 429 && xhr.responseJSON && xhr.responseJSON.concurrent_retry) {
                    if (++ajaxTries >= 10) {
                        $('#progress-page').hide();

                        alert('Too many concurrent requests, please reload to try again.');
                    } else {
                        var delay = 2500 + Math.round(Math.random() * 1000) + 1000 * ajaxTries;
                        console.log('Other concurrent requests currently being processed, will retry after ' + delay + 'ms');

                        window.setTimeout(
                            function () {
                                $.ajax(ajaxSettings);
                            }, delay);
                    }

                    return;
                }

                $('#progress-page').hide();

                if ((xhr.status == 503) && xhr.responseJSON && xhr.responseJSON.maintenance) {
                    tuj.APIMaintenance(xhr.responseJSON.maintenance);
                } else {
                    alert('Error fetching page data: ' + xhr.status + ' ' + stat + ' ' + er);
                }
            },
            url: 'api/item.php'
        };

        $.ajax(ajaxSettings);
    };

    function ItemResult(hash, dta)
    {
        if (hash) {
            lastResults.push({hash: hash, data: dta});
            while (lastResults.length > 10) {
                lastResults.shift();
            }
        }

        var itemPage = $('#item-page');
        itemPage.empty();
        itemPage.show();

        if (!dta.stats) {
            $('#page-title').empty().append(document.createTextNode(tuj.lang.item + ': ' + itemId));
            tuj.SetTitle(tuj.lang.item + ': ' + itemId);

            var h2 = libtuj.ce('h2');
            itemPage.append(h2);
            h2.appendChild(document.createTextNode(libtuj.sprintf(tuj.lang.notFound, tuj.lang.item + ' ' + itemId)));

            return;
        }

        levels = [];
        var foundLevel = false;

        for (var lvl in dta.stats) {
            if (!dta.stats.hasOwnProperty(lvl)) {
                continue;
            }
            levels.push(parseInt(lvl,10));
            foundLevel |= urlLevel == lvl;
        }
        levels.sort(function (a, b)
        {
            return a - b;
        });
        if (!foundLevel) {
            if (urlLevel === false) {
                // url didn't specify a level
                if (dta.stats.hasOwnProperty(dta.stats[levels[0]].baselevel)) {
                    // use the base level
                    level = dta.stats[levels[0]].baselevel;
                } else {
                    // no stats for the real base level, use the first level for which we have stats
                    tuj.SetParams({page: 'item', id: '' + itemId + '.' + levels[0]});
                    return;
                }
            } else {
                // didn't find the level specified in the URL in the list of levels for this house
                tuj.SetParams({page: 'item', id: '' + itemId});
                return;
            }
        } else if (!urlLevel) {
            // level === false
            level = 0; // so array indexes work
        } else if (dta.stats[urlLevel].baselevel == urlLevel) {
            // the level specified in the URL is the base level, which makes it redundant. remove it.
            tuj.SetParams({page: 'item', id: '' + itemId});
            return;
        }

        var fullItemName = '[' + dta.stats[level]['name_' + tuj.locale] + ']';

        var ta = libtuj.ce('a');
        ta.href = 'http://' + tuj.lang.wowheadDomain + '.wowhead.com/item=' + itemId;
        ta.target = '_blank';
        ta.rel = 'noopener noreferrer';
        ta.className = 'item';
        if (level != dta.stats[level].baselevel || levels.length > 1) {
{'fraction_non_alphanumeric': 0.13793103448275862, 'fraction_numerical': 0.0070594623947868584, 'mean_word_length': 1.2769420976715433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6371415', 'n_tokens_mistral': 3230, 'n_tokens_neox': 3029, 'n_words': 674}