<commit_before>/*
 * Copyright (C) 2016 QAware GmbH
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package de.qaware.chronix.solr.query.analysis.collectors;

import de.qaware.chronix.distance.DistanceFunction;
import de.qaware.chronix.distance.DistanceFunctionEnum;
import de.qaware.chronix.distance.DistanceFunctionFactory;
import de.qaware.chronix.dtw.FastDTW;
import de.qaware.chronix.dtw.TimeWarpInfo;
import de.qaware.chronix.solr.query.analysis.collectors.math.LinearRegression;
import de.qaware.chronix.solr.query.analysis.collectors.math.Percentile;
import de.qaware.chronix.timeseries.MetricTimeSeries;
import de.qaware.chronix.timeseries.MultivariateTimeSeries;
import de.qaware.chronix.timeseries.dt.DoubleList;
import de.qaware.chronix.timeseries.dt.LongList;
import de.qaware.chronix.timeseries.dt.Pair;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

/**
 * @author f.lautenschlager
 */
public class HighLevelAnalysisEvaluator {

    private HighLevelAnalysisEvaluator() {
        //avoid instances
    }

    /**
     * Applies an high level analysis (outlier, trend, frequency) on the timestamps and values.
     * If the result is =-1, the time series contains suspicions values, otherwise not.
     *
     * @param timeSeries the time series
     * @param analysis   the analysis itself
     * @return -1 if no suspicious values are found, otherwise 1 which means that there are suspicious values.
     */
    public static double analyze(MetricTimeSeries timeSeries, ChronixAnalysis analysis) {
        switch (analysis.getType()) {
            case OUTLIER:
                return detectOutlier(timeSeries.getValues());
            case TREND:
                return detectTrend(timeSeries.getTimestamps(), timeSeries.getValues());
            case FREQUENCY:<commit_msg>Fixed sonar violation: final class.<commit_after>/*
 * Copyright (C) 2016 QAware GmbH
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package de.qaware.chronix.solr.query.analysis.collectors;

import de.qaware.chronix.distance.DistanceFunction;
import de.qaware.chronix.distance.DistanceFunctionEnum;
import de.qaware.chronix.distance.DistanceFunctionFactory;
import de.qaware.chronix.dtw.FastDTW;
import de.qaware.chronix.dtw.TimeWarpInfo;
import de.qaware.chronix.solr.query.analysis.collectors.math.LinearRegression;
import de.qaware.chronix.solr.query.analysis.collectors.math.Percentile;
import de.qaware.chronix.timeseries.MetricTimeSeries;
import de.qaware.chronix.timeseries.MultivariateTimeSeries;
import de.qaware.chronix.timeseries.dt.DoubleList;
import de.qaware.chronix.timeseries.dt.LongList;
import de.qaware.chronix.timeseries.dt.Pair;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

/**
 * This class is used to evaluate the high level analyses
 *
 * @author f.lautenschlager
 */
public final class HighLevelAnalysisEvaluator {

    private HighLevelAnalysisEvaluator() {
        //avoid instances
    }

    /**
     * Applies an high level analysis (outlier, trend, frequency) on the timestamps and values.
     * If the result is =-1, the time series contains suspicions values, otherwise not.
     *
     * @param timeSeries the time series
     * @param analysis   the analysis itself
     * @return -1 if no suspicious values are found, otherwise 1 which means that there are suspicious values.
     */
    public static double analyze(MetricTimeSeries timeSeries, ChronixAnalysis analysis) {
        switch (analysis.getType()) {
            case OUTLIER:
                return detectOutlier(timeSeries.getValues());
            case TREND:
                return detectTrend(timeSeries.getTimestamps(), timeSeries.getValues());
            case FREQUENCY:
{'fraction_non_alphanumeric': 0.08583690987124463, 'fraction_numerical': 0.004496219088493766, 'mean_word_length': 3.5953051643192486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2776452', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1369, 'n_words': 414}