Commit fb08daef authored by Sören Henning's avatar Sören Henning

Parameter for JSONExporter

parent 7e224896
......@@ -10,7 +10,7 @@ public class AnomalyDetectionConfiguration extends Configuration {
// Create the stages
final MeassurementsGeneratorStage generator = new MeassurementsGeneratorStage(x -> 500 * Math.sin(x / 60) + 2000, 250, 0.01, 1000, Duration.ofSeconds(1),
900);
3600);
final AnomalyDetectionStage anomalyDetector = new AnomalyDetectionStage();
final SimpleAlertStage alerter = new SimpleAlertStage();
......
package anomalydetection;
import java.io.File;
import java.time.Duration;
import anomalydetection.aggregation.MeanAggregator;
......@@ -30,7 +31,7 @@ public class AnomalyDetectionStage extends CompositeStage {
final MeasurementForecastDecorationStage measurementForecastDecorator = new MeasurementForecastDecorationStage();
final AnomalyScoreCalculatorStage anomalyScoreCalculator = new AnomalyScoreCalculatorStage();
final PrinterStage printer = new PrinterStage(); // TODO Temp
final JSONExporter jsonExporter = new JSONExporter(); // TODO Temp
final JSONExporter jsonExporter = new JSONExporter(new File("values.json")); // TODO Temp
final StorageStage storager = new StorageStage();
this.inputPort = measurementDistributor.getInputPort();
......
package anomalydetection;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
......@@ -15,9 +16,9 @@ public class JSONExporter extends AbstractConsumerStage<AnomalyScoredMeasurement
private final JSONWriter writer;
private final Writer baseWriter;
public JSONExporter() {
public JSONExporter(final File file) {
try {
this.baseWriter = new FileWriter("values.json");
this.baseWriter = new FileWriter(file);
this.writer = new JSONWriter(this.baseWriter);
writer.array();
} catch (JSONException | IOException e) {
......@@ -34,16 +35,14 @@ public class JSONExporter extends AbstractConsumerStage<AnomalyScoredMeasurement
writer.key("prediction").value(measurement.getPrediction());
writer.key("anomalyscore").value(measurement.getAnomalyScore());
writer.endObject();
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (JSONException e) {
throw new IllegalStateException(e);
}
}
@Override
public void onTerminating() throws Exception {
writer.endArray();
baseWriter.close();
......
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