Example usage for org.jfree.data.time TimeSeries addOrUpdate

List of usage examples for org.jfree.data.time TimeSeries addOrUpdate

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeries addOrUpdate.

Prototype

public TimeSeriesDataItem addOrUpdate(RegularTimePeriod period, Number value) 

Source Link

Document

Adds or updates an item in the times series and sends a SeriesChangeEvent to all registered listeners.

Usage

From source file:skoa.helpers.Graficos.java

/*****************************************************************************************
 * Obtiene la serie de un fichero para la consulta D, que es un poco diferente a la de A.*
 *****************************************************************************************/
private TimeSeries obtenerSerieEvolucion2() {
    String naux1 = "", naux2;
    //x-x-xx-x-x-xx.txt
    naux1 = nombreFichero.substring(nombreFichero.indexOf(".txt") - 13, nombreFichero.indexOf(".txt") - 7); //Saca la DG del nombre del fich.
    naux1 = naux1.replaceAll("-", "/"); //Para que las DGs sea x/xx/xx en vez de x-xx-xx
    naux2 = nombreFichero.substring(nombreFichero.indexOf(".txt") - 6, nombreFichero.indexOf(".txt")); //Saca la DG del nombre del fich.
    naux2 = naux2.replaceAll("-", "/"); //Para que las DGs sea x/xx/xx en vez de x-xx-xx
    naux1 = naux1 + "-" + naux2;
    TimeSeries serie = new TimeSeries(naux1);
    File archivo = new File(ruta + nombreFichero);
    FileReader fr = null;/*from w ww.  jav  a 2 s.com*/
    BufferedReader linea = null;
    String line;
    try {
        fr = new FileReader(archivo);
        linea = new BufferedReader(fr); //Se crea para leer las lineas
        int d = 0, m = 0, a = 0, a1 = 0, m1 = 0, d1 = 0, j, h1, h2, h3;
        double e = 0;
        String aux, h, minutos, segundos;
        int min_ant = 0, sec_ant = 0, vez1 = 0; //min_prim mira si es el primero, para comparar ant y act.
        Day day1 = null;
        while ((line = linea.readLine()) != null) { //Lectura del fichero
            int i = line.indexOf("\t");
            String f = line.substring(0, i);
            String valor = line.substring(i + 1);
            //Obtencion del dia, mes y ao de la fecha.
            j = f.indexOf("-");
            aux = f.substring(0, j);
            a = Integer.parseInt(aux);
            f = f.substring(j + 1);
            j = f.indexOf("-");
            aux = f.substring(0, j);
            m = Integer.parseInt(aux);
            f = f.substring(j + 1);
            j = f.indexOf(" ");
            aux = f.substring(0, j);
            d = Integer.parseInt(aux);
            //Obtencion de la hora de la fecha.
            f = f.substring(j + 1);
            if (fechaInicial.contentEquals(""))
                fechaInicial = d + "/" + m + "/" + a + " " + f; //Variable para la grfica
            fechaFinal = d + "/" + m + "/" + a + " " + f;
            j = f.indexOf(":");
            h = f.substring(0, j);
            f = f.substring(j + 1);
            j = f.indexOf(":");
            minutos = f.substring(0, j);
            segundos = f.substring(j + 1);
            if (a1 == 0 & m1 == 0 & d1 == 0) { //Inicializacin: Primera fecha.
                a1 = a;
                m1 = m;
                d1 = d;
                day1 = new Day(d1, m1, a1);
            } else {
                if (a1 != a) {
                    a1 = a;
                    if (m1 != m)
                        m1 = m;
                    if (d1 != d)
                        d1 = d;
                    day1 = new Day(d1, m1, a1);
                } else if (m1 != m) {
                    m1 = m;
                    if (d1 != d)
                        d1 = d;
                    day1 = new Day(d1, m1, a1);
                } else if (d1 != d) {
                    d1 = d;
                    day1 = new Day(d1, m1, a1);
                }
            }
            //Comprueba si es boolean. Si lo es, se le asigna 0  1
            //para poder representarlo en la grfica. Si no, su <<valor>>.
            if (posiblesBooleanos(valor, 1))
                e = 1;
            else if (posiblesBooleanos(valor, 0))
                e = 0;
            else { //NO ES UN BOOLEANO.
                int u = valor.indexOf(" ");
                valor = valor.substring(0, u);
                e = Double.parseDouble(valor);
            }
            //Comprobamos que la hora no coincida, para que si coincide, introducir en la serie slo
            //la primera aparicin de la fecha con su valor, por ser este ms representativo segn lo visto.
            if (vez1 == 0) {
                min_ant = h1 = Integer.parseInt(minutos); //minutos
                h2 = Integer.parseInt(h); //hora
                sec_ant = h3 = Integer.parseInt(segundos); //segundos
                serie.addOrUpdate(new Second(h3, new Minute(h1, new Hour(h2, day1))), e);//Montamos la serie en base a los segundos, minutos, hora y da
                vez1 = 1;
            } else {
                h1 = Integer.parseInt(minutos); //minutos
                h2 = Integer.parseInt(h); //hora
                h3 = Integer.parseInt(segundos); //segundos
                if (min_ant == h1) { //Si el minuto es =, comprobamos los segundos
                    if (sec_ant == h3) {
                    } //Si los segundos son =, no se introduce nada en la serie.
                    else { //Si los segundos son !=, se introduce en la serie.
                        serie.addOrUpdate(new Second(h3, new Minute(h1, new Hour(h2, day1))), e);//Montamos la serie en base a los segundos, minutos, hora y da
                        sec_ant = h3;
                    }
                } else { //Si el minuto es !=, se introduce en la serie.
                    serie.addOrUpdate(new Second(h3, new Minute(h1, new Hour(h2, day1))), e);//Montamos la serie en base a los segundos, minutos, hora y da
                    min_ant = h1;
                    sec_ant = h3;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (null != fr)
                fr.close(); //Se cierra si todo va bien.
        } catch (Exception e2) { //Sino salta una excepcion.
            e2.printStackTrace();
        }
    }
    return serie;
}

From source file:org.codehaus.mojo.chronos.responsetime.ResponsetimeSamples.java

public final void appendResponsetimes(TimeSeries series, int responsetimeDivider) {
    long delta = getFirstTimestamp();
    for (Iterator it = samples.iterator(); it.hasNext();) {
        ResponsetimeSample sample = (ResponsetimeSample) it.next();
        Millisecond timestamp = Utils.createMS(sample.getTimestamp() - delta);
        double responseTime = sample.getResponsetime() / responsetimeDivider;
        series.addOrUpdate(timestamp, responseTime);
    }// ww  w .j  a v  a2  s .  c  o m
}

From source file:org.codehaus.mojo.chronos.responsetime.ResponsetimeSamples.java

public final void appendThreadCounts(TimeSeries series, long threadCountDuration) {
    if (samples.size() > 0) {
        long firstSerial = getFirstTimestamp();
        Map activeThreads = new HashMap();
        for (Iterator it = samples.iterator(); it.hasNext();) {
            ResponsetimeSample sample = (ResponsetimeSample) it.next();
            int threadCount = activeThreads.size();
            for (Iterator it2 = activeThreads.keySet().iterator(); it2.hasNext();) {
                String key = (String) it2.next();
                if (sample.getTimestamp() > ((ResponsetimeSample) activeThreads.get(key)).getTimestamp()
                        + threadCountDuration) {
                    it2.remove();//  w ww  . ja  v a2  s .  c o  m
                }
            }
            activeThreads.put(sample.getThreadId(), sample);

            if (threadCount != activeThreads.size()) {
                series.addOrUpdate(Utils.createMS(sample.getTimestamp() - firstSerial), threadCount);
                series.addOrUpdate(Utils.createMS(sample.getTimestamp() - firstSerial + 1),
                        activeThreads.size());
            }
        }
        ResponsetimeSample sample = (ResponsetimeSample) samples.get(samples.size() - 1);
        series.addOrUpdate(Utils.createMS(sample.getTimestamp() - firstSerial + 1), activeThreads.size());
    }
}

From source file:org.codehaus.mojo.chronos.responsetime.ResponsetimeSamples.java

public final TimeSeries createMovingThroughput(String name, final int responsetimedivider) {
    TimeSeries series = new TimeSeries(name, Millisecond.class);
    if (samples.isEmpty()) {
        return series;
    }//from   w  w w.  ja  v  a2s  .  c  o  m

    Collections.sort(samples, new Comparator() {
        public int compare(Object arg1, Object arg2) {
            ResponsetimeSample sample1 = (ResponsetimeSample) arg1;
            ResponsetimeSample sample2 = (ResponsetimeSample) arg2;
            long endtime1 = sample1.getTimestamp() + (long) sample1.getResponsetime() / responsetimedivider;
            long endtime2 = sample2.getTimestamp() + (long) sample2.getResponsetime() / responsetimedivider;
            return (int) (endtime1 - endtime2);
        }
    });

    int periodLength = 1000;
    long rampUpTime = 0;
    int measurements = 0;
    final long firstAllowedTimestamp = getFirstTimestamp() + rampUpTime;
    long periodStart = firstAllowedTimestamp;
    long periodEnd = periodStart + periodLength;
    for (int i = 0; i < samples.size(); i++) {
        ResponsetimeSample sample = (ResponsetimeSample) samples.get(i);
        long sampleEndTime = sample.getTimestamp() + sample.getResponsetime() / responsetimedivider;
        if (sampleEndTime < periodStart) {
            continue;
        }
        if (sampleEndTime <= periodEnd) {
            measurements++;
        } else {
            if (measurements > 0) {
                series.addOrUpdate(Utils.createMS(periodEnd - firstAllowedTimestamp),
                        measurements * responsetimedivider);
            } else {
                series.addOrUpdate(Utils.createMS(periodEnd - firstAllowedTimestamp), null);
            }
            measurements = 1;
            periodStart = periodEnd;
            periodEnd = periodStart + periodLength;
        }
    }
    return series;
}