zfinder's notebooks

  • chooseVariation test - /zfinder/choosevariation-test
    Last edited 5 months ago
    const chooseVariation = require("choose-variation") const randomstring = require("randomstring") const experiments = [ { name: 'newMlRanking', testId: '202307061807', seed: 'x-user-uid', value: [ 'on', 'off', 'noMlRanking' ], weights: [ 0.33333, 0.33333, 0.33334 ] }, { name: 'itemView', testId: '202306072011', seed: 'x-user-uid', value: [ 'vertical', 'horizontal', 'mini' ], weights: [ 0.33333, 0.33333, 0.33334 ] } ] const countDuplicateObjects = (array) => { const countMap = {} array.forEach(obj => { const key = JSON.stringify(obj) countMap[key] = (countMap[key] || 0) + 1 }) return countMap } const chooseVariations = (experiments, seed) => { const variations = experiments.reduce((acc, experiment) => { const variation = chooseVariation.chooseVariation(seed, experiment.salt + experiment.name + experiment.testId, experiment.weights) acc[experiment.name] = variation === -1 ? `default:${experiment.testId}` : `${experiment.value[variation]}:${experiment.testId}` return acc }, {}) return variations } const usersGroups = [] for (i=0; i<100000; i++) { const userUid = `${randomstring.generate()}.letu.ru` usersGroups.push(chooseVariations(experiments, userUid)) } countDuplicateObjects(usersGroups)