public static Context valueOf(String value) { return new Context(value); }
@Override public List<Map> getCountsFromRollups(Experiment.ID experimentID, Parameters parameters) throws RepositoryException { try { //build and execute SQL queries for counts from rollups String sqlQuery = "select day, bucket_label as bid, cumulative as c, action, impression_count as ic, " + "impression_user_count as iuc, action_count as ac, action_user_count as auc " + "from experiment_rollup where experiment_id = ? and context = ? order by day asc"; return transaction.select(sqlQuery, experimentID, parameters.getContext().getContext()); } catch (Exception e) { throw new RepositoryException("error reading counts from MySQL rollups", e); } }
@Override public String toString() { return "Event={\"timestamp\":\"" + (timestamp != null ? timestamp : emptyString) + "\"" + ",\"type\":\"" + (type != null ? type.toString() : emptyString) + "\"" + ",\"name\":\"" + (name != null ? name.toString() : emptyString) + "\"" + ",\"context\":\"" + (context != null ? context.toString() : emptyString) + "\"" + ",\"payload\":\"" + (payload != null ? payload.toString() : emptyString) + "\"" + ",\"value\":\"" + (value != null ? value : emptyString) + "\"}"; }
private static void doSomething(Context context, PerformingInterface perform) throws IOException { String traceId = null, tagId = null; for (Record record : context.getContext().readCacheTable("subscribe")) { getTraceIdAndTagIdFromRecord(record, traceId, tagId); if (traceSet.contains(traceId) == false) continue; if (!checkTagIdIsNumber(tagId)) { context.getCounter("Error", "tag_id not a number").increment(1); continue; } perform.accept(tagId, traceId); } }
@Override @Timed public Assignment getAssignment(User.ID userID, Application.Name appName, Experiment.ID experimentID, Context context) { ListenableFuture<Result<ExperimentUserByUserIdContextAppNameExperimentId>> resultFuture = experimentUserIndexAccessor.asyncSelectBy(userID.toString(), appName.toString(), experimentID.getRawID(), context.toString()); Result<ExperimentUserByUserIdContextAppNameExperimentId> assignmentResult = UninterruptibleUtil.getUninterruptibly(resultFuture); Stream<ExperimentUserByUserIdContextAppNameExperimentId> assignmentResultStream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(assignmentResult.iterator(), Spliterator.ORDERED), false); final Stream<Assignment.Builder> assignmentBuilderStream = assignmentResultStream.map(t -> { Assignment.Builder builder = Assignment.newInstance(Experiment.ID.valueOf(t.getExperimentId())) .withUserID(User.ID.valueOf(t.getUserId())) .withContext(Context.valueOf(t.getContext())); if (nonNull(t.getBucket()) && !t.getBucket().trim().isEmpty()) { builder.withBucketLabel(Bucket.Label.valueOf(t.getBucket())); } return builder; }); Optional<Assignment> assignmentOptional = getAssignmentFromStream(experimentID, userID, context, assignmentBuilderStream); return assignmentOptional.isPresent() ? assignmentOptional.get() : null; }
@Override public int hashCode() { int result = fromTime != null ? fromTime.hashCode() : 0; result = 31 * result + (toTime != null ? toTime.hashCode() : 0); result = 31 * result + (confidenceLevel != null ? confidenceLevel.hashCode() : 0); result = 31 * result + (effectSize != null ? effectSize.hashCode() : 0); result = 31 * result + (actions != null ? actions.hashCode() : 0); result = 31 * result + (singleShot != null ? singleShot.hashCode() : 0); result = 31 * result + (metric != null ? metric.hashCode() : 0); result = 31 * result + (mode != null ? mode.hashCode() : 0); result = 31 * result + (context != null ? context.hashCode() : 0); result = 31 * result + (metricImpl != null ? metricImpl.hashCode() : 0); result = 31 * result + (timeZone != null ? timeZone.hashCode() : 0); return result; }
List params = new ArrayList(); params.add(experimentID); params.add(parameters.getContext().getContext());
/** * Convert Assignment object of single-assignment to the response MAP expected by the end user. * <p> * Single-assignment response map can contain: * - assignment * - payload * - status * - cache * - context * * @param assignment * @return response map */ protected Map<String, Object> toSingleAssignmentResponseMap(final Assignment assignment) { Map<String, Object> response = newHashMap(); // Only include `assignment` property if there is a definitive assignment, either to a bucket or not if (assignment.getStatus().isDefinitiveAssignment()) { response.put("assignment", nonNull(assignment.getBucketLabel()) ? assignment.getBucketLabel().toString() : null); if (nonNull(assignment.getBucketLabel())) { response.put("payload", assignment.getPayload()); } } response.put("status", assignment.getStatus()); response.put("cache", assignment.getStatus().isDefinitiveAssignment()); if (assignment.getContext() != null) { response.put("context", assignment.getContext().toString()); } return response; }
private static void imYourNewMethod(Context context,Boolean isAddTag){ String traceId = null, tagId = null; for (Record record : context.getContext().readCacheTable("subscribe")) { getTraceIdAndTagIdFromRecord(record, traceId, tagId); if (traceSet.contains(traceId) == false) continue; if (!checkTagIdIsNumber(tagId)) { context.getCounter("Error", "tag_id not a number").increment(1); continue; } if(isAddTag){ Vector<String> ret = traceListMap.get(tagId); if (ret == null) { ret = new Vector<String>(); } ret.add(traceId); traceListMap.put(tagId, ret); }else{ tagSet.add(tagId); } }
@Override public List<Map> getImpressionRows(Experiment.ID experimentID, Parameters parameters) throws RepositoryException { try { //build and execute SQL queries for counts Date from_ts = parameters.getFromTime(); Date to_ts = parameters.getToTime(); String sqlBase = "bucket_label as bid, count(user_id) as c, count(distinct user_id) as cu"; String sqlParams = " where experiment_id = ? and context = ?"; List params = new ArrayList(); params.add(experimentID); params.add(parameters.getContext().getContext()); if (from_ts != null) { params.add(from_ts); sqlParams += " and timestamp >= ?"; } if (to_ts != null) { params.add(to_ts); sqlParams += " and timestamp <= ?"; } Object[] bucketSqlData = new Object[params.size()]; params.toArray(bucketSqlData); String sqlImpressions = "select " + sqlBase + " from event_impression" + sqlParams + " group by bucket_label"; List<Map> impressionRows = transaction.select(sqlImpressions, bucketSqlData); return impressionRows; } catch (Exception e) { throw new RepositoryException("error reading actions rows from MySQL", e); } }
assignment.getExperimentID().toString(): null); eventJson.put("context", assignment != null && assignment.getContext() != null ? assignment.getContext().toString(): null); eventJson.put("epochTimestamp", event != null && event.getTimestamp() != null ? event.getTimestamp().getTime(): null);
private static Stream<Record> validRecords(Context context) throws IOException { return context.getContext().readCacheTable("subscribe").stream() .filter(r -> { if (!traceSet.contains(traceId(r))) { return false; } try { Integer.parseInt(tagId(r)); return true; } catch (NumberFormatException e) { context.getCounter("Error", "tag_id not a number").increment(1); return false; } }); } private static String traceId(Record record) { return record.get("trace_id").toString(); } private static String tagId(Record record) { return record.get("tag_id").toString(); }
private Builder(String ctx) { instance = new Context(ctx); }
parameters.getContext().getContext());
if (LOGGER.isDebugEnabled()) LOGGER.debug("Sent prioritiesAccessor.asyncGetPriorities({})", appName); userAssignmentsFuture = experimentUserIndexAccessor.asyncSelectBy(userID.toString(), appName.toString(), context.toString()); if (LOGGER.isDebugEnabled()) LOGGER.debug("Sent experimentUserIndexAccessor.asyncSelectBy({}, {}, {})", userID, appName, context);
private Builder(String ctx) { instance = new Context(ctx); }
LOGGER.debug("Query user assignment export for experimentID={}, at dateHour={}", experimentID.getRawID(), dateHour); if (ignoreNullBucket) { result = userAssignmentExportAccessor.selectBy(experimentID.getRawID(), dateHour, context.getContext(), false); } else { result = userAssignmentExportAccessor.selectBy(experimentID.getRawID(), dateHour, context.getContext());
/** * Make entries in experiment_user_index table * * @param assignments */ private void indexExperimentsToUser(List<Pair<Experiment, Assignment>> assignments) { try { Session session = driver.getSession(); final BatchStatement batchStatement = new BatchStatement(BatchStatement.Type.UNLOGGED); assignments.forEach(pair -> { Assignment assignment = pair.getRight(); LOGGER.debug("assignment={}", assignment); BoundStatement bs; if (isNull(assignment.getBucketLabel())) { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID()); } else { bs = experimentUserIndexAccessor.insertBoundStatement(assignment.getUserID().toString(), assignment.getContext().toString(), assignment.getApplicationName().toString(), assignment.getExperimentID().getRawID(), assignment.getBucketLabel().toString()); } batchStatement.add(bs); }); session.execute(batchStatement); LOGGER.debug("Finished experiment_user_index"); } catch (Exception e) { LOGGER.error("Error occurred while adding data in to experiment_user_index", e); } }
public static Context valueOf(String value) { return new Context(value); }
List params = new ArrayList(); params.add(experimentID); params.add(parameters.getContext().getContext());