Skip to content
Snippets Groups Projects
Commit 642ba4b4 authored by Bruce Flynn's avatar Bruce Flynn
Browse files

fix issues related to new timecode code

parent 80af8eaf
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ import pprint ...@@ -11,6 +11,7 @@ import pprint
import edosl0util.crio as crio import edosl0util.crio as crio
from edosl0util.headers import DaySegmentedTimecode from edosl0util.headers import DaySegmentedTimecode
from edosl0util.stream import jpss_packet_stream from edosl0util.stream import jpss_packet_stream
from edosl0util.timecode import dt_to_cds
def diff_crs(real_file, generated_file): def diff_crs(real_file, generated_file):
...@@ -115,7 +116,7 @@ def pds_id_from_path(pds_file): ...@@ -115,7 +116,7 @@ def pds_id_from_path(pds_file):
def get_pds_creation_time(pds_file_or_id): def get_pds_creation_time(pds_file_or_id):
"""Parse 11-char creation time out of a PDS ID or file name; return a DaySegmentedTimecode""" """Parse 11-char creation time out of a PDS ID or file name; return a DaySegmentedTimecode"""
pds_file_or_id = os.path.basename(pds_file_or_id) pds_file_or_id = os.path.basename(pds_file_or_id)
return create_timecode(datetime.strptime(pds_file_or_id[22:33], '%y%j%H%M%S')) return create_timecode(dt_to_cds(datetime.strptime(pds_file_or_id[22:33], '%y%j%H%M%S')))
def build_apid_info(scan_apid_info): def build_apid_info(scan_apid_info):
...@@ -189,7 +190,7 @@ def scan_packets(pds_file, prev_pds_file=None): ...@@ -189,7 +190,7 @@ def scan_packets(pds_file, prev_pds_file=None):
if pkt.cds_timecode: if pkt.cds_timecode:
if not first_pkt_time: if not first_pkt_time:
first_pkt_time = pkt.cds_timecode first_pkt_time = pkt.cds_timecode
last_pkt_time = pkt.cds_timemcode last_pkt_time = pkt.cds_timecode
return {'first_packet_time': create_timecode(first_pkt_time), return {'first_packet_time': create_timecode(first_pkt_time),
'last_packet_time': create_timecode(last_pkt_time), 'last_packet_time': create_timecode(last_pkt_time),
'apid_info': [apid_map[k] for k in sorted(apid_map)]} 'apid_info': [apid_map[k] for k in sorted(apid_map)]}
...@@ -241,7 +242,7 @@ def create_timecode(tc): ...@@ -241,7 +242,7 @@ def create_timecode(tc):
Handles input of None by returning epoch value of 1958-01-01. Handles input of None by returning epoch value of 1958-01-01.
""" """
return DaySegmentedTimecode(tc.days, tc.millis, tc.micros) if tc else DaySegmentedTimecode() return DaySegmentedTimecode(*tc) if tc else DaySegmentedTimecode()
idps_epoch = datetime(1958, 1, 1) idps_epoch = datetime(1958, 1, 1)
......
...@@ -95,11 +95,14 @@ def read_packet_index(stream): ...@@ -95,11 +95,14 @@ def read_packet_index(stream):
def _sort_by_time_apid(index, order=None): def _sort_by_time_apid(index, order=None):
"""
Sort pointers by time and apid in-place.
"""
if order: if order:
index = sorted(index, key=lambda p: order.index(p.apid) if p.apid in order else -1) index = sorted(index, key=lambda p: order.index(p.apid) if p.apid in order else -1)
else: else:
index = sorted(index, key=lambda p: p.apid) index = sorted(index, key=lambda p: p.apid)
return sorted(index, key=lambda p: p.cds_timecode) return sorted(index, key=lambda p: p.timecode)
def _filter_duplicates_by_size(index): def _filter_duplicates_by_size(index):
......
...@@ -124,7 +124,7 @@ class Packet(object): ...@@ -124,7 +124,7 @@ class Packet(object):
return ( return (
self.secondary_header and self.secondary_header and
hasattr(self.secondary_header, 'timecode') and hasattr(self.secondary_header, 'timecode') and
self.secondary_header.day_segmented_timecode() or None) self.secondary_header.timecode.day_segmented_timecode() or None)
@property @property
def stamp(self): def stamp(self):
......
...@@ -48,4 +48,12 @@ def cds_to_dt(days, ms, us): ...@@ -48,4 +48,12 @@ def cds_to_dt(days, ms, us):
return timecode_parts_to_dt(days, ms, us, CDS_EPOCH) return timecode_parts_to_dt(days, ms, us, CDS_EPOCH)
def dt_to_cds(dt):
"""
UTC datetime to (day, millis, micros)
"""
d = (dt - CDS_EPOCH)
return (d.days, int(d.seconds * 1e3), d.microseconds)
iet_to_dt = _grain.iet2utc iet_to_dt = _grain.iet2utc
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment