calc max and min, numpy, cloudlog

pull/36045/head
Quantizr (Jimmy) 1 month ago
parent 5fb1e29514
commit f4afe9c347
  1. 22
      tools/jotpluggler/data.py

@ -2,6 +2,7 @@ import threading
import numpy as np import numpy as np
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Any from typing import Any
from openpilot.common.swaglog import cloudlog
from openpilot.tools.lib.logreader import LogReader from openpilot.tools.lib.logreader import LogReader
from openpilot.tools.lib.log_time_series import msgs_to_time_series from openpilot.tools.lib.log_time_series import msgs_to_time_series
@ -28,12 +29,13 @@ class LogReaderSource(DataSource):
raw_time_series = msgs_to_time_series(lr) raw_time_series = msgs_to_time_series(lr)
processed_data = self._expand_list_fields(raw_time_series) processed_data = self._expand_list_fields(raw_time_series)
# Calculate timing information min_time = float('inf')
times = [data['t'] for data in processed_data.values() if 't' in data and len(data['t']) > 0] max_time = float('-inf')
if times: for data in processed_data.values():
all_times = np.concatenate(times) min_time = min(min_time, data['t'][0])
self._start_time_mono = all_times.min() max_time = max(max_time, data['t'][-1])
self._duration = all_times.max() - self._start_time_mono self._start_time_mono = min_time
self._duration = max_time - min_time
return {'time_series_data': processed_data, 'route_start_time_mono': self._start_time_mono, 'duration': self._duration} return {'time_series_data': processed_data, 'route_start_time_mono': self._start_time_mono, 'duration': self._duration}
@ -50,7 +52,7 @@ class LogReaderSource(DataSource):
expanded_data[msg_type]['t'] = values expanded_data[msg_type]['t'] = values
continue continue
if isinstance(values, np.ndarray) and values.dtype == object: # ragged array if values.dtype == object: # ragged array
lens = np.fromiter((len(v) for v in values), dtype=int, count=len(values)) lens = np.fromiter((len(v) for v in values), dtype=int, count=len(values))
max_len = lens.max() if lens.size else 0 max_len = lens.max() if lens.size else 0
if max_len > 0: if max_len > 0:
@ -60,7 +62,7 @@ class LogReaderSource(DataSource):
for i in range(max_len): for i in range(max_len):
sub_arr = arr[:, i] sub_arr = arr[:, i]
expanded_data[msg_type][f"{field}/{i}"] = sub_arr expanded_data[msg_type][f"{field}/{i}"] = sub_arr
elif isinstance(values, np.ndarray) and values.ndim > 1: # regular array elif values.ndim > 1: # regular multidimensional array
for i in range(values.shape[1]): for i in range(values.shape[1]):
col_data = values[:, i] col_data = values[:, i]
expanded_data[msg_type][f"{field}/{i}"] = col_data expanded_data[msg_type][f"{field}/{i}"] = col_data
@ -173,7 +175,7 @@ class DataManager:
self._notify_observers(DataLoadedEvent(data)) self._notify_observers(DataLoadedEvent(data))
except Exception as e: except Exception:
print(f"Error loading route: {e}") cloudlog.exception("Error loading route:")
finally: finally:
self.loading = False self.loading = False

Loading…
Cancel
Save