@plasmicapp/loader-splits
Advanced tools
Comparing version 1.0.49 to 1.0.51
@@ -135,2 +135,3 @@ "use strict"; | ||
splits.forEach((split) => { | ||
var _a; | ||
const key = getSplitKey(split); | ||
@@ -145,10 +146,39 @@ const knownVal = getKnownValue == null ? void 0 : getKnownValue(key); | ||
if (split.type === "experiment") { | ||
let p = getRandomValue(split.id); | ||
chosenSlice = split.slices[numSlices - 1]; | ||
for (let i = 0; i < numSlices; i++) { | ||
if (p - split.slices[i].prob <= 0) { | ||
chosenSlice = split.slices[i]; | ||
break; | ||
if (opts.useSeedBucketing) { | ||
const seed = opts.traits[PLASMIC_SEED]; | ||
const buckets = []; | ||
const totalBuckets = (_a = opts.seedRange) != null ? _a : 1; | ||
let avaiableBuckets = totalBuckets; | ||
for (let i = 0; i < numSlices; i++) { | ||
const slice = split.slices[i]; | ||
const numBuckets = Math.min( | ||
Math.floor(slice.prob * totalBuckets), | ||
avaiableBuckets | ||
); | ||
for (let j = 0; j < numBuckets; j++) { | ||
buckets.push(slice.id); | ||
} | ||
avaiableBuckets -= numBuckets; | ||
} | ||
p -= split.slices[i].prob; | ||
if (buckets.length > 0) { | ||
const shuffleRand = getSeededRandomFunction(split.id); | ||
for (let i = 0; i < buckets.length; i++) { | ||
const j = Math.floor(shuffleRand() * (i + 1)); | ||
[buckets[i], buckets[j]] = [buckets[j], buckets[i]]; | ||
} | ||
const sliceIdx = +(seed != null ? seed : "0") % buckets.length; | ||
chosenSlice = split.slices.find((s) => s.id === buckets[sliceIdx]); | ||
} else { | ||
chosenSlice = split.slices[numSlices - 1]; | ||
} | ||
} else { | ||
let p = getRandomValue(split.id); | ||
chosenSlice = split.slices[numSlices - 1]; | ||
for (let i = 0; i < numSlices; i++) { | ||
if (p - split.slices[i].prob <= 0) { | ||
chosenSlice = split.slices[i]; | ||
break; | ||
} | ||
p -= split.slices[i].prob; | ||
} | ||
} | ||
@@ -155,0 +185,0 @@ } else if (split.type === "segment") { |
@@ -14,2 +14,4 @@ import type { Split } from '@plasmicapp/loader-fetcher'; | ||
enableUnseededExperiments?: boolean; | ||
useSeedBucketing?: boolean; | ||
seedRange?: number; | ||
}): Record<string, string>; | ||
@@ -16,0 +18,0 @@ |
@@ -99,2 +99,3 @@ var __defProp = Object.defineProperty; | ||
splits.forEach((split) => { | ||
var _a; | ||
const key = getSplitKey(split); | ||
@@ -109,10 +110,39 @@ const knownVal = getKnownValue == null ? void 0 : getKnownValue(key); | ||
if (split.type === "experiment") { | ||
let p = getRandomValue(split.id); | ||
chosenSlice = split.slices[numSlices - 1]; | ||
for (let i = 0; i < numSlices; i++) { | ||
if (p - split.slices[i].prob <= 0) { | ||
chosenSlice = split.slices[i]; | ||
break; | ||
if (opts.useSeedBucketing) { | ||
const seed = opts.traits[PLASMIC_SEED]; | ||
const buckets = []; | ||
const totalBuckets = (_a = opts.seedRange) != null ? _a : 1; | ||
let avaiableBuckets = totalBuckets; | ||
for (let i = 0; i < numSlices; i++) { | ||
const slice = split.slices[i]; | ||
const numBuckets = Math.min( | ||
Math.floor(slice.prob * totalBuckets), | ||
avaiableBuckets | ||
); | ||
for (let j = 0; j < numBuckets; j++) { | ||
buckets.push(slice.id); | ||
} | ||
avaiableBuckets -= numBuckets; | ||
} | ||
p -= split.slices[i].prob; | ||
if (buckets.length > 0) { | ||
const shuffleRand = getSeededRandomFunction(split.id); | ||
for (let i = 0; i < buckets.length; i++) { | ||
const j = Math.floor(shuffleRand() * (i + 1)); | ||
[buckets[i], buckets[j]] = [buckets[j], buckets[i]]; | ||
} | ||
const sliceIdx = +(seed != null ? seed : "0") % buckets.length; | ||
chosenSlice = split.slices.find((s) => s.id === buckets[sliceIdx]); | ||
} else { | ||
chosenSlice = split.slices[numSlices - 1]; | ||
} | ||
} else { | ||
let p = getRandomValue(split.id); | ||
chosenSlice = split.slices[numSlices - 1]; | ||
for (let i = 0; i < numSlices; i++) { | ||
if (p - split.slices[i].prob <= 0) { | ||
chosenSlice = split.slices[i]; | ||
break; | ||
} | ||
p -= split.slices[i].prob; | ||
} | ||
} | ||
@@ -119,0 +149,0 @@ } else if (split.type === "segment") { |
@@ -135,2 +135,3 @@ "use strict"; | ||
splits.forEach((split) => { | ||
var _a; | ||
const key = getSplitKey(split); | ||
@@ -145,10 +146,39 @@ const knownVal = getKnownValue == null ? void 0 : getKnownValue(key); | ||
if (split.type === "experiment") { | ||
let p = getRandomValue(split.id); | ||
chosenSlice = split.slices[numSlices - 1]; | ||
for (let i = 0; i < numSlices; i++) { | ||
if (p - split.slices[i].prob <= 0) { | ||
chosenSlice = split.slices[i]; | ||
break; | ||
if (opts.useSeedBucketing) { | ||
const seed = opts.traits[PLASMIC_SEED]; | ||
const buckets = []; | ||
const totalBuckets = (_a = opts.seedRange) != null ? _a : 1; | ||
let avaiableBuckets = totalBuckets; | ||
for (let i = 0; i < numSlices; i++) { | ||
const slice = split.slices[i]; | ||
const numBuckets = Math.min( | ||
Math.floor(slice.prob * totalBuckets), | ||
avaiableBuckets | ||
); | ||
for (let j = 0; j < numBuckets; j++) { | ||
buckets.push(slice.id); | ||
} | ||
avaiableBuckets -= numBuckets; | ||
} | ||
p -= split.slices[i].prob; | ||
if (buckets.length > 0) { | ||
const shuffleRand = getSeededRandomFunction(split.id); | ||
for (let i = 0; i < buckets.length; i++) { | ||
const j = Math.floor(shuffleRand() * (i + 1)); | ||
[buckets[i], buckets[j]] = [buckets[j], buckets[i]]; | ||
} | ||
const sliceIdx = +(seed != null ? seed : "0") % buckets.length; | ||
chosenSlice = split.slices.find((s) => s.id === buckets[sliceIdx]); | ||
} else { | ||
chosenSlice = split.slices[numSlices - 1]; | ||
} | ||
} else { | ||
let p = getRandomValue(split.id); | ||
chosenSlice = split.slices[numSlices - 1]; | ||
for (let i = 0; i < numSlices; i++) { | ||
if (p - split.slices[i].prob <= 0) { | ||
chosenSlice = split.slices[i]; | ||
break; | ||
} | ||
p -= split.slices[i].prob; | ||
} | ||
} | ||
@@ -155,0 +185,0 @@ } else if (split.type === "segment") { |
{ | ||
"version": "1.0.49", | ||
"version": "1.0.51", | ||
"license": "MIT", | ||
@@ -51,3 +51,3 @@ "types": "./dist/index.d.ts", | ||
}, | ||
"gitHead": "9216f61b95565cb9ff8639fa7f2d2640a320e731" | ||
"gitHead": "9638cc7f1d2af2fbbf9966b4096449e9c82b375b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49166
670