Search in sources :

Example 1 with LogChannel

use of org.openmuc.framework.datalogger.spi.LogChannel in project OpenMUC by isc-konstanz.

the class LogFileReaderTestSingleFile method setup.

@BeforeAll
public static void setup() {
    System.out.println("### Setup() LogFileReaderTestSingleFile");
    TestUtils.createTestFolder();
    // File file = new File(TestUtils.TESTFOLDERPATH + fileDate0 + "_" + loggingInterval + ext);
    // if (file.exists()) {
    // Do nothing, file exists.
    // }
    // else {
    // eine Datei
    channelIds = new String[] { "power" };
    // Logs 1 channel in second interval from 1 to 3 o'clock
    HashMap<String, LogChannel> logChannelList = new HashMap<>();
    LogChannelTestImpl ch1 = new LogChannelTestImpl(Channel0Name, "", "dummy description", "kW", ValueType.DOUBLE, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
    logChannelList.put(Channel0Name, ch1);
    Calendar calendar = TestUtils.stringToDate(dateFormat, fileDate0 + " 01:00:00");
    for (int i = 0; i < ((60 * 60 * 2) * (1000d / loggingInterval)); i++) {
        LoggingRecord container1 = new LoggingRecord(Channel0Name, new Record(new DoubleValue(i), calendar.getTimeInMillis()));
        LogIntervalContainerGroup group = new LogIntervalContainerGroup();
        group.add(container1);
        LogFileWriter lfw = new LogFileWriter(TestUtils.TESTFOLDERPATH, false);
        lfw.log(group, loggingInterval, 0, calendar, logChannelList);
        AsciiLogger.setLastLoggedLineTimeStamp(loggingInterval, 0, calendar.getTimeInMillis());
        calendar.add(Calendar.MILLISECOND, loggingInterval);
    }
// }
}
Also used : HashMap(java.util.HashMap) DoubleValue(org.openmuc.framework.data.DoubleValue) Calendar(java.util.Calendar) LogChannel(org.openmuc.framework.datalogger.spi.LogChannel) LogIntervalContainerGroup(org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup) Record(org.openmuc.framework.data.Record) LoggingRecord(org.openmuc.framework.datalogger.spi.LoggingRecord) LogFileWriter(org.openmuc.framework.datalogger.ascii.LogFileWriter) LoggingRecord(org.openmuc.framework.datalogger.spi.LoggingRecord) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with LogChannel

use of org.openmuc.framework.datalogger.spi.LogChannel in project OpenMUC by isc-konstanz.

the class AsciiLogger method setChannelsToLog.

/**
 * Will called if OpenMUC starts the logger
 */
@Override
public void setChannelsToLog(List<LogChannel> logChannels) {
    Calendar calendar = new GregorianCalendar(Locale.getDefault());
    logChannelList.clear();
    logger.trace("channels to log:");
    for (LogChannel logChannel : logChannels) {
        if (logger.isTraceEnabled()) {
            logger.trace("channel.getId() " + logChannel.getId());
            logger.trace("channel.getLoggingInterval() " + logChannel.getLoggingInterval());
        }
        logChannelList.put(logChannel.getId(), logChannel);
    }
    if (isFillUpFiles) {
        Map<String, Boolean> areHeaderIdentical = LoggerUtils.areHeadersIdentical(loggerDirectory, logChannels, calendar);
        for (Entry<String, Boolean> entry : areHeaderIdentical.entrySet()) {
            String key = entry.getKey();
            boolean isHeaderIdentical = entry.getValue();
            if (isHeaderIdentical) {
                // Fill file up with error flag 32 (DATA_LOGGING_NOT_ACTIVE)
                if (logger.isTraceEnabled()) {
                    logger.trace("Fill file " + LoggerUtils.buildFilename(key, calendar) + " up with error flag 32.");
                }
                fillUpFileWithErrorCode(loggerDirectory, key, calendar);
            } else {
                // rename file in old file (if file is existing), because of configuration has
                // changed
                LoggerUtils.renameFileToOld(loggerDirectory, key, calendar);
            }
        }
    } else {
        LoggerUtils.renameAllFilesToOld(loggerDirectory, calendar);
    }
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) LogChannel(org.openmuc.framework.datalogger.spi.LogChannel)

Example 3 with LogChannel

use of org.openmuc.framework.datalogger.spi.LogChannel in project OpenMUC by isc-konstanz.

the class LogFileHeader method getIESDataFormatHeaderString.

/**
 * Generate the standard IES Data Format Header
 *
 * @param filename
 *            the name of the file to add the header
 * @param logChannelList
 *            a list of all channels for this file
 * @return the header as a string
 */
public static String getIESDataFormatHeaderString(String filename, List<LogChannel> logChannelList) {
    StringBuilder sb0 = new StringBuilder();
    StringBuilder sb1 = new StringBuilder();
    setHeaderTop(sb0, logChannelList.get(0).getLoggingInterval(), filename);
    // write channel specific header informations
    int colNumber = 4;
    Iterator<LogChannel> iterator = logChannelList.listIterator();
    while (iterator.hasNext()) {
        LogChannel logChannel = iterator.next();
        appendChannelSpecificComment(sb0, logChannel, colNumber);
        sb1.append(logChannel.getId());
        if (iterator.hasNext()) {
            sb1.append(Const.SEPARATOR);
        }
        ++colNumber;
    }
    appendColumnHeaderTimestamp(sb0);
    sb0.append(sb1);
    sb0.append(Const.LINESEPARATOR);
    return sb0.toString();
}
Also used : LogChannel(org.openmuc.framework.datalogger.spi.LogChannel)

Example 4 with LogChannel

use of org.openmuc.framework.datalogger.spi.LogChannel in project OpenMUC by isc-konstanz.

the class AmqpLogger method setChannelsToLog.

@Override
public void setChannelsToLog(List<LogChannel> logChannels) {
    channelsToLog.clear();
    for (LogChannel logChannel : logChannels) {
        String channelId = logChannel.getId();
        channelsToLog.put(channelId, logChannel);
    }
}
Also used : LogChannel(org.openmuc.framework.datalogger.spi.LogChannel)

Example 5 with LogChannel

use of org.openmuc.framework.datalogger.spi.LogChannel in project OpenMUC by isc-konstanz.

the class AmqpLogger method getQueueName.

private String getQueueName(String channelId) {
    LogChannel logChannelMeta = channelsToLog.get(channelId);
    String logSettings = logChannelMeta.getLoggingSettings();
    if (logSettings == null || logSettings.isEmpty()) {
        return propertyHandler.getString(Settings.FRAMEWORK) + channelId;
    } else {
        return parseDefinedQueue(logSettings);
    }
}
Also used : LogChannel(org.openmuc.framework.datalogger.spi.LogChannel)

Aggregations

LogChannel (org.openmuc.framework.datalogger.spi.LogChannel)21 LoggingRecord (org.openmuc.framework.datalogger.spi.LoggingRecord)6 Record (org.openmuc.framework.data.Record)4 IOException (java.io.IOException)3 Calendar (java.util.Calendar)3 LinkedList (java.util.LinkedList)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 DoubleValue (org.openmuc.framework.data.DoubleValue)2 LogFileWriter (org.openmuc.framework.datalogger.ascii.LogFileWriter)2 LogIntervalContainerGroup (org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup)2 MqttLogChannel (org.openmuc.framework.datalogger.mqtt.dto.MqttLogChannel)2 RandomAccessFile (java.io.RandomAccessFile)1 SQLException (java.sql.SQLException)1 GregorianCalendar (java.util.GregorianCalendar)1 Hashtable (java.util.Hashtable)1 TreeMap (java.util.TreeMap)1