test_class.file: frontend/src/test/java/macrobase/runtime/resources/AnalyzeResourceTest.java
test_class.identifier: AnalyzeResourceTest
test_case.body: @Test
      public void testMADAnalyzer() throws Exception {
          MacroBaseConf conf = new MacroBaseConf()
                  .set(MacroBaseConf.TARGET_PERCENTILE, 0.99) // analysis
                  .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");
  
          // this is not a great API...
          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());
      }
test_case.class_method_signature: AnalyzeResourceTest.testMADAnalyzer()
test_case.full_signature: @Test public void testMADAnalyzer()
test_case.identifier: testMADAnalyzer
test_case.invocations: set set set set set set set loadSystemProperties newArrayList newArrayList newArrayList getAnalysis assertTrue size get assertEquals size getItemSets newHashSet newHashSet getItems get getItemSets assertTrue contains getColumn remove getColumn assertTrue contains getValue remove getValue assertEquals size assertEquals size
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMADAnalyzer()
focal_class.declarator: log = LoggerFactory.getLogger(SchemaResource.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(SchemaResource.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.file: frontend/src/main/java/macrobase/runtime/resources/AnalyzeResource.java
focal_class.identifier: AnalyzeResource
focal_class.class_method_signature: AnalyzeResource.AnalyzeResource(MacroBaseConf conf)
focal_class.full_signature: public  AnalyzeResource(MacroBaseConf conf)
focal_class.identifier: AnalyzeResource
focal_class.modifiers: public
focal_class.parameters: (MacroBaseConf conf)
focal_class.signature:  AnalyzeResource(MacroBaseConf conf)
focal_class.class_method_signature: AnalyzeResource.getAnalysis(AnalysisRequest request)
focal_class.full_signature: @POST @Consumes(MediaType.APPLICATION_JSON) public AnalysisResponse getAnalysis(AnalysisRequest request)
focal_class.identifier: getAnalysis
focal_class.modifiers: @POST @Consumes(MediaType.APPLICATION_JSON) public
focal_class.parameters: (AnalysisRequest request)
focal_class.return: AnalysisResponse
focal_class.signature: AnalysisResponse getAnalysis(AnalysisRequest request)
focal_class.superclass: extends BaseResource
focal_method.body: @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);
  
              // temp hack to enable CSV loading
              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;
      }
focal_method.class_method_signature: AnalyzeResource.getAnalysis(AnalysisRequest request)
focal_method.full_signature: @POST @Consumes(MediaType.APPLICATION_JSON) public AnalysisResponse getAnalysis(AnalysisRequest request)
focal_method.identifier: getAnalysis
focal_method.invocations: addAll addAll set set set set set set contains set replace set forName getString getName newInstance error getName run initialize size getItemSets warn size getItemSets setItemSets subList getItemSets report error getStackTrace
focal_method.modifiers: @POST @Consumes(MediaType.APPLICATION_JSON) public
focal_method.parameters: (AnalysisRequest request)
focal_method.return: AnalysisResponse
focal_method.signature: AnalysisResponse getAnalysis(AnalysisRequest request)