use of org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup 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);
}
// }
}
use of org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup in project OpenMUC by isc-konstanz.
the class LogFileWriterTest method getGroup.
private static LogIntervalContainerGroup getGroup(long timeStamp, int i, boolean boolValue, byte byteValue, String testString) {
LogIntervalContainerGroup group = new LogIntervalContainerGroup();
LoggingRecord container1 = new LoggingRecord(ch01, new Record(new FloatValue(i * -7 - 0.555F), timeStamp));
LoggingRecord container2 = new LoggingRecord(ch02, new Record(new DoubleValue(i * +7 - 0.555), timeStamp));
LoggingRecord container3 = new LoggingRecord(ch03, new Record(new BooleanValue(boolValue), timeStamp));
LoggingRecord container4 = new LoggingRecord(ch04, new Record(new ShortValue((short) i), timeStamp));
LoggingRecord container5 = new LoggingRecord(ch05, new Record(new IntValue(i), timeStamp));
LoggingRecord container6 = new LoggingRecord(ch06, new Record(new LongValue(i * 1000000), timeStamp));
LoggingRecord container7 = new LoggingRecord(ch07, new Record(new ByteValue(byteValue), timeStamp));
LoggingRecord container8 = new LoggingRecord(ch08, new Record(new StringValue(testString), timeStamp));
LoggingRecord container9 = new LoggingRecord(ch09, new Record(new ByteArrayValue(testByteArray), timeStamp));
group.add(container1);
group.add(container2);
group.add(container3);
group.add(container4);
group.add(container5);
group.add(container6);
group.add(container7);
group.add(container8);
group.add(container9);
return group;
}
use of org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup in project OpenMUC by isc-konstanz.
the class LogFileWriterTest method tc301_check_file_fill_up_at_logging.
// @Test
// public void tc302_check_file_fill_up_at_logging_at_day_change() {
// // TODO:
// second_setup();
// System.out.println("### Begin test tc301_check_file_fill_up_at_logging_at_day_change");
//
// int valuesToWrite = 5;
//
// calendar.add(Calendar.MILLISECOND, loggingInterval * valuesToWrite);
//
// LogIntervalContainerGroup group = getSecondGroup(calendar.getTimeInMillis(), 4);
// lfw.log(group, loggingInterval, loggingTimeOffset, calendar, logChannelList);
//
// LogChannelTestImpl ch1 = new LogChannelTestImpl(ch01, "dummy description", dummy, ValueType.FLOAT,
// loggingInterval, loggingTimeOffset);
// LogFileReader lfr = new LogFileReader(TestUtils.TESTFOLDERPATH, ch1);
//
// List<Record> recordList = lfr.getValues(calendar.getTimeInMillis() - loggingInterval * 5,
// calendar.getTimeInMillis());
// int receivedRecords = recordList.size();
//
// int numErrorFlags = 0;
// for (Record record : recordList) {
// if (record.getFlag().equals(Flag.DATA_LOGGING_NOT_ACTIVE)) {
// ++numErrorFlags;
// }
// }
//
// Boolean assertT;
// if (receivedRecords == valuesToWrite && numErrorFlags == valuesToWrite - 1) {
// assertT = true;
// }
// else {
// assertT = false;
// }
// System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName());
// System.out.println(" records = " + receivedRecords + " (" + valuesToWrite + " expected)");
// System.out
// .println(" records with error flag 32 = " + numErrorFlags + " (" + (valuesToWrite - 1) + " expected)");
//
// assertTrue(assertT);
// }
// private void second_setup() {
//
// System.out.println("### second_setup() LogFileWriterTest");
//
// TestSuite.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,
// loggingInterval, loggingTimeOffset);
//
// logChannelList.put(ch01, ch1);
//
// long timeStamp = calendar.getTimeInMillis();
//
// // writes 24 records for 2 channels from 12 o'clock till 12 o'clock of the other day
// AsciiLogger.setLastLoggedLineTimeStamp(loggingInterval, loggingTimeOffset, 0); // Set to 0, for deleting
// // timestamp of previous test
// for (int i = 0; i < ((60 * 10) * (1000d / loggingInterval)); ++i) {
//
// LogFileWriter lfw = new LogFileWriter(TestUtils.TESTFOLDERPATH, true);
//
// LogIntervalContainerGroup group = getSecondGroup(timeStamp, i);
// lfw.log(group, loggingInterval, loggingTimeOffset, calendar, logChannelList);
// calendar.add(Calendar.MILLISECOND, loggingInterval);
// }
// }
@Test
public void tc301_check_file_fill_up_at_logging() {
System.out.println("### Begin test tc301_check_file_fill_up_at_logging");
int valuesToWrite = 5;
calendar.add(Calendar.MILLISECOND, loggingInterval * valuesToWrite - 10);
LogIntervalContainerGroup group = getGroup(calendar.getTimeInMillis(), 3, true, (byte) 0x11, "nope");
lfw.log(group, loggingInterval, loggingTimeOffset, calendar, logChannelList);
AsciiLogger.setLastLoggedLineTimeStamp(loggingInterval, loggingTimeOffset, calendar.getTimeInMillis());
LogChannelTestImpl ch1 = new LogChannelTestImpl(ch01, "", "dummy description", dummy, ValueType.FLOAT, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
LogFileReader lfr = new LogFileReader(TestUtils.TESTFOLDERPATH, ch1);
List<Record> recordList = lfr.getValues(calendar.getTimeInMillis() - loggingInterval * 5, calendar.getTimeInMillis()).get(ch01);
int receivedRecords = recordList.size();
int numErrorFlags = 0;
for (Record record : recordList) {
if (record.getFlag().equals(Flag.DATA_LOGGING_NOT_ACTIVE)) {
++numErrorFlags;
}
}
Boolean assertT;
if (receivedRecords == valuesToWrite && numErrorFlags == valuesToWrite - 1) {
assertT = true;
} else {
assertT = false;
}
System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName());
System.out.println(" records = " + receivedRecords + " (" + valuesToWrite + " expected)");
System.out.println(" records with error flag 32 = " + numErrorFlags + " (" + (valuesToWrite - 1) + " expected)");
assertTrue(assertT);
}
use of org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup in project OpenMUC by isc-konstanz.
the class LoggerUtilsTest method tc_503_test_fillUpFileWithErrorCode.
// ####################################################################################################################
// ####################################################################################################################
// ####################################################################################################################
@Test
public void tc_503_test_fillUpFileWithErrorCode() {
long lastTimestamp = AsciiLogger.fillUpFileWithErrorCode(TestUtils.TESTFOLDERPATH, Integer.toString(loggingInterval), calendar);
AsciiLogger.setLastLoggedLineTimeStamp(loggingInterval, loggingTimeOffset, lastTimestamp);
LogIntervalContainerGroup group = getGroup(calendar.getTimeInMillis(), 3);
calendar = new GregorianCalendar();
int sub = (int) (calendar.getTimeInMillis() % 10l);
calendar.add(Calendar.MILLISECOND, -sub + 10);
lfw.log(group, loggingInterval, loggingTimeOffset, calendar, logChannelList);
AsciiLogger.setLastLoggedLineTimeStamp(loggingInterval, loggingTimeOffset, calendar.getTimeInMillis());
LogChannelTestImpl ch1 = new LogChannelTestImpl(ch01, "", "dummy description", dummy, ValueType.DOUBLE, 0.0, 0.0, false, 1000, 0, "", loggingInterval, loggingTimeOffset, false, false);
}
use of org.openmuc.framework.datalogger.ascii.LogIntervalContainerGroup 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);
}
}
Aggregations