Search in sources :

Example 1 with IsoDateFormat

use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.

the class DetailedLogTable method setupContent.

/**
	 * Fill the table with the fields of the given log.
	 * 
	 * @param log The log whose content is shown in the table
	 */
public void setupContent(ILogEntry log) {
    if (log == null) {
        setEmptyContent();
        return;
    }
    // The number of rows in the table is given by the number of fields
    // of each LogEntry plus the number of the "data" elements for the selected log
    Vector<ILogEntry.AdditionalData> additionalData = log.getAdditionalData();
    rowsNum = LogField.values().length;
    if (additionalData != null) {
        rowsNum += additionalData.size();
    }
    if (rowsNum > 0) {
        nameValue = new String[rowsNum][2];
        for (int i = 0; i < LogField.values().length; i++) {
            LogField field = LogField.values()[i];
            nameValue[i][0] = "<HTML><B>" + field.getName() + "</B>";
            Object obj = log.getField(field);
            if (obj != null) {
                if (field == LogField.ENTRYTYPE) {
                    nameValue[i][1] = obj.toString();
                    dataModel.logType = (LogTypeHelper) obj;
                } else if (field == LogField.TIMESTAMP) {
                    SimpleDateFormat df = new IsoDateFormat();
                    Date dt = new Date((Long) obj);
                    StringBuffer dateSB = new StringBuffer();
                    java.text.FieldPosition pos = new java.text.FieldPosition(0);
                    df.format(dt, dateSB, pos);
                    nameValue[i][1] = dateSB.toString();
                } else {
                    nameValue[i][1] = obj.toString();
                }
            } else {
                nameValue[i][1] = "";
            }
        }
        for (int i = LogField.values().length; i < rowsNum; i++) {
            nameValue[i][0] = "<HTML><B>Additional</B> <I>" + additionalData.get(i - LogField.values().length).name + "</I>";
            String temp = (String) additionalData.get(i - LogField.values().length).value;
            nameValue[i][1] = temp;
        }
        dataModel.fireTableDataChanged();
    }
}
Also used : IsoDateFormat(alma.acs.util.IsoDateFormat) LogField(com.cosylab.logging.engine.log.LogField) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with IsoDateFormat

use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.

the class ACSLogParserVTD method getLongFromTimestamp.

/**
	 * Gets a Long from VTD XML parser (using VTDNav navigation)
	 * 
	 * @param vtdNav the navigator to use to navigate the parsed xml
	 * @param os output stream to use for conversion of bytes to useful formatted data.
	 * @param attrName the name of the field we are searching for
	 * @param bytesXML the bytes (containing XML) that are being referenced by the navigator.
	 * @return Long populated with the attribute's value
	 * @throws NavException if navigation encounters problems
	 * @throws LogParseException if parsing fails
	 */
private Long getLongFromTimestamp(Object vtdNav, ByteArrayOutputStream os, String attrName, byte[] bytesXML) throws LogParseException, Exception {
    Long retVal = null;
    int tIndex = (Integer) VTDNav_getAttrVal.invoke(vtdNav, attrName);
    int tOffset = (Integer) VTDNav_getTokenOffset.invoke(vtdNav, tIndex);
    int tLen = (Integer) VTDNav_getTokenLength.invoke(vtdNav, tIndex);
    os.reset();
    //write the fragment out
    os.write(bytesXML, tOffset, tLen);
    try {
        SimpleDateFormat dateFormat = new IsoDateFormat();
        Date date = dateFormat.parse(os.toString());
        retVal = Long.valueOf(date.getTime());
    } catch (java.text.ParseException pEx) {
        throw new LogParseException("Error parsing date", pEx);
    }
    return retVal;
}
Also used : IsoDateFormat(alma.acs.util.IsoDateFormat) LogParseException(com.cosylab.logging.engine.ACS.LogParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with IsoDateFormat

use of alma.acs.util.IsoDateFormat 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)

Example 4 with IsoDateFormat

use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.

the class FilePrinter method openFile.

private boolean openFile() {
    IsoDateFormat fo = new IsoDateFormat();
    filename = component + "_" + property + "_" + getFrequency() + "_" + fo.format(new Date()) + ".csv";
    try {
        file = new FileWriter(filename);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    writer = new BufferedWriter(file);
    return true;
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) IsoDateFormat(alma.acs.util.IsoDateFormat) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter)

Example 5 with IsoDateFormat

use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.

the class PlotPrinter method openFile.

private boolean openFile() {
    IsoDateFormat fo = new IsoDateFormat();
    filename = component.replace('/', '-') + "_" + property.replace('/', '-') + "_" + getFrequency() + "_" + fo.format(new Date()) + ".csv";
    try {
        file = new FileWriter(filename);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    writer = new BufferedWriter(file);
    return true;
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) IsoDateFormat(alma.acs.util.IsoDateFormat) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter)

Aggregations

IsoDateFormat (alma.acs.util.IsoDateFormat)21 Date (java.util.Date)20 SimpleDateFormat (java.text.SimpleDateFormat)15 FieldPosition (java.text.FieldPosition)10 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)9 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)5 IOException (java.io.IOException)3 Vector (java.util.Vector)3 FileHelper (alma.acs.logging.archive.zoom.FileHelper)2 LogField (com.cosylab.logging.engine.log.LogField)2 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 Random (java.util.Random)2 ParserTypes (alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)1 DataItem (cl.utfsm.samplingSystemUI.core.DataItem)1 LogParseException (com.cosylab.logging.engine.ACS.LogParseException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 JFileChooser (javax.swing.JFileChooser)1