@Override public ExperimentCounts clone() { ExperimentCounts cloned = (ExperimentCounts) super.clone(); if (buckets != null) { Map<Bucket.Label, BucketCounts> clonedBuckets = new HashMap<>(); for (Entry<Label, BucketCounts> entry : buckets.entrySet()) { clonedBuckets.put(entry.getKey(), entry.getValue().clone()); } cloned.setBuckets(clonedBuckets); } return cloned; }
public Builder withBucketCounts(BucketCounts value) { this.item.label = value.getLabel(); this.item.impressionCounts = value.getImpressionCounts(); this.item.jointActionCounts = value.getJointActionCounts(); this.item.actionCounts = value.getActionCounts(); return this; }
public Builder() { this.item = new BucketCounts(); }
perDayBuckets.put(bucketEntry.getKey(), bucketEntry.getValue().clone()); cumulativeBuckets.put(bucketEntry.getKey(), bucketEntry.getValue().clone()); cumulativeBuckets.get(bucketLabel).setImpressionCounts(bucketImpressions); cumulativeBuckets.get(bucketLabel).setJointActionCounts(bucketJointActions); } else { perDayBuckets.get(bucketLabel).setImpressionCounts(bucketImpressions); perDayBuckets.get(bucketLabel).setJointActionCounts(bucketJointActions); cumulativeBuckets.get(bucketLabel).addActionCounts(actionName, bucketAction); } else { perDayBuckets.get(bucketLabel).addActionCounts(actionName, bucketAction); perDayBuckets.put(bucketEntry.getKey(), bucketEntry.getValue().clone()); cumulativeBuckets.put(bucketEntry.getKey(), bucketEntry.getValue().clone());
@Override public Map<Bucket.Label, BucketCounts> getEmptyBuckets(Experiment.ID experimentID) throws RepositoryException { try { List<Map> bucketRows = transaction.select("select label from bucket where experiment_id=?", experimentID); Counts impressions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Counts jointActions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Map<Event.Name, ActionCounts> perDayBucketActions = new HashMap<>(); BucketCounts blankBucket = new BucketCounts.Builder().withImpressionCounts(impressions) .withJointActionCounts(jointActions) .withActionCounts(perDayBucketActions).build(); Map<Bucket.Label, BucketCounts> buckets = new HashMap<>(); for (Map bucketRow : bucketRows) { Bucket.Label externalLabel = Bucket.Label.valueOf((String) bucketRow.get("label")); BucketCounts bucket = blankBucket.clone(); bucket.setLabel(externalLabel); buckets.put(externalLabel, bucket); } return buckets; } catch (Exception e) { throw new RepositoryException("error reading actions rows from MySQL", e); } }
BucketCounts bucket = buckets.get(Bucket.Label.valueOf((String) actionRow.get("bid"))); Event.Name actionName = Event.Name.valueOf((String) actionRow.get(ACTION)); bucket.addActionCounts(actionName, new ActionCounts.Builder() .withActionName(actionName) .withEventCount((Long) actionRow.get("c")) BucketCounts bucket = buckets.get(Bucket.Label.valueOf((String) impressionRow.get("bid"))); bucket.setImpressionCounts(new Counts.Builder() .withEventCount((Long) impressionRow.get("c")) .withUniqueUserCount((Long) impressionRow.get("cu")) BucketCounts bucket = buckets.get(Bucket.Label.valueOf((String) jointActionsRow.get("bid"))); bucket.setJointActionCounts(new Counts.Builder() .withEventCount((Long) jointActionsRow.get("c")) .withUniqueUserCount((Long) jointActionsRow.get("cu"))
/** * Creates a list of BucketStatistics objects from a list of BucketCounts objects. * * @param buckets a complete list of BucketCounts for this experiment * @param metric the binomial metric to use for statistics calculations * @param effectSize the effect size of interest to use for statistics calculations * @return Map of bucket label and bucket stats */ Map<Bucket.Label, BucketStatistics> calculateBucketStatistics(Map<Bucket.Label, BucketCounts> buckets, BinomialMetric metric, double effectSize, Parameters.Mode mode) { Map<Bucket.Label, BucketStatistics> bucketsWithStats = new HashMap<>(); for (BucketCounts bucket : buckets.values()) { Bucket.Label bucketLabel = bucket.getLabel(); BucketStatistics bucketWithStats = new BucketStatistics.Builder() .withBucketCounts(bucket) .withBucketComparisons(new HashMap<Bucket.Label, BucketComparison>()) .build(); analysisTools.generateRate(bucketWithStats, metric); bucketsWithStats.put(bucketLabel, bucketWithStats); } analysisTools.generateBucketComparison(bucketsWithStats, metric, effectSize, mode); return bucketsWithStats; }
bucket.setImpressionCounts(new Counts.Builder() .withEventCount(Long.valueOf((Integer) rollupRow.get("ic"))) .withUniqueUserCount(Long.valueOf((Integer) rollupRow.get("iuc"))) .build()); bucket.setJointActionCounts(new Counts.Builder() .withEventCount(Long.valueOf((Integer) rollupRow.get("ac"))) .withUniqueUserCount(Long.valueOf((Integer) rollupRow.get("auc"))) } else { Event.Name actionName = Event.Name.valueOf((String) rollupRow.get(ACTION)); bucket.addActionCounts(actionName, new ActionCounts.Builder() .withActionName(actionName) .withEventCount(Long.valueOf((Integer) rollupRow.get("ac")))
.withBucketCounts(bucket) .build(); Bucket.Label bucketLabel = bucket.getLabel(); analysisTools.generateRate(bucketWithStats, metric); bucketsWithStats.put(bucketLabel, bucketWithStats);
public Builder withBucketCounts(BucketCounts value) { this.item.label = value.getLabel(); this.item.impressionCounts = value.getImpressionCounts(); this.item.jointActionCounts = value.getJointActionCounts(); this.item.actionCounts = value.getActionCounts(); return this; }
/** * {@inheritDoc} */ @Override public ExperimentCounts calculateExperimentCounts(Collection<BucketCounts> bucketsSet) { Map<Bucket.Label, BucketCounts> buckets = new HashMap<>(); for (BucketCounts bucket : bucketsSet) { buckets.put(bucket.getLabel(), bucket); } Counts jointActionCounts = new Counts(0, 0); Counts impressionCounts = new Counts(0, 0); Map<Event.Name, ActionCounts> experimentActionCounts = new HashMap<>(); for (BucketCounts bucket : bucketsSet) { jointActionCounts.addCount(bucket.getJointActionCounts()); impressionCounts.addCount(bucket.getImpressionCounts()); Map<Event.Name, ActionCounts> bucketActionCounts = bucket.getActionCounts(); for (ActionCounts bucketCounts : bucketActionCounts.values()) { Event.Name actionName = bucketCounts.getActionName(); ActionCounts currentExperimentCounts = experimentActionCounts.get(actionName); if (currentExperimentCounts == null) { experimentActionCounts.put(actionName, bucketCounts.clone()); } else { currentExperimentCounts.addCount(bucketCounts); } } } return new ExperimentCounts.Builder().withActionCounts(experimentActionCounts).withBuckets(buckets) .withImpressionCounts(impressionCounts).withJointActionCounts(jointActionCounts) .build(); }