AnalyzeResource extends BaseResource { @POST @Consumes(MediaType.APPLICATION_JSON) public AnalysisResponse getAnalysis(AnalysisRequest request) { AnalysisResponse response = new AnalysisResponse(); try { List<String> allMetrics = new ArrayList<>(); allMetrics.addAll(request.highMetrics); allMetrics.addAll(request.lowMetrics); conf.set(MacroBaseConf.DB_URL, request.pgUrl); conf.set(MacroBaseConf.BASE_QUERY, request.baseQuery); conf.set(MacroBaseConf.ATTRIBUTES, request.attributes); conf.set(MacroBaseConf.METRICS, allMetrics); conf.set(MacroBaseConf.LOW_METRIC_TRANSFORM, request.lowMetrics); conf.set(MacroBaseConf.USE_PERCENTILE, true); if (request.baseQuery.contains("csv: conf.set(MacroBaseConf.CSV_INPUT_FILE, request.baseQuery.replace("csv: conf.set(MacroBaseConf.DATA_LOADER_TYPE, MacroBaseConf.DataIngesterType.CSV_LOADER); } Class c = Class.forName(conf.getString(MacroBaseConf.PIPELINE_NAME, BasicBatchedPipeline.class.getName())); Object ao = c.newInstance(); if (!(ao instanceof Pipeline)) { log.error("{} is not an instance of Pipeline! Exiting...", ao); response.errorMessage = "Requested pipeline of type "+c.getName()+ " is not a Pipeline"; return response; } Pipeline pipeline = (Pipeline) ao; List<AnalysisResult> results = pipeline.initialize(conf).run(); for (AnalysisResult result : results) { if (result.getItemSets().size() > 1000) { log.warn("Very large result set! {}; truncating to 1000", result.getItemSets().size()); result.setItemSets(result.getItemSets().subList(0, 1000)); } } response.results = results; MacroBase.reporter.report(); } catch (Exception e) { log.error("An error occurred while processing a request: {}", e); response.errorMessage = ExceptionUtils.getStackTrace(e); } return response; } AnalyzeResource(MacroBaseConf conf); @POST @Consumes(MediaType.APPLICATION_JSON) AnalysisResponse getAnalysis(AnalysisRequest request);  }
@Test public void testMADAnalyzer() throws Exception { MacroBaseConf conf = new MacroBaseConf() .set(MacroBaseConf.TARGET_PERCENTILE, 0.99) .set(MacroBaseConf.USE_PERCENTILE, true) .set(MacroBaseConf.MIN_OI_RATIO, .01) .set(MacroBaseConf.MIN_SUPPORT, .01) .set(MacroBaseConf.RANDOM_SEED, 0) .set(MacroBaseConf.DATA_LOADER_TYPE, MacroBaseConf.DataIngesterType.CSV_LOADER) .set(MacroBaseConf.CSV_INPUT_FILE, "src/test/resources/data/simple.csv"); conf.loadSystemProperties(); AnalyzeResource resource = new AnalyzeResource(conf); AnalyzeResource.AnalysisRequest r = new AnalyzeResource.AnalysisRequest(); r.attributes = Lists.newArrayList("A1", "A2", "A3", "A4"); r.highMetrics = Lists.newArrayList(); r.lowMetrics = Lists.newArrayList("A5"); r.pgUrl = "should be unused"; r.baseQuery = "also should be unused"; List<AnalysisResult> arl = resource.getAnalysis(r).results; assertTrue(arl.size() == 1); AnalysisResult ar = arl.get(0); assertEquals(1, ar.getItemSets().size()); HashSet<String> toFindColumn = Sets.newHashSet("A1", "A2", "A3", "A4"); HashSet<String> toFindValue = Sets.newHashSet("0", "1", "2", "3"); for (ColumnValue cv : ar.getItemSets().get(0).getItems()) { assertTrue(toFindColumn.contains(cv.getColumn())); toFindColumn.remove(cv.getColumn()); assertTrue(toFindValue.contains(cv.getValue())); toFindValue.remove(cv.getValue()); } assertEquals(0, toFindColumn.size()); assertEquals(0, toFindValue.size()); }