Skip to content

Commit

Permalink
cleanup cont'd
Browse files Browse the repository at this point in the history
  • Loading branch information
jusyc committed Jun 22, 2018
1 parent 05bc28a commit be912ab
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ public class BasicBatchPipeline implements Pipeline {
private String ratioMetric;
private double minSupport;
private double minRiskRatio;


private int numRows;
private String columnFiltersJson;


public BasicBatchPipeline (PipelineConfig conf) {
public BasicBatchPipeline(PipelineConfig conf) {
inputURI = conf.get("inputURI");

classifierType = conf.get("classifier", "percentile");
Expand All @@ -64,32 +61,14 @@ public BasicBatchPipeline (PipelineConfig conf) {
cutoff = conf.get("cutoff", 1.0);
}

pctileHigh = conf.get("includeHi",true);
pctileHigh = conf.get("includeHi", true);
pctileLow = conf.get("includeLo", true);
predicateStr = conf.get("predicate", "==").trim();

summarizerType = conf.get("summarizer", "apriori");
attributes = conf.get("attributes");
ratioMetric = conf.get("ratioMetric", "globalRatio");

//Allowing conversion from integer b/c of type confusion by UI (via JSON.stringify)
if(conf.get("minRatioMetric", 3.0) instanceof Double) {
minRiskRatio = (double) conf.get("minRatioMetric", 3.0);
}
else {
minRiskRatio = (double) (int) conf.get("minRatioMetric", 3);
}

if(conf.get("minSupport", 0.01) instanceof Double) {
minSupport = (double) conf.get("minSupport", 0.01);
}
else {
minSupport= (double) (int) conf.get("minSupport", 0);
}

numRows = conf.get("numRows", -1); //-1 indicating all
columnFiltersJson = conf.get("columnFilters", "");

minRiskRatio = conf.get("minRatioMetric", 3.0);
minSupport = conf.get("minSupport", 0.01);
numThreads = conf.get("numThreads", Runtime.getRuntime().availableProcessors());
}

Expand All @@ -103,14 +82,14 @@ public Classifier getClassifier() throws MacroBaseException {
return classifier;
}
case "predicate": {
if (isStrPredicate){
if (isStrPredicate) {
PredicateClassifier classifier = new PredicateClassifier(metric, predicateStr, strCutoff);
return classifier;
}
PredicateClassifier classifier = new PredicateClassifier(metric, predicateStr, cutoff);
return classifier;
}
default : {
default: {
throw new MacroBaseException("Bad Classifier Type");
}
}
Expand Down Expand Up @@ -147,8 +126,7 @@ public DataFrame loadData() throws Exception {
Map<String, Schema.ColType> colTypes = new HashMap<>();
if (isStrPredicate) {
colTypes.put(metric, Schema.ColType.STRING);
}
else{
} else {
colTypes.put(metric, Schema.ColType.DOUBLE);
}
List<String> requiredColumns = new ArrayList<>(attributes);
Expand Down Expand Up @@ -181,32 +159,4 @@ public Explanation results() throws Exception {

return output;
}

@Override
public DataFrame getRows() throws Exception {
long startTime = System.currentTimeMillis();
DataFrame df = loadData();
long elapsed = System.currentTimeMillis() - startTime;

log.info("Loading time: {} ms", elapsed);
log.info("{} rows", df.getNumRows());
log.info("Metric: {}", metric);
log.info("Attributes: {}", attributes);

if(!columnFiltersJson.equals("")){
Map<String, Object> columnFilters = PipelineUtils.jsonStringToMap(columnFiltersJson);
for(String columnName: columnFilters.keySet()) {
Predicate<Object> columnPredicate = (i) -> (i.equals(columnFilters.get(columnName)));
df = df.filter(columnName, columnPredicate);
log.info("Filtering on column {} == {}", columnName, columnFilters.get(columnName));
}
}

if(numRows >= 0){
df = df.limit(numRows);
log.info("Limiting on {} rows", numRows);
}

return df;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ public APLExplanation results() throws Exception {
return explanation;
}

@Override
public DataFrame getRows() {
return null;
}

private Map<String, Schema.ColType> getColTypes() throws MacroBaseException {
Map<String, Schema.ColType> colTypes = new HashMap<>();
colTypes.put(countColumn, Schema.ColType.DOUBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@

public interface Pipeline {
Explanation results() throws Exception;
DataFrame getRows() throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static void main(String[] args) {

post("/sql", RestServer::processSQLQuery, RestServer::toJsonString);
post("/query", RestServer::processBasicBatchQuery, RestServer::toJsonString);
post("/rows", RestServer::getRows, RestServer::toJsonString);

exception(Exception.class, (exception, request, response) -> {
log.error("An exception occurred: ", exception);
Expand All @@ -70,16 +69,6 @@ public static Explanation processBasicBatchQuery(
return p.results();
}

public static DataFrame getRows(
Request req, Response res
) throws Exception {
//res.type()
PipelineConfig conf = PipelineConfig.fromJsonString(req.body());
Pipeline p = PipelineUtils.createPipeline(conf);
DataFrame df = p.getRows();
return df;
}

public static String toJsonString(Object o) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(o);
Expand Down

0 comments on commit be912ab

Please sign in to comment.