<commit_before>package de.qaware.chronix.client.benchmark.benchmarkrunner.util;

import de.qaware.chronix.client.benchmark.queryhandler.util.JsonTimeSeriesHandler;
import de.qaware.chronix.database.TimeSeriesMetaData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 * Created by mcqueen666 on 13.09.16.
 */
public class TimeSeriesCounter {

    private static TimeSeriesCounter instance;

    private final Logger logger = LoggerFactory.getLogger(TimeSeriesCounter.class);
    private JsonTimeSeriesHandler jsonTimeSeriesHandler;


    private TimeSeriesCounter(){
        jsonTimeSeriesHandler = JsonTimeSeriesHandler.getInstance();
    }

    public TimeSeriesCounter getInstance(){
        if(instance != null){
            instance = new TimeSeriesCounter();
        }
        return instance;
    }

    /**
     * Returns meta data for all previously imported time series.
     *
     * @return list of all imported meta data. Empty if nothing was imported previously.
     */
    public List<TimeSeriesMetaData> getAll(){
        List<TimeSeriesMetaData> metaDataList = new ArrayList<>();
        File directory = new File(jsonTimeSeriesHandler.getTimeSeriesMetaDataRecordDirectoryPath());
        if(directory.exists() && directory.isDirectory()){
            File[] measurements = directory.listFiles();
            if(measurements != null && measurements.length > 0) {
                for (File measurement : measurements) {
                    if (measurement.isDirectory()) {
                        metaDataList.addAll(jsonTimeSeriesHandler.readTimeSeriesMetaDatafromJson(measurement.getName()));
                    }
                }
            } else {
                logger.error("TimeSeriesCounter: No meta data to read.");
            }
        }
        return metaDataList;
    }

    /**
     * Returns meta data for a random time series size times in a list. (for cache testing)
     *
     * @param size number of how many elements the list should have.
     * @return list if meta data.
     */
    public List<TimeSeriesMetaData> getCachingTestMetaData(int size){
        List<TimeSeriesMetaData> allMetaData = this.getAll();
<commit_msg>measurements are files, not directories. .json extension should not be given to jsonTimeSeriesHandler.<commit_after>package de.qaware.chronix.client.benchmark.benchmarkrunner.util;

import de.qaware.chronix.client.benchmark.queryhandler.util.JsonTimeSeriesHandler;
import de.qaware.chronix.database.TimeSeriesMetaData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by mcqueen666 on 13.09.16.
 */
public class TimeSeriesCounter {

    private static TimeSeriesCounter instance;

    private final Logger logger = LoggerFactory.getLogger(TimeSeriesCounter.class);
    private JsonTimeSeriesHandler jsonTimeSeriesHandler;


    private TimeSeriesCounter(){
        jsonTimeSeriesHandler = JsonTimeSeriesHandler.getInstance();
    }

    public static TimeSeriesCounter getInstance(){
        if(instance == null){
            instance = new TimeSeriesCounter();
        }
        return instance;
    }

    /**
     * Returns meta data for all previously imported time series.
     *
     * @return list of all imported meta data. Empty if nothing was imported previously.
     */
    public List<TimeSeriesMetaData> getAll(){
        List<TimeSeriesMetaData> metaDataList = new ArrayList<>();
        File directory = new File(jsonTimeSeriesHandler.getTimeSeriesMetaDataRecordDirectoryPath());
        if(directory.exists() && directory.isDirectory()){
            File[] measurements = directory.listFiles();
            if(measurements != null && measurements.length > 0) {
                for (File measurement : measurements) {
                    if (measurement.isFile() && measurement.getName().endsWith(".json")) {
                        metaDataList.addAll(jsonTimeSeriesHandler.readTimeSeriesMetaDatafromJson(measurement.getName().replaceAll(".json","")));
                    }
                }
            } else {
                logger.error("TimeSeriesCounter: No meta data to read.");
            }
        }
        return metaDataList;
    }

    /**
     * Returns meta data for a random time series size times in a list. (for cache testing)
     *
     * @param size number of how many elements the list should have.
     * @return list if meta data.
     */
    public List<TimeSeriesMetaData> getCachingTestMetaData(int size){
        List<TimeSeriesMetaData> allMetaData = this.getAll();

{'fraction_non_alphanumeric': 0.09249894648124736, 'fraction_numerical': 0.0050568900126422255, 'mean_word_length': 2.828225806451613, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1121849', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1200, 'n_words': 314}