<commit_before>/**
 * 
 */
package org.trustsoft.slastic.control.recordConsumer;

import java.util.TreeMap;
import java.util.concurrent.ConcurrentSkipListSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.trustsoft.slastic.monadapt.monitoringRecord.SLA.SLOMonitoringRecord;

/**
 * @author Lena
 * 
 */
public class QuantileCalculator {

    private static final Log log = LogFactory.getLog(QuantileCalculator.class);
    private final TreeMap<Integer, ConcurrentSkipListSet<SLOMonitoringRecord>> map;

    public QuantileCalculator(int[] serviceIDs) {
        log.info("QuantileCalculatorThread created!");
        this.map = new TreeMap<Integer, ConcurrentSkipListSet<SLOMonitoringRecord>>();
        for(int i = 0; i< serviceIDs.length; i++){
        	this.map.put(serviceIDs[i], new ConcurrentSkipListSet<SLOMonitoringRecord>());
        	System.out.println("ID mit der Nummer: "+serviceIDs[i]+" himzugegt.");
        }
    }

    public void updateSample(SLOMonitoringRecord newRecord,
            SLOMonitoringRecord oldRecord) {
        Integer newID = new Integer(newRecord.serviceId);
        if (this.map.containsKey(newID)) {
            this.map.get(newID).add(newRecord);
            if (oldRecord != null) {
                this.map.get(new Integer(oldRecord.serviceId)).remove(oldRecord);
            }
        } else {
//            ConcurrentSkipListSet<SLOMonitoringRecord> set = new ConcurrentSkipListSet<SLOMonitoringRecord>();
//            set.add(newRecord);
//            this.map.put(newID, set);
        	log.error("SLO for ID: "+newRecord.serviceId+" does not exist!");
        }
        
//		log.info("record added with ID: "+newRecord.serviceId);
    }

    public long[] getQuantile(Float[] quantiles, int serviceID) {
        long[] quantile;

        System.out.println("Quantile Request for ServiceID: " + serviceID);
        quantile = new long[quantiles.length];
        ConcurrentSkipListSet<SLOMonitoringRecord> rtSet = this.map.get(serviceID);
        
        if (rtSet == null) {
            log.error("Not yet any serviced with this ID available");
            return null;
        } else {
        	
            Object[] a = rtSet.toArray();
            
            for (int i = 0; i < q.length; i++) {
                if (a.length % (1 / q[i]) != 0) {
                	
                    quantile[i] = ((SLOMonitoringRecord) a[(int) ((a.length) / (1 / q[i]))]).rtNseconds;
                    System.out.println("Hier dann nicht mehr?");
                    log.info("UPDATING............." + quantile[i] + "......................");
                } else {
                    quantile[i] = (long) (0.5 * (((SLOMonitoringRecord) (a[(int) (a.length / (1 / q[i]))])).rtNseconds) + ((SLOMonitoringRecord) (a[(int) ((a.length / (1 / q[i])) + 1)])).rtNseconds);
                    log.info("UPDATING.............." + quantile[i] + ".....................");
                }
            }
        }
//        System.out.println("Die Quantile sehen so aus: " + quantile.length);
//        for (int i = 0; i < quantile.length; i++) {
//            System.out.println(quantile[i]);
//        }
        return quantile;
    }
}<commit_msg>quantile <commit_after>/**
 * 
 */
package org.trustsoft.slastic.control.recordConsumer;

import java.util.TreeMap;
import java.util.concurrent.ConcurrentSkipListSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.trustsoft.slastic.monadapt.monitoringRecord.SLA.SLOMonitoringRecord;

/**
 * @author Lena
 * 
 */
public class QuantileCalculator {

    private static final Log log = LogFactory.getLog(QuantileCalculator.class);
    private final TreeMap<Integer, ConcurrentSkipListSet<SLOMonitoringRecord>> map;

    public QuantileCalculator(int[] serviceIDs) {
        log.info("QuantileCalculatorThread created!");
        this.map = new TreeMap<Integer, ConcurrentSkipListSet<SLOMonitoringRecord>>();
        for(int i = 0; i< serviceIDs.length; i++){
        	this.map.put(serviceIDs[i], new ConcurrentSkipListSet<SLOMonitoringRecord>());
        	System.out.println("ID mit der Nummer: "+serviceIDs[i]+" himzugegt.");
        }
    }

    public void updateSample(SLOMonitoringRecord newRecord,
            SLOMonitoringRecord oldRecord) {
        Integer newID = new Integer(newRecord.serviceId);
        if (this.map.containsKey(newID)) {
            this.map.get(newID).add(newRecord);
            if (oldRecord != null) {
                this.map.get(new Integer(oldRecord.serviceId)).remove(oldRecord);
            }
        } else {
//            ConcurrentSkipListSet<SLOMonitoringRecord> set = new ConcurrentSkipListSet<SLOMonitoringRecord>();
//            set.add(newRecord);
//            this.map.put(newID, set);
        	log.error("SLO for ID: "+newRecord.serviceId+" does not exist!");
        }
        
//		log.info("record added with ID: "+newRecord.serviceId);
    }

    public long[] getQuantile(Float[] quantiles, int serviceID) {
        long[] quantile;

        System.out.println("Quantile Request for ServiceID: " + serviceID);
        quantile = new long[quantiles.length];
        ConcurrentSkipListSet<SLOMonitoringRecord> rtSet = this.map.get(serviceID);
        
        if (rtSet == null) {
            log.error("Not yet any serviced with this ID available");
            return null;
        } else {
        	
            Object[] a = rtSet.toArray();
            
            for (int i = 0; i < quantile.length; i++) {
                if (a.length % (1 / quantile[i]) != 0) {
                	
                    quantile[i] = ((SLOMonitoringRecord) a[(int) ((a.length) / (1 / quantile[i]))]).rtNseconds;
                    System.out.println("Hier dann nicht mehr?");
                    log.info("UPDATING............." + quantile[i] + "......................");
                } else {
                    quantile[i] = (long) (0.5 * (((SLOMonitoringRecord) (a[(int) (a.length / (1 / quantile[i]))])).rtNseconds) + ((SLOMonitoringRecord) (a[(int) ((a.length / (1 / quantile[i])) + 1)])).rtNseconds);
                    log.info("UPDATING.............." + quantile[i] + ".....................");
                }
            }
        }
//        System.out.println("Die Quantile sehen so aus: " + quantile.length);
//        for (int i = 0; i < quantile.length; i++) {
//            System.out.println(quantile[i]);
//        }
        return quantile;
    }
}
{'fraction_non_alphanumeric': 0.15873015873015872, 'fraction_numerical': 0.0033903529049160116, 'mean_word_length': 2.1382978723404253, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 19, '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': '18449', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1911, 'n_words': 369}