public void validateExperimentBuckets(List<Bucket> buckets) { if ((buckets == null) || (buckets.isEmpty())) { throw new IllegalArgumentException("No experiment buckets specified"); } Double totalAllocation = 0.0; Integer numControl = 0; Integer nOpen = 0; for (Bucket bucket : buckets) { Double val = bucket.getAllocationPercent(); totalAllocation += val; if (bucket.getState() == Bucket.State.OPEN || bucket.getState() == null) { nOpen++; } if (bucket.isControl()) { numControl++; } } if ((nOpen > 0 && Math.abs(totalAllocation - 1.0) > 1e-12) || (nOpen == 0 && Double.doubleToRawLongBits(totalAllocation) != 0)) { throw new IllegalArgumentException("Total allocation must be 1.0 (or 0.0 if all buckets are closed/empty"); } if (numControl > 1) { throw new IllegalArgumentException("Only one bucket may be specified as a control bucket"); } }
private Builder(Bucket other) { instance = new Bucket(); instance.experimentID = other.getExperimentID(); instance.label = other.getLabel(); instance.control = other.isControl() == null ? Boolean.FALSE : other.isControl(); instance.allocationPercent = other.getAllocationPercent(); instance.description = other.getDescription(); instance.payload = other.getPayload(); instance.state = other.getState(); }
@Override public int compare(Bucket b1, Bucket b2) { return b1.getAllocationPercent().compareTo( b2.getAllocationPercent()); } });
public Bucket build() { Bucket result = new Bucket(); result.setControl(instance.isControl()); result.setState(instance.getState()); result.setLabel(instance.getLabel()); result.setPayload(instance.getPayload()); result.setAllocationPercent(instance.getAllocationPercent()); result.setDescription(instance.getDescription()); result.setExperimentID(instance.getExperimentID()); instance = null; return result; } }
protected Bucket selectBucket(List<Bucket> buckets) { final double dieRoll = rollDie(); // Sort the buckets consistently (by label) Collections.sort(buckets, new Comparator<Bucket>() { @Override public int compare(Bucket b1, Bucket b2) { return b1.getAllocationPercent().compareTo( b2.getAllocationPercent()); } }); Double totalProbability = 0.0d; Bucket bucket = null; for (Bucket candidateBucket : buckets) { totalProbability += candidateBucket.getAllocationPercent(); if (dieRoll < totalProbability) { bucket = candidateBucket; break; } } return bucket; }
public void validateExperimentBuckets(List<Bucket> buckets) { if ((buckets == null) || (buckets.isEmpty())) { throw new IllegalArgumentException("No experiment buckets specified"); } Double totalAllocation = 0.0; Integer numControl = 0; Integer nOpen = 0; for (Bucket bucket : buckets) { Double val = bucket.getAllocationPercent(); totalAllocation += val; if (bucket.getState() == Bucket.State.OPEN || bucket.getState() == null) { nOpen++; } if (bucket.isControl()) { numControl++; } } if ((nOpen > 0 && Math.abs(totalAllocation - 1.0) > 1e-12) || (nOpen == 0 && Double.doubleToRawLongBits(totalAllocation) != 0)) { throw new IllegalArgumentException("Total allocation must be 1.0 (or 0.0 if all buckets are closed/empty"); } if (numControl > 1) { throw new IllegalArgumentException("Only one bucket may be specified as a control bucket"); } }
/** * This method takes a list of buckets and transforms it to the {@link BucketDetail}s that are needed * for later extension. * * @param buckets a list of {@link Bucket}s */ public void addBuckets(List<Bucket> buckets) { List<BucketDetail> details = buckets.stream() .map(b -> new BucketDetail(b.getLabel(), b.isControl(), b.getAllocationPercent(), b.getState(), b.getDescription())) .collect(Collectors.toList()); setBuckets(details); }
/** * {@inheritDoc} */ @Override public BucketList adjustAllocationPercentages(Experiment experiment, Bucket newBucket) { double remainingAlloc = 1. - newBucket.getAllocationPercent(); BucketList bucketList = buckets.getBuckets(experiment.getID(), false /* don't check experiment again */); BucketList newBuckets = new BucketList(); for (Bucket bucket : bucketList.getBuckets()) { if (bucket.getLabel().equals(newBucket.getLabel())) { continue; } double newAlloc = roundToTwo(remainingAlloc * bucket.getAllocationPercent()); LOGGER.debug("Add Bucket: setting allocation percentage for bucket " + bucket.getLabel() + " in experiment " + experiment.getID() + " to: " + newAlloc); Bucket.Builder builder = Bucket.from(bucket).withAllocationPercent(newAlloc); Bucket updatedBucket = builder.build(); newBuckets.addBucket(updatedBucket); if (!Experiment.State.DRAFT.equals(experiment.getState()) && Double.compare(bucket.getAllocationPercent(), updatedBucket.getAllocationPercent()) != 0) { // this is a system event, so no user needed eventLog.postEvent(new BucketChangeEvent(experiment, updatedBucket, "allocation", String.valueOf(bucket.getAllocationPercent()), String.valueOf(updatedBucket.getAllocationPercent()))); } } return newBuckets; }
if (updates.getAllocationPercent() != null && !updates.getAllocationPercent().equals(bucket.getAllocationPercent())) { builder.withAllocationPercent(updates.getAllocationPercent()); changeData = new Bucket.BucketAuditInfo("allocation", bucket.getAllocationPercent().toString(), updates.getAllocationPercent().toString()); changeList.add(changeData);
args.add(b.getState().name()); if (b.getAllocationPercent() != null) { CQL += "allocation = ?,"; args.add(b.getAllocationPercent());
if (bucketList.getBuckets().get(i).getAllocationPercent() != null) { hasval = true; break; for (int i = 0; i < bucketListSize; i++) { Bucket b = bucketList.getBuckets().get(i); if (b.getAllocationPercent() != null) { SQL.append("WHEN ? then ? "); if (b.getAllocationPercent() != null) { args.add(b.getLabel().toString()); args.add(b.getAllocationPercent().toString());
&& !bucket.getLabel().toString().trim().isEmpty(), "Bucket external label cannot be null or an empty string"); Preconditions.checkArgument(bucket.getAllocationPercent() >= 0d, "Bucket allocation percentage must be greater than or " + "equal to 0.0"); Preconditions.checkArgument(bucket.getAllocationPercent() <= 1d, "Bucket allocation percentage must be less than or equal to 1.0"); ? bucket.getDescription() : "", bucket.getAllocationPercent(), bucket.isControl(), bucket.getPayload() != null
/** * {@inheritDoc} */ @Override public void createBucket(Bucket newBucket) { LOGGER.debug("Creating bucket {}", newBucket); Preconditions.checkNotNull(newBucket, "Parameter \"newBucket\" cannot be null"); final Bucket.State STATE = Bucket.State.OPEN; try { bucketAccessor.insert(newBucket.getExperimentID().getRawID(), newBucket.getLabel().toString(), newBucket.getDescription(), newBucket.getAllocationPercent(), newBucket.isControl(), newBucket.getPayload(), STATE.name()); } catch (Exception e) { LOGGER.error("Error creating bucket {}", newBucket, e); throw new RepositoryException("Could not create bucket \"" + newBucket + "\" because " + e, e); } }
private Builder(Bucket other) { instance = new Bucket(); instance.experimentID = other.getExperimentID(); instance.label = other.getLabel(); instance.control = other.isControl() == null ? Boolean.FALSE : other.isControl(); instance.allocationPercent = other.getAllocationPercent(); instance.description = other.getDescription(); instance.payload = other.getPayload(); instance.state = other.getState(); }
bucketAccessor.updateBucket( bucket.getDescription() != null ? bucket.getDescription() : "", bucket.getAllocationPercent(), bucket.isControl(), bucket.getPayload() != null ? bucket.getPayload() : "",
Double bucketB = roundToTwo(bucket.getAllocationPercent()); Double A = buck.getAllocationPercent(); newPct = A + (A * bucketB / ((Double) 1. - bucketB)); } else { newPct = buck.getAllocationPercent(); buck.getAllocationPercent().toString(), newPct.toString()); changeList.add(changeData); allChanges.add(changeList);
public Bucket build() { Bucket result = new Bucket(); result.setControl(instance.isControl()); result.setState(instance.getState()); result.setLabel(instance.getLabel()); result.setPayload(instance.getPayload()); result.setAllocationPercent(instance.getAllocationPercent()); result.setDescription(instance.getDescription()); result.setExperimentID(instance.getExperimentID()); instance = null; return result; } }
} else if (event instanceof BucketCreateEvent) { property = "allocation"; after = String.valueOf(((BucketCreateEvent) event).getBucket().getAllocationPercent());
@Override public void createBucket(Bucket newBucket) throws RepositoryException { final String SQL = "insert into bucket (" + "experiment_id, description, label, allocation_percent, is_control, payload, state) " + "values (?,?,?,?,?,?,?)"; try { newTransaction().insert( SQL, newBucket.getExperimentID(), newBucket.getDescription() != null ? newBucket.getDescription() : "", newBucket.getLabel().toString(), newBucket.getAllocationPercent(), newBucket.isControl() != null ? newBucket.isControl() : false, newBucket.getPayload() != null ? newBucket.getPayload() : "", Bucket.State.OPEN.toString()); } catch (WasabiException e) { throw e; } catch (Exception e) { throw new RepositoryException("Could not create bucket \"" + newBucket + "\"", e); } }
if (bucket != null) { Bucket newBucket = Bucket.newInstance(experimentID, bucketLabel) .withAllocationPercent(bucket.getAllocationPercent()) .withControl(bucket.isControl()) .withDescription(bucket.getDescription())