use of org.openmuc.framework.data.Record 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.data.Record 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.data.Record in project OpenMUC by isc-konstanz.
the class LoggerUtilsTest method tc_505_test_findLatestValue.
@Test
public void tc_505_test_findLatestValue() {
Map<String, List<Record>> recordsMap = new HashMap<>();
for (int j = 0; j < 5; j++) {
List<Record> records = new LinkedList<>();
for (int i = 0; i < 20; i++) {
long timestamp = i;
DoubleValue value = new DoubleValue(i + j);
Record record = new Record(value, timestamp);
records.add(record);
}
recordsMap.put("channel" + j, records);
}
Map<String, Record> latestValue = LoggerUtils.findLatestValue(recordsMap);
for (int j = 0; j < 5; j++) {
Double actual = latestValue.get("channel" + j).getValue().asDouble();
Double expected = 19.0 + j;
assertEquals(expected, actual);
}
}
use of org.openmuc.framework.data.Record in project OpenMUC by isc-konstanz.
the class LogFileReader method getRecordFromNonNumberValue.
/**
* Returns the record from a non number value read from the logfile. This is the case if the value is an error like
* "e0" or a normal ByteArrayValue
*
* @param strValue
* string value
* @param timestamp
* time stamp
* @return the value in a record.
*/
private Record getRecordFromNonNumberValue(String strValue, long timestamp) {
Record record = null;
if (strValue.trim().startsWith(Const.ERROR)) {
int errorSize = Const.ERROR.length();
int stringLength = strValue.length();
String errorFlag = strValue.substring(errorSize, errorSize + stringLength - errorSize);
errorFlag = errorFlag.trim();
if (isNumber(errorFlag)) {
record = new Record(null, timestamp, Flag.newFlag(Integer.parseInt(errorFlag)));
} else {
record = new Record(null, timestamp, Flag.NO_VALUE_RECEIVED_YET);
}
} else if (strValue.trim().startsWith(Const.HEXADECIMAL)) {
record = new Record(new ByteArrayValue(strValue.trim().getBytes(Const.CHAR_SET)), timestamp, Flag.VALID);
} else {
record = new Record(new StringValue(strValue.trim()), timestamp, Flag.VALID);
}
return record;
}
use of org.openmuc.framework.data.Record in project OpenMUC by isc-konstanz.
the class AsciiLogger method getLatestLogRecord.
/**
* Get the latest logged Record for the given value. This is achieved by searching within a few times the
* loggingInterval from the current time for any record and then selecting the one with the highest timestamp
*
* @param channelId
* to be searched
* @return latest Record
*/
@Override
public Record getLatestLogRecord(String channelId) throws IOException {
LogChannel logChannel = logChannelList.get(channelId);
LogFileReader reader = null;
if (logChannel == null) {
throw new IOException("ChannelID (" + channelId + ") not available. It's not a logging Channel.");
}
reader = new LogFileReader(loggerDirectory, logChannel);
// attempt to find a record within the last day
long endTime = System.currentTimeMillis();
long startTime = endTime - MS_PER_DAY;
Map<String, List<Record>> recordsMap = reader.getValues(startTime, endTime);
Map<String, Record> latestRecordsMap = LoggerUtils.findLatestValue(recordsMap);
Record record = latestRecordsMap.get(channelId);
if (record != null) {
return record;
}
// Fallback: read all files and find the latest record within these
List<File> files = LoggerUtils.getAllDataFiles(loggerDirectory);
if (files == null) {
return null;
}
File file = LoggerUtils.getLatestFile(files);
if (file == null) {
return null;
}
recordsMap = reader.getValues(file.getPath());
latestRecordsMap = LoggerUtils.findLatestValue(recordsMap);
record = latestRecordsMap.get(channelId);
return record;
}
Aggregations