<commit_before>package de.qaware.chronix.server.benchmark.collector;

import com.google.common.base.Optional;
import com.codahale.metrics.annotation.Timed;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

/**
 * Created by mcqueen666 on 15.06.16.
 */
@Path("/collector")
@Produces(MediaType.APPLICATION_JSON)
public class StatsCollectorResource {

    private final StatsCollector statsCollector = StatsCollector.getInstance();

    // JUST FOR TESTING
    @GET
    @Path("test")
    @Timed
    public String test() {
        return "Hello from StatsCollector Resource!";
    }<commit_msg>added resource to transfer benchmark records to client<commit_after>package de.qaware.chronix.server.benchmark.collector;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Optional;
import com.codahale.metrics.annotation.Timed;
import de.qaware.chronix.server.benchmark.configurator.BenchmarkConfiguratorResource;
import de.qaware.chronix.shared.QueryUtil.BenchmarkRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by mcqueen666 on 15.06.16.
 */
@Path("/collector")
@Produces(MediaType.APPLICATION_JSON)
public class StatsCollectorResource {

    private final StatsCollector statsCollector = StatsCollector.getInstance();
    private final Logger logger = LoggerFactory.getLogger(StatsCollectorResource.class);

    // JUST FOR TESTING
    @GET
    @Path("test")
    @Timed
    public String test() {
        return "Hello from StatsCollector Resource!";
    }


    @GET
    @Path("benchmarkrecords")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getBenchmarkRecords(){
        List<BenchmarkRecord> benchmarkRecordList = statsCollector.getBenchmarkRecords();
        logger.info("Size of benchmarkRecordList: {}", benchmarkRecordList.size());
        GenericEntity<List<BenchmarkRecord>> genericEntity = new GenericEntity<List<BenchmarkRecord>>(new ArrayList<>(benchmarkRecordList)){};

        return Response.ok().entity(genericEntity).build();

    }


{'fraction_non_alphanumeric': 0.11296900489396411, 'fraction_numerical': 0.008156606851549755, 'mean_word_length': 4.6782407407407405, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4560389', 'n_tokens_mistral': 785, 'n_tokens_neox': 744, 'n_words': 142}