Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
fix parse exception of ad result response (#132)
Browse files Browse the repository at this point in the history
* fix parse exception of ad result response
  • Loading branch information
ylwu-amzn authored Dec 10, 2019
1 parent 3728752 commit 5d837c3
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.List;

import com.amazon.elasticsearch.ad.model.FeatureData;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
import org.elasticsearch.common.io.stream.OutputStreamStreamOutput;
Expand All @@ -14,8 +15,6 @@
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;

import com.amazon.elasticsearch.ad.model.FeatureData;

public class AnomalyResultResponse extends ActionResponse implements ToXContentObject {
public static final String ANOMALY_GRADE_JSON_KEY = "anomalyGrade";
public static final String CONFIDENCE_JSON_KEY = "confidence";
Expand All @@ -39,10 +38,10 @@ public AnomalyResultResponse(StreamInput in) throws IOException {
int size = in.readVInt();
features = new ArrayList<FeatureData>();
for (int i=0; i<size; i++) {
String featureId = in.readString();
String featureName = in.readString();
double featureValue = in.readDouble();
// the client does not need feature id, so we make it null
features.add(new FeatureData(null, featureName, featureValue));
features.add(new FeatureData(featureId, featureName, featureValue));
}
}

Expand All @@ -65,7 +64,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeDouble(confidence);
out.writeVInt(features.size());
for(FeatureData feature : features) {
// the client does not need feature id, so we omit it
out.writeString(feature.getFeatureId());
out.writeString(feature.getFeatureName());
out.writeDouble(feature.getData());
}
Expand Down

0 comments on commit 5d837c3

Please sign in to comment.