All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jdplus.toolkit.desktop.plugin.ui.processing.stats.SlidingSpansUI Maven / Gradle / Ivy

/*
 * Copyright 2013 National Bank of Belgium
 *
 * Licensed under the EUPL, Version 1.1 or – as soon they will be approved 
 * by the European Commission - subsequent versions of the EUPL (the "Licence");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 * 
 * http://ec.europa.eu/idabc/eupl
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and 
 * limitations under the Licence.
 */
package jdplus.toolkit.desktop.plugin.ui.processing.stats;

import jdplus.toolkit.desktop.plugin.ui.JSlidingSpansView;
import jdplus.toolkit.desktop.plugin.ui.processing.ItemUI;
import jdplus.toolkit.base.api.timeseries.TsData;
import java.util.function.Function;
import javax.swing.JComponent;
import jdplus.toolkit.base.core.stats.DescriptiveStatistics;
import jdplus.toolkit.base.core.timeseries.simplets.analysis.DiagnosticInfo;
import jdplus.toolkit.base.core.timeseries.simplets.analysis.SlidingSpans;

/**
 *
 * @author Mats Maggi
 */
public class SlidingSpansUI implements ItemUI> {

    public SlidingSpansUI() {
    }

    @Override
    public JComponent getView(Information input) {
        JSlidingSpansView view = new JSlidingSpansView();
        view.setInfo(input.getDiag());
        view.setInfoName(input.getInfo());
        view.setExtractor(input.getExtractor());
        view.setMultiplicative(input.isMultiplicative());
        if (input.isMultiplicative()) {
            view.setThreshold(0.03);
        } else {
            TsData s = input.getExtractor().apply(input.getSlidingSpans().getReferenceInfo());
            if (s != null) {
                DescriptiveStatistics stats = DescriptiveStatistics.of(s.getValues());
                view.setThreshold(Math.sqrt(stats.getSumSquare() / stats.getDataCount()));
            }
        }
        view.setSlidingSpans(input.getSlidingSpans());
        return view;
    }

    @lombok.Value
    public static class Information {

        private boolean multiplicative;
        private SlidingSpans slidingSpans;
        private DiagnosticInfo diag;
        private String info;
        private Function extractor;

    }

}