Commit dc444401 authored by Eirik Alvær's avatar Eirik Alvær

Fixes #2147 - Enrich correlation and regression output with variable metadata

parent ebea5451
......@@ -13,6 +13,7 @@ import com.nesstar.rest.common.ResourceExtractor;
import com.nesstar.rest.common.ETag;
import com.nesstar.rest.common.CorrelationClassVariables;
import com.nesstar.rest.result_object_makers.MetadataMaker;
import com.nesstar.rest.result_object_makers.VariableMetadataMaker;
import com.yammer.metrics.annotation.Timed;
import javax.servlet.http.HttpServletRequest;
......@@ -25,6 +26,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
......@@ -59,11 +61,8 @@ public final class CorrelationResource extends AbstractResource {
classVariables.setCorrelationVariables(ResourceExtractor.getVariables(correlationVariables, classVariables.getServer()));
classVariables.setWeightVariables(ResourceExtractor.getVariables(weightVariables, classVariables.getServer()));
classVariables.setCaseSubsetExpression(caseSubset);
try {
if (missingDeletion != null) {
classVariables.setMissingDeletionType(classVariables.getMissingDeletionType());
} catch (NullPointerException e) {
//ignore
}
CorrelationResult correlationResult = performCorrelation(classVariables);
ETag etag = ETag.generateEtagForCorrelation(classVariables, request);
......@@ -91,7 +90,7 @@ public final class CorrelationResource extends AbstractResource {
return classVariables.getStudy().correlate(correlationBuilder);
}
private Object getCorrelationObject(CorrelationResult correlationResult, CorrelationClassVariables classVariables) throws IOException, NotAuthorizedException {
private Object getCorrelationObject(CorrelationResult correlationResult, CorrelationClassVariables classVariables) throws NotAuthorizedException, IOException {
HashMap<String, Object> resultValuesMap = new LinkedHashMap<String, Object>();
List<Variable> correlationVariables = classVariables.getCorrelationVariables();
for (int i = 0; i < correlationVariables.size(); i++) {
......@@ -106,6 +105,10 @@ public final class CorrelationResource extends AbstractResource {
HashMap<String, Object> correlation = new LinkedHashMap<String, Object>();
correlation.put("resultValuesMap", resultValuesMap);
List<Variable> variables = new ArrayList<Variable>(classVariables.getCorrelationVariables());
variables.addAll(classVariables.getWeightVariables());
correlation.put("variablesMetadata", VariableMetadataMaker.getSimpleVariablesMetadata(variables));
HashMap<String, Object> result = new LinkedHashMap<String, Object>();
result.put(MetadataMaker.DATA_ENVELOPE_NAME, correlation);
......
......@@ -15,6 +15,7 @@ import com.nesstar.rest.common.ETag;
import com.nesstar.rest.common.RegressionClassVariables;
import com.nesstar.rest.result_object_makers.ErrorMaker;
import com.nesstar.rest.result_object_makers.MetadataMaker;
import com.nesstar.rest.result_object_makers.VariableMetadataMaker;
import com.yammer.metrics.annotation.Timed;
import javax.servlet.http.HttpServletRequest;
......@@ -68,13 +69,9 @@ public final class RegressionResource extends AbstractResource {
classVariables.setIndependentVariables(ResourceExtractor.getVariables(independentVariables, server));
classVariables.setWeightVariables(ResourceExtractor.getVariables(weightVariables, server));
classVariables.setCaseSubsetExpression(caseSubset);
try {
if (missingDeletion != null) {
classVariables.setMissingDeletionType(classVariables.getMissingDeletionType());
} catch (NullPointerException e) {
//ignore
}
LinearRegressionResult linearRegressionResult = performRegression(classVariables);
ETag etag = ETag.generateEtagForRegression(classVariables, request);
setETagHeader(etag, response);
......@@ -125,6 +122,11 @@ public final class RegressionResource extends AbstractResource {
}
regression.put("independentVariablesData", independentVariablesData);
List<Variable> variables = new ArrayList<Variable>(classVariables.getIndependentVariables());
variables.add(classVariables.getDependentVariable());
variables.addAll(classVariables.getWeightVariables());
regression.put("variablesMetadata", VariableMetadataMaker.getSimpleVariablesMetadata(variables));
HashMap<String, Object> result = new LinkedHashMap<String, Object>();
result.put(MetadataMaker.DATA_ENVELOPE_NAME, regression);
return result;
......
......@@ -13,6 +13,7 @@ import com.nesstar.api.Category;
import com.nesstar.api.DdiElement;
import com.nesstar.api.DdiList;
import com.nesstar.api.NotAuthorizedException;
import com.nesstar.api.Variable;
import com.nesstar.rest.common.DdiUtils;
public final class VariableMetadataMaker {
......@@ -49,4 +50,19 @@ public final class VariableMetadataMaker {
return result;
}
public static Object getSimpleVariablesMetadata(List<Variable> variables) throws IOException, NotAuthorizedException {
HashMap<String, Object> result = new LinkedHashMap<String, Object>();
for (Variable variable : variables) {
result.put(variable.getId(), getSimpleVariableMetadata(variable));
}
return result;
}
private static Object getSimpleVariableMetadata(Variable variable) throws IOException, NotAuthorizedException {
HashMap<String, Object> result = new LinkedHashMap<String, Object>();
result.put("name", variable.getName());
result.put("label", variable.getLabel());
return result;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment