Skip to content

Commit

Permalink
Issue #189 - Update backend handling of Complex types when diffing
Browse files Browse the repository at this point in the history
Update handling of packet diffing to include complex types (Time, Cmd,
and EVR) in with DN-to-EU values. This pushes human-readable info for
these types to the frontend so clients don't need to inspect the
dictionaries to determine what should be displayed.

Update calls to `replace_datetimes` so the "dntoeu" diffs are passed
instead of the raw ones. Previously these calls weren't doing anything
since the passed diffs were always raw values. This was likely left in
from a previous iteration on this functionality.

Note, this doesn't make sweeping changes to the diffing code and instead
works around the existing framework. The current stuff is a bit of a
mess and could really use some TLC. We'll need to revisit this in a
follow up ticket.
  • Loading branch information
MJJoyce committed Jan 21, 2021
1 parent 0af0c88 commit 2d2f36c
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions ait/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def addTelemetry (self, uid, packet):
pkt_defn = getPacketDefn(uid)
pkt_name = pkt_defn.name
delta, dntoeus = get_packet_delta(pkt_defn, packet)
delta = replace_datetimes(delta)
dntoeus = replace_datetimes(dntoeus)

for session in self.values():
counter = session.updateCounter(pkt_name)
Expand Down Expand Up @@ -748,9 +748,24 @@ def get_packet_delta(pkt_defn, packet):
packet_states[pkt_defn.name]['raw'] = raw_fields
delta = raw_fields

# get converted fields
# get converted fields / complex fields
packet_states[pkt_defn.name]['dntoeu'] = {}
dntoeus = {f.name: getattr(ait_pkt, f.name) for f in pkt_defn.fields if f.dntoeu is not None}
dntoeus = {}
for f in pkt_defn.fields:
if f.dntoeu is not None or f.enum is not None or f.type.name in dtype.ComplexTypeMap.keys():
try:
val = getattr(ait_pkt, f.name)
except ValueError:
if isinstance(f.type, dtype.CmdType):
val = "Unidentified Cmd"
else:
val = getattr(ait_pkt.raw, f.name)

if isinstance(val, cmd.CmdDefn) or isinstance(val, evr.EVRDefn):
val = val.name

dntoeus[f.name] = val


# get derivations
packet_states[pkt_defn.name]['raw'].update({f.name: getattr(ait_pkt.raw, f.name) for f in pkt_defn.derivations})
Expand All @@ -768,8 +783,18 @@ def get_packet_delta(pkt_defn, packet):
delta[field.name] = new_value
packet_states[pkt_defn.name]['raw'][field.name] = new_value

if field.dntoeu is not None:
dntoeu_val = getattr(ait_pkt, field.name)
if field.dntoeu is not None or field.enum is not None or field.type.name in dtype.ComplexTypeMap.keys():
try:
dntoeu_val = getattr(ait_pkt, field.name)
except ValueError:
if isinstance(field.type, dtype.CmdType):
dntoeu_val = "Unidentified Cmd"
else:
dntoeu_val = getattr(ait_pkt.raw, field.name)

if isinstance(dntoeu_val, cmd.CmdDefn) or isinstance(dntoeu_val, evr.EVRDefn):
dntoeu_val = dntoeu_val.name

dntoeus[field.name] = dntoeu_val
packet_states[pkt_defn.name]['dntoeu'][field.name] = dntoeu_val

Expand Down Expand Up @@ -837,7 +862,7 @@ def handle():
def handle():
"""Return latest telemetry packet to client"""
for pkt_type, state in packet_states.items():
packet_states[pkt_type]['raw'] = replace_datetimes(state['raw'])
packet_states[pkt_type]['dntoeu'] = replace_datetimes(state['dntoeu'])

with Sessions.current() as session:
counters = session.tlm_counters
Expand Down

0 comments on commit 2d2f36c

Please sign in to comment.