// no ES6 here! /* eslint-disable no-console, no-var */ (function() { var abConfigString = '{"name":"ab-2024-11-11","groups":[{"probability":30,"name":"gruppe-a","searchConfig":"\/search\/documents?tuning="},{"probability":30,"name":"gruppe-b","searchConfig":"\/search\/documents?tuning=stopwords:false,type.use.additive:false,compression.use:false,asym.decay:false,time.override.enabled:false,txt.function:true,function.scoremode:avg,function.boostmode:multiply,synthetic.episode.size:7,decay.shape:gauss,weight.decay:128.0,scale:90d,future.scale:7d,boost.category:6.0,boost.brand:9.0,time.override.teilbereich:heute.de,time.override.weight:15.0,time.override.scale:14d,time.override.future.scale:2d,boost.field.newsOverline:0.2,boost.field.title:0.2,boost.field.title2:0.05,boost.field.title3:0.05,boost.field.text:0.1,boost.field.description:0.02,boost.field.editorialTagsFulltext:0.15,compression.target.score:10.0,compression.range:1.0,compression.max.input.score:150.0,boost.ctype.brand:15.0,boost.ctype.news:5.0,boost.ctype.episode:5.0,boost.ctype.clip:4.0,boost.type.page-video:5.0,boost.type.page-index:2.0,weight.type:0.3,weight.category:1.5,weight.brand:1.5,boost.field.category:0.05,boost.field.brand:0.07,weight.txt.function:0.01,decayFunctionOffset:0d,past.decay:0.5,future.decay:0.5"},{"probability":30,"name":"gruppe-c","searchConfig":"\/search\/documents?tuning="},{"probability":5,"name":"gruppe-d","searchConfig":"\/search\/documents?tuning="},{"probability":5,"name":"gruppe-e","searchConfig":"\/search\/documents?tuning="}],"expirationDate":"2024-11-11T08:00:00 01:00"}'; var abConfig = null; var abGroup = null; function getConfig() { return abConfig; } function getGroup() { if (!abGroup) { abGroup = selectGroup(abConfig); } return abGroup; } function getConfigName() { return abConfig && abConfig.name; } function getExpirationDate() { return abConfig && abConfig.expirationDate; } function selectGroup(config) { var groups = config && config.groups; if (!groups || !Array.isArray(groups) || !groups.length) { console.warn('cannot select ab group, groups data not valid:', groups); return null; } var sum = groups.reduce(addProbabilities, 0); var rand = Math.round(Math.random() * sum); var selectedGroup = groups.reduce(findGroupForSelectedProbability, { 'start': 0, 'index': 0, 'probability': rand }); var groupData = groups[selectedGroup.index]; return { 'name': config.name, 'expirationDate': config.expirationDate, 'group': groupData.name, 'searchConfig': groupData.searchConfig, } } function addProbabilities(accumulator, currentValue) { return accumulator currentValue.probability; } function findGroupForSelectedProbability(accumulator, currentValue, currentIndex) { var start = accumulator.start; var end = start currentValue.probability; var probability = accumulator.probability; return { 'start': end, 'index': (probability >= start && probability < end) ? currentIndex : accumulator.index, 'probability': accumulator.probability, }; } ///////////////////////////////////////////////////////////////////////// try { abConfig = JSON.parse(abConfigString); } catch(e) { console.warn('Error parsing abGroup config!', e.message); } window.abselector = { 'getConfig': getConfig, 'getGroup': getGroup, 'getConfigName': getConfigName, 'getExpirationDate': getExpirationDate, }; }());