Skip to content

Commit

Permalink
revise primary_ble_sensed_mode_for_trip again for JS
Browse files Browse the repository at this point in the history
As it turns out, Transcrypt doesn't support the 'index' argument of the max() function, so we cannot use the preferred Python method here.
We'll have to make our own little for-loop to find the max. Finally, this works in JS as well as Python!
  • Loading branch information
JGreenlee committed May 7, 2024
1 parent 1409664 commit 78d536f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 7 additions & 4 deletions emcommon_js/emcommon.bluetooth.ble_matching.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/emcommon/bluetooth/ble_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ def get_vehicle_with_ble_beacon(major_minor, app_config):
Logger.log_debug('no vehicle found for BLE beacon %s' % major_minor)
return None

def primary_ble_sensed_mode_for_trip(trip: dict) -> str:
def primary_ble_sensed_mode_for_trip(trip) -> str:
"""
Returns the primary BLE sensed mode for the trip (the mode with the greatest distance).
"""
if 'ble_sensed_summary' not in trip or 'distance' not in trip['ble_sensed_summary']:
return None
dists = trip['ble_sensed_summary']['distance']
dists = dists if type(dists) == dict else dict(dists)
# return the key of the mode with the greatest distance
return max(dists, key=lambda mode: dists[mode])
high = (None, 0)
for k, v in dists.items():
high = (k, v) if v > high[1] else high
return high[0]

0 comments on commit 78d536f

Please sign in to comment.