LegacyEwmaDetectorFactoryProvider implements DetectorFactoryProvider<ForecastingDetector> { @Override public ForecastingDetector buildDetector(DetectorDocument document) { val uuid = document.getUuid(); val config = document.getConfig(); log.info("config={}", config); val type = AnomalyType.valueOf((String) config.get("type")); val paramsMap = config.get("params"); val legacyParams = objectMapper.convertValue(paramsMap, LegacyEwmaDetectorParams.class); val ewmaParams = legacyParams.toEwmaParams(); val welfordParams = legacyParams.toWelfordParams(); val ewma = new EwmaPointForecaster(ewmaParams); val welford = new ExponentialWelfordIntervalForecaster(welfordParams); val trusted = document.isTrusted(); return new ForecastingDetector(uuid, ewma, welford, type, trusted, "ewma"); }  @Override ForecastingDetector buildDetector(DetectorDocument document);  }
@Test public void testBuildDetector() { val factoryUnderTest = new LegacyEwmaDetectorFactoryProvider(); val document = readDocument("ewma"); val detector = factoryUnderTest.buildDetector(document); val ewma = (EwmaPointForecaster) detector.getPointForecaster(); val ewmaParams = ewma.getParams(); val welford = (ExponentialWelfordIntervalForecaster) detector.getIntervalForecaster(); val welfordParams = welford.getParams(); assertEquals(ForecastingDetector.class, detector.getClass()); assertEquals("3e047348-f837-f615-271c-dce6206f50d6", detector.getUuid().toString()); assertEquals(AnomalyType.RIGHT_TAILED, detector.getAnomalyType()); assertEquals(0.20, ewmaParams.getAlpha(), TOLERANCE); assertEquals(1.4, ewmaParams.getInitMeanEstimate(), TOLERANCE); assertEquals(3.0, welfordParams.getWeakSigmas(), TOLERANCE); assertEquals(4.0, welfordParams.getStrongSigmas(), TOLERANCE); }