Search in sources :

Example 1 with DataItem

use of cl.utfsm.samplingSystemUI.core.DataItem in project ACS by ACS-Community.

the class DataItemTest method testEquals.

public void testEquals() throws Exception {
    DataItem sd1 = new DataItem(100, 3.14);
    DataItem sd2 = new DataItem(100, 3.14);
    DataItem sd3 = new DataItem(117, 2.70);
    assertEquals(sd1, sd2);
    assertTrue(sd1.hashCode() == sd2.hashCode());
    assertNotSame(sd2, sd3);
    assertTrue(sd1.getTime() == 100);
    assertTrue(sd1.getValue() == 3.14);
}
Also used : DataItem(cl.utfsm.samplingSystemUI.core.DataItem)

Example 2 with DataItem

use of cl.utfsm.samplingSystemUI.core.DataItem in project ACS by ACS-Community.

the class SamplingDataCorrelator method addSamplingSet.

/**
	 * Registers a Sampling Set, and read the first line, obtaining the component and the property which sampled.
	 * @param filaname Name of the file in which the data for this Sampling Set was dumped.
	 */
public void addSamplingSet(String filename) {
    BufferedReader br = openReadOnly(filename);
    String line = null;
    try {
        if ((line = br.readLine()) != null) {
            StringTokenizer st = new StringTokenizer(line, ";");
            while (st.hasMoreTokens()) {
                st.nextToken();
                headers.add(st.nextToken());
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    readers.add(br);
    data.add(new ArrayList<DataItem>());
    header = header + ";" + headers.get(headers.size() - 1);
    meanData.add(new ArrayList<Double>());
}
Also used : StringTokenizer(java.util.StringTokenizer) DataItem(cl.utfsm.samplingSystemUI.core.DataItem) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 3 with DataItem

use of cl.utfsm.samplingSystemUI.core.DataItem in project ACS by ACS-Community.

the class SamplingDataCorrelator method dumpToFile.

/**
	 * Starts the correlation process. This method should only be called if you know what you are doing.<br /> 
	 * Setting the prec lower or higher will get you leaks of data.
	 * @param prec How much of the Frequency will each entry take as a valid interval of time to look forward and backward for data.
	 */
public void dumpToFile(double prec) {
    boolean done = false;
    int flag = 0;
    frequency = 1000000L / frequency;
    long w = (long) (frequency * prec);
    // A brief buffer is created, according to how much data the mean needs.		
    consume();
    for (int k = 0; k < meanQty; k++) {
        consume();
    }
    //The First timestamp (the earliest), is the one that is used to align the data.
    long timestamp = data.get(0).get(0).getTime();
    // The file is open, and the header is written
    openReadWrite();
    try {
        writer.write(header + "\n");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    while (!done) {
        consume();
        String line = "" + formater.format(new Date(UTCUtility.utcOmgToJava(timestamp)));
        boolean dataPresent = true;
        for (ArrayList<DataItem> i : data) {
            dataPresent = false;
            if (i.isEmpty()) {
                line += ";";
                continue;
            }
            DataItem item = i.get(0);
            if ((item.getTime() >= (timestamp - w)) && (item.getTime() <= (timestamp + w))) {
                line += ";" + item.getValue();
                dataPresent = true;
                addValueToMean(data.indexOf(i), item.getValue());
                i.remove(item);
            } else {
                if ((item.getTime() >= (timestamp + w)) && (item.getTime() <= (timestamp + frequency - w))) {
                    line += ";" + mean(data.indexOf(i));
                    addValueToMean(data.indexOf(i), mean(data.indexOf(i)));
                    i.remove(item);
                } else {
                    line += ";" + mean(data.indexOf(i));
                    addValueToMean(data.indexOf(i), mean(data.indexOf(i)));
                }
            }
            if (i.isEmpty())
                flag++;
        }
        if (dataPresent) {
            try {
                writer.write(line + "\n");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        // Check if we passed over all dataItem recollected			
        if (flag == data.size())
            done = true;
        timestamp += frequency;
    //System.out.println("Array completed: " + flag + "\t Array Size: " + data.get(0).size());
    }
    try {
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DataItem(cl.utfsm.samplingSystemUI.core.DataItem) IOException(java.io.IOException) Date(java.util.Date)

Example 4 with DataItem

use of cl.utfsm.samplingSystemUI.core.DataItem in project ACS by ACS-Community.

the class SamplingDataCorrelator method consume.

/**
	 * Method that consumes one line on every cvs file, storing them on memory.
	 * @return True in case that there remains lines to be consumed, and false in case that no lines remain in every file.
	 */
public boolean consume() {
    String line = null;
    String timestamp = null;
    String value = null;
    int finished = 0;
    int j = 0;
    for (BufferedReader i : readers) {
        try {
            if ((line = i.readLine()) != null) {
                StringTokenizer st = new StringTokenizer(line, ";");
                while (st.hasMoreTokens()) {
                    timestamp = st.nextToken();
                    value = st.nextToken();
                }
                //System.out.println("Parsed: " + formater.format(new Date( formater.parse( timestamp ).getTime() )) + "; " + value );
                data.get(j).add(new DataItem(UTCUtility.utcJavaToOmg((formater.parse(timestamp).getTime())), Double.parseDouble(value)));
            } else {
                finished++;
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        j++;
    }
    if (finished == readers.size())
        return false;
    else
        return true;
}
Also used : StringTokenizer(java.util.StringTokenizer) DataItem(cl.utfsm.samplingSystemUI.core.DataItem) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 5 with DataItem

use of cl.utfsm.samplingSystemUI.core.DataItem in project ACS by ACS-Community.

the class FileHelper method dumpToFile.

/**
	 * Start the dumping process. This method should only be called if you know what you are doing.<br /> 
	 * Setting the prec lower will get leaks of data, and setting it higher, will get you duplicated data.
	 * @param frequency Frequency at which the data is to be separated in the printout file.
	 * @param prec How much of the Frequency will each entry take as a valid interval of time to look forward and backward for data.
	 */
public void dumpToFile(long frequency, double prec) {
    IsoDateFormat formater = new IsoDateFormat();
    long timestamp = data.get(0).get(0).getTime();
    boolean done = false;
    frequency = 1000000L / frequency;
    long w = (long) (frequency * prec);
    int[] c = new int[data.size()];
    openFile();
    try {
        writer.write(header + "\n");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    while (!done) {
        String line = "" + formater.format(new Date(UTCUtility.utcOmgToJava(timestamp)));
        boolean dataPresent = true;
        for (int i = 0; i < data.size(); i++) {
            dataPresent = false;
            if (c[i] == data.get(i).size()) {
                line += ";";
                continue;
            }
            DataItem item = data.get(i).get(c[i]);
            if ((item.getTime() >= (timestamp - w)) && (item.getTime() <= (timestamp + w))) {
                line += ";" + item.getValue();
                c[i]++;
                dataPresent = true;
            } else if ((item.getTime() >= (timestamp + w)) && (item.getTime() <= (timestamp + frequency - w))) {
                line += ";";
                c[i]++;
            } else
                line += ";";
        }
        try {
            if (dataPresent) {
                writer.write(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        /*Check if we passed over all dataItem recolected*/
        int flag = 0;
        for (int i = 0; i < c.length; i++) {
            if (c[i] == data.get(i).size())
                flag++;
        }
        if (flag == c.length)
            done = true;
        timestamp += frequency;
    }
    try {
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DataItem(cl.utfsm.samplingSystemUI.core.DataItem) IOException(java.io.IOException) IsoDateFormat(alma.acs.util.IsoDateFormat) Date(java.util.Date)

Aggregations

DataItem (cl.utfsm.samplingSystemUI.core.DataItem)6 IOException (java.io.IOException)4 BufferedReader (java.io.BufferedReader)2 Date (java.util.Date)2 StringTokenizer (java.util.StringTokenizer)2 IsoDateFormat (alma.acs.util.IsoDateFormat)1 ParseException (java.text.ParseException)1 LinkedList (java.util.LinkedList)1