Search in sources :

Example 1 with LogFileWriter

use of org.openmuc.framework.datalogger.ascii.LogFileWriter 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 LogFileWriter

use of org.openmuc.framework.datalogger.ascii.LogFileWriter in project OpenMUC by isc-konstanz.

the class LoggerUtilsTest method setup.

@BeforeAll
public static void setup() {
    int sub = (int) (calendar.getTimeInMillis() % 10l);
    calendar.add(Calendar.MILLISECOND, -loggingInterval * 5 - sub);
    TestUtils.createTestFolder();
    TestUtils.deleteExistingFile(loggingInterval, loggingTimeOffset, calendar);
    LogChannelTestImpl ch1 = new LogChannelTestImpl(ch01, "", "dummy description", dummy, ValueType.DOUBLE, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
    logChannelList.put(ch01, ch1);
    long timeStamp = calendar.getTimeInMillis();
    for (int i = 0; i < 5; ++i) {
        LogFileWriter lfw = new LogFileWriter(TestUtils.TESTFOLDERPATH, false);
        LogIntervalContainerGroup group = getGroup(timeStamp, i);
        lfw.log(group, loggingInterval, loggingTimeOffset, calendar, logChannelList);
        AsciiLogger.setLastLoggedLineTimeStamp(loggingInterval, loggingTimeOffset, calendar.getTimeInMillis());
        calendar.add(Calendar.MILLISECOND, loggingInterval);
    }
}
Also used : LogIntervalContainerGroup(org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup) LogFileWriter(org.openmuc.framework.datalogger.ascii.LogFileWriter) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with LogFileWriter

use of org.openmuc.framework.datalogger.ascii.LogFileWriter in project OpenMUC by isc-konstanz.

the class LogFileReaderTestMultipleFiles method setup.

@BeforeAll
public static void setup() {
    System.out.println("### Setup() LogFileReaderTestMultipleFiles");
    TestUtils.createTestFolder();
    // drei Dateien
    // 1 Kanal im Sekunden-Takt loggen ueber von 23 Uhr bis 1 Uhr des uebernaechsten Tages
    // --> Ergebnis muessten drei
    // Dateien sein die vom LogFileWriter erstellt wurden
    String filename0 = TestUtils.TESTFOLDERPATH + fileDate0 + "_" + loggingInterval + EXT;
    String filename1 = TestUtils.TESTFOLDERPATH + fileDate1 + "_" + loggingInterval + EXT;
    String filename2 = TestUtils.TESTFOLDERPATH + fileDate2 + "_" + loggingInterval + EXT;
    File file0 = new File(filename0);
    File file1 = new File(filename1);
    File file2 = new File(filename2);
    if (file0.exists()) {
        System.out.println("Delete File " + filename2);
        file0.delete();
    }
    if (file1.exists()) {
        System.out.println("Delete File " + filename1);
        file1.delete();
    }
    if (file2.exists()) {
        System.out.println("Delete File " + filename2);
        file2.delete();
    }
    HashMap<String, LogChannel> logChannelList = new HashMap<>();
    LogChannelTestImpl ch0 = new LogChannelTestImpl("power", "", "dummy description", "kW", ValueType.DOUBLE, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
    logChannelList.put(Channel0Name, ch0);
    Calendar calendar = TestUtils.stringToDate(dateFormat, fileDate0 + " 23:00:00");
    int hour = 3600;
    for (int i = 0; i < ((hour * 24 + hour * 2) * (1000d / loggingInterval)); i++) {
        LoggingRecord container1 = new LoggingRecord(Channel0Name, new Record(new DoubleValue(1), 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) Calendar(java.util.Calendar) LogChannel(org.openmuc.framework.datalogger.spi.LogChannel) LogIntervalContainerGroup(org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup) LogFileWriter(org.openmuc.framework.datalogger.ascii.LogFileWriter) LoggingRecord(org.openmuc.framework.datalogger.spi.LoggingRecord) DoubleValue(org.openmuc.framework.data.DoubleValue) Record(org.openmuc.framework.data.Record) LoggingRecord(org.openmuc.framework.datalogger.spi.LoggingRecord) File(java.io.File) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with LogFileWriter

use of org.openmuc.framework.datalogger.ascii.LogFileWriter in project OpenMUC by isc-konstanz.

the class LogFileWriterTest method setup.

@BeforeAll
public static void setup() {
    System.out.println("### Setup() LogFileWriterTest");
    TestUtils.createTestFolder();
    // 2 Kanaele im Stunden-Takt loggen von 12 Uhr bis 12 Uhr in den naechsten Tage hinein
    // --> Ergebnis muessten zwei Dateien sein die vom LogFileWriter erstellt wurden
    String filename1 = TestUtils.TESTFOLDERPATH + fileDate1 + "_" + loggingInterval + ext;
    String filename2 = TestUtils.TESTFOLDERPATH + fileDate2 + "_" + loggingInterval + ext;
    File file1 = new File(filename1);
    File file2 = new File(filename2);
    if (file1.exists()) {
        System.out.println("Delete File " + filename1);
        file1.delete();
    }
    if (file2.exists()) {
        System.out.println("Delete File " + filename2);
        file2.delete();
    }
    LogChannelTestImpl ch1 = new LogChannelTestImpl(ch01, "", "dummy description", dummy, ValueType.FLOAT, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
    LogChannelTestImpl ch2 = new LogChannelTestImpl(ch02, "", "dummy description", dummy, ValueType.DOUBLE, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
    LogChannelTestImpl ch3 = new LogChannelTestImpl(ch03, "", "dummy description", dummy, ValueType.BOOLEAN, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
    LogChannelTestImpl ch4 = new LogChannelTestImpl(ch04, "", "dummy description", dummy, ValueType.SHORT, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
    LogChannelTestImpl ch5 = new LogChannelTestImpl(ch05, "", "dummy description", dummy, ValueType.INTEGER, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
    LogChannelTestImpl ch6 = new LogChannelTestImpl(ch06, "", "dummy description", dummy, ValueType.LONG, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
    LogChannelTestImpl ch7 = new LogChannelTestImpl(ch07, "", "dummy description", dummy, ValueType.BYTE, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
    LogChannelTestImpl ch8 = new LogChannelTestImpl(ch08, "", "dummy description", dummy, ValueType.STRING, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false, valueLength);
    LogChannelTestImpl ch9 = new LogChannelTestImpl(ch09, "", "dummy description", dummy, ValueType.BYTE_ARRAY, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false, valueLengthByteArray);
    logChannelList.put(ch01, ch1);
    logChannelList.put(ch02, ch2);
    logChannelList.put(ch03, ch3);
    logChannelList.put(ch04, ch4);
    logChannelList.put(ch05, ch5);
    logChannelList.put(ch06, ch6);
    logChannelList.put(ch07, ch7);
    logChannelList.put(ch08, ch8);
    logChannelList.put(ch09, ch9);
    long timeStamp = calendar.getTimeInMillis();
    boolean boolValue;
    byte byteValue = 0;
    String testString;
    // writes 24 records for 2 channels from 12 o'clock till 12 o'clock of the other day
    // Set to 0, for deleting
    AsciiLogger.setLastLoggedLineTimeStamp(loggingInterval, loggingTimeOffset, 0);
    for (int i = 0; i < ((60 * 10) * (1000d / loggingInterval)); ++i) {
        if ((i % 2) > 0) {
            boolValue = true;
            testString = testStringValueCorrect;
        } else {
            boolValue = false;
            testString = testStringValueIncorrect;
        }
        LogFileWriter lfw = new LogFileWriter(TestUtils.TESTFOLDERPATH, false);
        LogIntervalContainerGroup group = getGroup(timeStamp, i, boolValue, byteValue, testString);
        lfw.log(group, loggingInterval, loggingTimeOffset, calendar, logChannelList);
        AsciiLogger.setLastLoggedLineTimeStamp(loggingInterval, loggingTimeOffset, calendar.getTimeInMillis());
        calendar.add(Calendar.MILLISECOND, loggingInterval);
        ++byteValue;
    }
}
Also used : LogIntervalContainerGroup(org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup) LogFileWriter(org.openmuc.framework.datalogger.ascii.LogFileWriter) File(java.io.File) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

BeforeAll (org.junit.jupiter.api.BeforeAll)4 LogFileWriter (org.openmuc.framework.datalogger.ascii.LogFileWriter)4 LogIntervalContainerGroup (org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup)4 File (java.io.File)2 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 DoubleValue (org.openmuc.framework.data.DoubleValue)2 Record (org.openmuc.framework.data.Record)2 LogChannel (org.openmuc.framework.datalogger.spi.LogChannel)2 LoggingRecord (org.openmuc.framework.datalogger.spi.LoggingRecord)2