List params = new ArrayList(); params.add(experimentID); params.add(parameters.getContext().getContext());
@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); } }
@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); } }
parameters.getContext().getContext());
List params = new ArrayList(); params.add(experimentID); params.add(parameters.getContext().getContext());
@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); } }
/** * Retrieves the analytics data for the buckets and the experiment itself. * * @param experimentDetail the {@link ExperimentDetail} that needs to be enhanced with analytics data * @param params {@link Parameters} for the Analytics calls- containing the context for example * @return the same object with additional analytic information */ ExperimentDetail getAnalyticData(ExperimentDetail experimentDetail, Parameters params) { // analytics data is only necessary for running/paused/terminated experiments if (!experimentDetail.getState().equals(Experiment.State.DRAFT)) { //experiment level analytics AssignmentCounts assignmentCounts = analytics.getAssignmentCounts(experimentDetail.getId(), params.getContext()); if (!Objects.isNull(assignmentCounts)) { long onlyBucketAssignments = assignmentCounts.getTotalUsers().getBucketAssignments(); experimentDetail.setTotalNumberUsers(onlyBucketAssignments); } ExperimentStatistics expStats = analytics.getExperimentStatistics(experimentDetail.getId(), params); getBucketDetails(experimentDetail, expStats, assignmentCounts); } return experimentDetail; }