<commit_before>//beta browsers not handled
//+ not handled
var Log = require('./logger'),
    logger = new Log(global.logLevel || 'info');

var ConfigParser = {
  finalBrowsers: [],

  bsBrowsers: null,

  parse: function(client, browser_config, callback) {
    client.getBrowsers(function(error, browsers) {
      if(error) {
        logger.info('Error getting browsers list from BrowserStack');
        logger.info(error);
        throw new Error('Error getting browsers list from BrowserStack');
      }
      ConfigParser.bsBrowsers = browsers;
      for (var key in browser_config) {
        var entry = browser_config[key];
        ConfigParser.finalBrowsers.push(ConfigParser.getBrowserObject(entry));
      }
      callback(ConfigParser.finalBrowsers);
    });
    return;
  },

  setBrowserVersion: function(browserObject, verStr) {
    var filteredBrowsers = ConfigParser.bsBrowsers.map(function(currentValue) {
      if (currentValue.browser.toLowerCase() === browserObject.browser) {
        return (browserObject.mobile ? currentValue.os_version : currentValue.browser_version);
      }
    }).filter(function(currentValue, index, array) {
      return currentValue && array.indexOf(currentValue) === index;
    }).sort(function(a, b) {
      return parseFloat(a) - parseFloat(b);
    });
    if (verStr === 'current' || verStr === 'latest') {
      return filteredBrowsers[filteredBrowsers.length - 1];
    }
    else if (verStr === 'previous') {
      return filteredBrowsers[filteredBrowsers.length - 2];
    }
  },

  populateOsAndOsVersion: function(browserObject) {
    if (!(browserObject.os && browserObject.os_version)) {
      if (browserObject.mobile) {

        var mobileFiltered = ConfigParser.bsBrowsers.filter(function(currentValue) {
          return currentValue.browser.toLowerCase() === browserObject.browser && parseFloat(currentValue.os_version).toPrecision(4) === parseFloat(browserObject.os_version).toPrecision(4);
        });

        browserObject = mobileFiltered[Math.floor(Math.random() * mobileFiltered.length)];
      }
      else {

        var windowsFiltered = ConfigParser.bsBrowsers.filter(function(currentValue) {
          return currentValue.os === 'Windows' && currentValue.browser_version.match(/metro/i) == null && currentValue.browser === browserObject.browser && parseFloat(currentValue.browser_version).toPrecision(4) === parseFloat(browserObject.browser_version).toPrecision(4);
        });

        var osxFiltered = ConfigParser.bsBrowsers.filter(function(currentValue) {
          return currentValue.os === 'OS X' && currentValue.browser === browserObject.browser && parseFloat(currentValue.browser_version).toPrecision(4) === parseFloat(browserObject.browser_version).toPrecision(4);
        });
        browserObject = windowsFiltered.length > 0 ? windowsFiltered[Math.floor(Math.random() * windowsFiltered.length)] : osxFiltered[Math.floor(Math.random() * osxFiltered.length)];
      }

    }
    return browserObject;
  },

  getBrowserObject: function(entry) {
    var browserObject = {};
    var version = null;
    var sliceStart = 1;
    if (typeof(entry) === 'string') {
      var browserData = entry.split('_');
      var lindex = browserData.length - 1;
      if (browserData[0] === 'mobile' || browserData[0] === 'android' || (browserData[0] === 'opera' && browserData[1] === 'browser')) {
        browserObject.browser = browserData[0] + ' ' + browserData[1];
        browserObject.mobile = true;
        sliceStart = 2;
      }
      else {
        browserObject.browser = browserData[0];
      }<commit_msg>using last stable version when using compact config<commit_after>//beta browsers not handled
//+ not handled
var Log = require('./logger'),
    logger = new Log(global.logLevel || 'info');

var ConfigParser = {
  finalBrowsers: [],

  bsBrowsers: null,

  parse: function(client, browser_config, callback) {
    client.getBrowsers(function(error, browsers) {
      if(error) {
        logger.info('Error getting browsers list from BrowserStack');
        logger.info(error);
        throw new Error('Error getting browsers list from BrowserStack');
      }
      ConfigParser.bsBrowsers = browsers;
      for (var key in browser_config) {
        var entry = browser_config[key];
        ConfigParser.finalBrowsers.push(ConfigParser.getBrowserObject(entry));
      }
      callback(ConfigParser.finalBrowsers);
    });
    return;
  },

  setBrowserVersion: function(browserObject, verStr) {
    var filteredBrowsers = ConfigParser.bsBrowsers.map(function(currentValue) {
      if (currentValue.browser.toLowerCase() === browserObject.browser) {
        return (browserObject.mobile ? currentValue.os_version : currentValue.browser_version);
      }
    }).filter(function(currentValue, index, array) {
      return currentValue && array.indexOf(currentValue) === index;
    }).sort(function(a, b) {
      return parseFloat(a) - parseFloat(b);
    });
    if (verStr === 'current' || verStr === 'latest') {
      return ConfigParser.checkIfLatestFlagApplicable(browserObject) ? 'latest' : filteredBrowsers[filteredBrowsers.length - 1];
    }
    else if (verStr === 'previous') {
      return ConfigParser.checkIfLatestFlagApplicable(browserObject) ? 'latest-1' : filteredBrowsers[filteredBrowsers.length - 2];
    }
  },

  checkIfLatestFlagApplicable: function(browserObject) {
    return !browserObject.mobile && ['chrome', 'firefox', 'edge'].includes(browserObject.browser)
  },

  populateOsAndOsVersion: function(browserObject) {
    if (!(browserObject.os && browserObject.os_version)) {
      if (browserObject.mobile) {

        var mobileFiltered = ConfigParser.bsBrowsers.filter(function(currentValue) {
          return currentValue.browser.toLowerCase() === browserObject.browser && parseFloat(currentValue.os_version).toPrecision(4) === parseFloat(browserObject.os_version).toPrecision(4);
        });

        browserObject = mobileFiltered[Math.floor(Math.random() * mobileFiltered.length)];
      }
      else {

        var windowsFiltered = ConfigParser.bsBrowsers.filter(function(currentValue) {
          return currentValue.os === 'Windows' && currentValue.browser_version.match(/metro/i) == null && currentValue.browser === browserObject.browser && ((browserObject.browser_version && browserObject.browser_version.indexOf('latest') > -1) || parseFloat(currentValue.browser_version).toPrecision(4) === parseFloat(browserObject.browser_version).toPrecision(4));
        });

        var osxFiltered = ConfigParser.bsBrowsers.filter(function(currentValue) {
          return currentValue.os === 'OS X' && currentValue.browser === browserObject.browser && ((browserObject.browser_version && browserObject.browser_version.indexOf('latest')) > -1 || parseFloat(currentValue.browser_version).toPrecision(4) === parseFloat(browserObject.browser_version).toPrecision(4));
        });

        let filteredObject = windowsFiltered.length > 0 ? windowsFiltered[Math.floor(Math.random() * windowsFiltered.length)] : osxFiltered[Math.floor(Math.random() * osxFiltered.length)];
        if (browserObject.browser_version.indexOf('latest') > -1) {
          filteredObject.browser_version = browserObject.browser_version
        }
        browserObject = filteredObject
      }

    }
    return browserObject;
  },

  getBrowserObject: function(entry) {
    var browserObject = {};
    var version = null;
    var sliceStart = 1;
    if (typeof(entry) === 'string') {
      var browserData = entry.split('_');
      var lindex = browserData.length - 1;
      if (browserData[0] === 'mobile' || browserData[0] === 'android' || (browserData[0] === 'opera' && browserData[1] === 'browser')) {
        browserObject.browser = browserData[0] + ' ' + browserData[1];
        browserObject.mobile = true;
        sliceStart = 2;
      }
      else {
        browserObject.browser = browserData[0];
      }
{'fraction_non_alphanumeric': 0.13391612821487395, 'fraction_numerical': 0.005321170657544659, 'mean_word_length': 3.68208778173191, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '5789061', 'n_tokens_mistral': 2285, 'n_tokens_neox': 2221, 'n_words': 398}