def testCalculateTimestampInputDateAndTime1(self): time_utils = TimeUtils(self.test_date, self.test_time) actual = time_utils.calculateTimestamp(None, None, 140.320) expected = datetime.combine( self.test_date, self.test_time, tzinfo=timezone.utc) + timedelta( 0, 140.320) self.assertEqual( expected, actual, 'The calculated timestamp did not match the expected value.')
def process(input_paths, output_url, output_format, tags, output_batch_size, start_date_datum, start_time_datum): data = DataState() time_util = TimeUtils(start_date_datum, start_time_datum) data.set_data_item('DateTime', time_util.calculateTimestamp(None, None, 0.0)) last_data_time = data.state_time parser = Parser(data) formatter = FormatterFactory.getFormatter(output_format, tags) ostream = io.StringIO() header_line = formatter.formatHeading(data) if header_line is not None: if verbose > 0: print(header_line) print(header_line, end='\n', file=ostream) line_count = 0 for path in input_paths: print("Processing {0}".format(path)) with open(path, "r") as ifile: for data_line in ifile: input_line = data_line.strip() if verbose > 0: print(input_line) parser.parse(input_line) output_lines = formatter.formatData(data) if output_lines is not None: for output_line in output_lines: if verbose > 0: print(output_line) print(output_line, end='\n', file=ostream) line_count = line_count + 1 if data.state_time > last_data_time: last_data_time = data.state_time data.set_data_item( 'DateTime', time_util.calculateTimestamp( data.get_data_item('GPS_Date'), data.get_data_item('GPS_Time'), data.state_time)) output_line = formatter.formatTimeIncrement(data) if output_line is not None: if verbose > 0: print(output_line) print(output_line, end='\n', file=ostream) line_count = line_count + 1 if line_count >= output_batch_size: writeBatch(output_url, ostream) ostream.close() ostream = io.StringIO() line_count = 0 footer_line = formatter.formatFooter(data) if footer_line is not None: if verbose > 0: print(footer_line) print(footer_line, end='\n', file=ostream) writeBatch(output_url, ostream) ostream.close()
def testCalculatedTimestampInputDate3(self): time_utils = TimeUtils(self.test_date, None) test_gps_time = time(22, 38, 12) actual = time_utils.calculateTimestamp(None, test_gps_time, 2273.431) expected = datetime.combine(self.test_date, test_gps_time, tzinfo=timezone.utc) self.assertEqual( expected, actual, 'Time calculated timestamp did not match the expected value.')
def testCalculatedTimestampInputDateAndTime2(self): time_utils = TimeUtils(self.test_date, self.test_time) test_gps_date = date(1999, 12, 19) actual = time_utils.calculateTimestamp(test_gps_date, None, 1432.938) expected = datetime.combine( self.test_date, self.test_time, tzinfo=timezone.utc) + timedelta( 0, 1432.938) self.assertEqual( expected, actual, 'Time calculated timestamp did not match the expected value.')
def testCalculatedTimestampNoInput4(self): time_utils = TimeUtils(None, None) test_gps_date = date(2019, 8, 19) test_gps_time = time(22, 38, 12) actual = time_utils.calculateTimestamp(test_gps_date, test_gps_time, 1174.835) expected = datetime.combine(test_gps_date, test_gps_time, timezone.utc) self.assertEqual( expected, actual, 'Time calculated timestamp did not match the expected value.')
def testCalculatedTimestampInputDate2(self): time_utils = TimeUtils(self.test_date, None) test_gps_date = date(1999, 12, 19) actual = time_utils.calculateTimestamp(test_gps_date, None, 1432.938) self.assertIsNone(actual, 'The calculated timestamp was expected to be None.')
def testCalculateTimestampInputDate1(self): time_utils = TimeUtils(self.test_date, None) actual = time_utils.calculateTimestamp(None, None, 140.320) self.assertIsNone(actual, 'The calculated timestamp was expected to be None.')
def testCalculatedTimestampNoInput3(self): time_utils = TimeUtils(None, None) test_gps_time = time(22, 38, 12) actual = time_utils.calculateTimestamp(None, test_gps_time, 2273.431) self.assertIsNone(actual, 'The calculated timestamp was expected to be None.')