private Parameters createParameters(final Context context) { Parameters parameters = new Parameters(); parameters.setContext(context); return parameters; }
public static Name valueOf(String value) { return new Name(value); }
public static Payload valueOf(String value) { return new Payload(value); }
void recordEvent(Assignment assignment, Event event) throws Exception { String actionNameString = event.getName().toString(); String payload = (event.getPayload() != null) ? event.getPayload().toString() : null; String userIDString = assignment.getUserID().toString(); String context = (event.getContext() != null) ? event.getContext().getContext() : "PROD"; if (event.getType().equals(Event.Type.IMPRESSION)) { transaction.insert("INSERT INTO event_impression " + "(user_id, experiment_id, bucket_label, context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, context, event.getTimestamp(), payload); } else { transaction.insert("INSERT INTO event_action " + userIDString, experimentIDValue, bucketLabelValue, actionNameString, context, event.getTimestamp(), payload);
boolean circumventRollup(final Experiment.ID experimentID, final Parameters parameters) { Experiment exp = getExperimentIfExists(experimentID); Date to = parameters.getToTime(); if (parameters.getFromTime() != null || parameters.getActions() != null) { return true; } else if (to != null) { // Get the date of the most recent rollup. Check to make sure that the toTime specified is >= last rollup // Return true if the date of the most recent rollup is before the specified toTime return analyticsRepository.checkMostRecentRollup(exp, parameters, to); } else { return false; } }
@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) + "\"}"; }
List<Date> getDateHourRangeList(Experiment.ID experimentID, Parameters parameters) { final Experiment id = experimentRepository.getExperiment(experimentID); if (isNull(id)) { throw new ExperimentNotFoundException(experimentID); } final Optional<Date> from_ts = Optional.ofNullable(parameters.getFromTime()); final Optional<Date> to_ts = Optional.ofNullable(parameters.getToTime()); // Fetches the relevant partitions for a given time window where the user assignments data resides. return getUserAssignmentPartitions( from_ts.orElseGet(id::getCreationTime), to_ts.orElseGet(Date::new) ); }
/** * {@inheritDoc} */ @Override public void recordEvents(Application.Name applicationName, Experiment.Label experimentLabel, User.ID userID, EventList events, Set<Context> contextSet) { Map<Context, Assignment> assignmentHashMap = getAssignments(userID, applicationName, experimentLabel, contextSet); for (Event event : events.getEvents()) { Assignment assignment = assignmentHashMap.get(event.getContext()); if (assignment != null) { postEventToMysql(assignment, event); ingestEventToRealTimeSystems(applicationName, experimentLabel, event, assignment); } } }
public void setName(Event.Name value) { name = value; if (name.toString().equals(IMPRESSION)) { type = Type.IMPRESSION; } else { //todo: for other event types, will need to check this.value type = Type.BINARY_ACTION; } }
@Override public void serialize(Payload payload, JsonGenerator generator, SerializerProvider provider) throws IOException { generator.writeString(payload.toString()); } }
@Override public Object value(Transaction transaction) { ExperimentCounts counts = getExperimentRollup(experimentId, parameters); return calculateExperimentStatistics(counts, parameters.getMetricImpl(), parameters.getEffectSize(), parameters.getMode()); } });
@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 Name deserialize(JsonParser parser, DeserializationContext context) throws IOException { return Name.valueOf(parser.getText()); } }
void addActionsToSql(Parameters parameters, StringBuilder sqlParams, List params) { List<String> actions = parameters.getActions(); if (actions != null) { int num_actions = actions.size(); if (num_actions >= 1) { sqlParams.append(" and action in (?"); params.add(actions.get(0)); } for (int num = 1; num < num_actions; num++) { sqlParams.append(",?"); params.add(actions.get(num)); } if (num_actions >= 1) { sqlParams.append(") "); } } }
public T setDate(String date) { date_ = date; return getThis(); }
@Override public Payload deserialize(JsonParser parser, DeserializationContext context) throws IOException { return Payload.valueOf(parser.getText()); } }
private void postEventToMysql(Assignment assignment, Event event) { try { mysqlExecutor.execute(makeEventEnvelope(assignment, event)); } catch (Exception e) { LOGGER.warn("Mysql error: Unable to record event " + event.toString() + " for the user " + assignment.getUserID().toString() + " for context " + assignment.getContext(), e); } }
@Override public void serialize(Name name, JsonGenerator generator, SerializerProvider provider) throws IOException { generator.writeString(name.toString()); } }
public void setPayload(Payload value) { if (value == null || value.toString() == null) { throw new IllegalArgumentException("Invalid value for payload. Payload should not be null."); } else if (value.toString().length() > 4096) { throw new IllegalArgumentException( String.format("Invalid value for payload \"%s\". Payload should be 4096 characters or less", value)); } payload = value; }
@Override public List<Map> getRollupRows(Experiment.ID experimentId, String rollupDate, Parameters parameters) throws RepositoryException { // TODO enable direct mapping of DateMidnight List rollupRows; try { //build and execute SQL queries for counts from rollups String sqlQuery = "select bucket_label as bid, 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 cumulative = ? and day = ? and context = ?"; rollupRows = transaction.select(sqlQuery, experimentId, true, rollupDate, parameters.getContext().getContext()); return rollupRows; } catch (Exception e) { throw new RepositoryException("error reading rollup rows from MySQL", e); } }