<commit_before>/**
 * @file mip-pix 统计组件
 * @author baidu-authors<>, liangjiaying<<EMAIL>>
 */
define(function (require) {
    var customElem = require('customElement').create();
    var util = require('util');

    /**
     * 替换请求链接中的参数
     * @param {string} src      用户填写在mip-pix中的src
     * @param {string} paraName key, 如"title"
     * @param {string} paraVal  value, 如当前时间戳
     */
    function addParas(src, paraName, paraVal) {
        var paraNameQ = '{' + paraName + '}';
        if (src.indexOf(paraNameQ) > -1) {
            return src.replace(new RegExp(paraNameQ, 'g'), paraVal);
        }
        src += src.indexOf('?') > -1 ? '&' : '?';
        return src + paraName + '=' + paraVal;
    }

    /**
     * 从body获取mip-expeirment实验分组
     * @param  {string} attr 实验名
     * @return {string}      实验分组
     */
    function getBodyAttr(attr) {
        var body = document.getElementsByTagName('body')[0];
        return body.getAttribute(attr) || 'default'
    }

    customElem.prototype.firstInviewCallback = function () {
        // 获取统计所需参数
        var ele = this.element;
        var src = ele.getAttribute('src');
        var host = window.location.href;
        var title = (document.querySelector('title') || {}).innerHTML || '';
        var time = Date.now();

        // 替换通用参数
        src = addParas(src, 't', time);
        src = addParas(src, 'title', encodeURIComponent(title));
        src = addParas(src, 'host', encodeURIComponent(host));

        // 增加对<mip-experiment>支持，获取实验分组
        var expReg = /mip-x-((\w|-|\d|_)+)/g;
        var matchExpArr = src.match(expReg);
        for (i in matchExpArr) {
            var matchExp = matchExpArr[i];
            src = addParas(src, matchExp, getBodyAttr(matchExp));
        }

        // 去除匹配失败的其餘{參數}
        src = src.replace(new RegExp("{.+?}", 'g'), '');
        // 去除其餘 '{', '}' 確保輸出不包含 MIP 定义的语法
        src = src.replace(new RegExp("{|}", 'g'), '');
        
        // 创建请求img
        var image = new Image();
        image.src = src;
        image.setAttribute('width', 0);
        image.setAttribute('height', 0);
        ele.setAttribute('width', '');<commit_msg>mip-pix 關鍵字 TIME, TITLE, HOST 改為大寫<commit_after>/**
 * @file mip-pix 统计组件
 * @author baidu-authors<>, liangjiaying<<EMAIL>>
 */
define(function (require) {
    var customElem = require('customElement').create();
    var util = require('util');

    /**
     * 替换请求链接中的参数
     * @param {string} src      用户填写在mip-pix中的src
     * @param {string} paraName key, 如"title"
     * @param {string} paraVal  value, 如当前时间戳
     */
    function addParas(src, paraName, paraVal) {
        var paraNameQ = '{' + paraName + '}';
        if (src.indexOf(paraNameQ) > -1) {
            return src.replace(new RegExp(paraNameQ, 'g'), paraVal);
        }
        src += src.indexOf('?') > -1 ? '&' : '?';
        return src + paraName + '=' + paraVal;
    }

    /**
     * 从body获取mip-expeirment实验分组
     * @param  {string} attr 实验名
     * @return {string}      实验分组
     */
    function getBodyAttr(attr) {
        var body = document.getElementsByTagName('body')[0];
        return body.getAttribute(attr) || 'default'
    }

    customElem.prototype.firstInviewCallback = function () {
        // 获取统计所需参数
        var ele = this.element;
        var src = ele.getAttribute('src');
        var host = window.location.href;
        var title = (document.querySelector('title') || {}).innerHTML || '';
        var time = Date.now();

        // 替换通用参数
        src = addParas(src, 'TIME', time);
        src = addParas(src, 'TITLE', encodeURIComponent(title));
        src = addParas(src, 'HOST', encodeURIComponent(host));

        // 增加对<mip-experiment>支持，获取实验分组
        var expReg = /mip-x-((\w|-|\d|_)+)/g;
        var matchExpArr = src.match(expReg);
        for (i in matchExpArr) {
            var matchExp = matchExpArr[i];
            src = addParas(src, matchExp, getBodyAttr(matchExp));
        }

        // 去除匹配失败的其餘{參數}
        src = src.replace(new RegExp("{.+?}", 'g'), '');
        // 去除其餘 '{', '}' 確保輸出不包含 MIP 定义的语法
        src = src.replace(new RegExp("{|}", 'g'), '');
        
        // 创建请求img
        var image = new Image();
        image.src = src;
        image.setAttribute('width', 0);
        image.setAttribute('height', 0);
        ele.setAttribute('width', '');
{'fraction_non_alphanumeric': 0.1675913083680074, 'fraction_numerical': 0.002311604253351826, 'mean_word_length': 2.1839587932303166, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '4246441', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1631, 'n_words': 291}