forked from commaai/openpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: add bootlog helpers (commaai#23504)
* tools: add bootlog helpers * this is nice * types
- Loading branch information
1 parent
f808b17
commit 7d7c0ff
Showing
3 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import datetime | ||
import functools | ||
import re | ||
|
||
from tools.lib.auth_config import get_token | ||
from tools.lib.api import CommaApi | ||
from tools.lib.helpers import RE, timestamp_to_datetime | ||
|
||
|
||
@functools.total_ordering | ||
class Bootlog: | ||
def __init__(self, url: str): | ||
self._url = url | ||
|
||
r = re.search(RE.BOOTLOG_NAME, url) | ||
if not r: | ||
raise Exception(f"Unable to parse: {url}") | ||
|
||
self._dongle_id = r.group('dongle_id') | ||
self._timestamp = r.group('timestamp') | ||
|
||
@property | ||
def url(self) -> str: | ||
return self._url | ||
|
||
@property | ||
def dongle_id(self) -> str: | ||
return self._dongle_id | ||
|
||
@property | ||
def timestamp(self) -> str: | ||
return self._timestamp | ||
|
||
@property | ||
def datetime(self) -> datetime.datetime: | ||
return timestamp_to_datetime(self._timestamp) | ||
|
||
def __eq__(self, b) -> bool: | ||
return self.datetime == b.datetime | ||
|
||
def __lt__(self, b) -> bool: | ||
return self.datetime < b.datetime | ||
|
||
|
||
def get_bootlogs(dongle_id: str): | ||
api = CommaApi(get_token()) | ||
r = api.get(f'v1/devices/{dongle_id}/bootlogs') | ||
return [Bootlog(b) for b in r] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import datetime | ||
|
||
TIME_FMT = "%Y-%m-%d--%H-%M-%S" | ||
|
||
# regex patterns | ||
class RE: | ||
DONGLE_ID = r'(?P<dongle_id>[a-z0-9]{16})' | ||
TIMESTAMP = r'(?P<timestamp>[0-9]{4}-[0-9]{2}-[0-9]{2}--[0-9]{2}-[0-9]{2}-[0-9]{2})' | ||
ROUTE_NAME = r'{}[|_/]{}'.format(DONGLE_ID, TIMESTAMP) | ||
SEGMENT_NAME = r'{}(?:--|/)(?P<segment_num>[0-9]+)'.format(ROUTE_NAME) | ||
BOOTLOG_NAME = ROUTE_NAME | ||
|
||
EXPLORER_FILE = r'^(?P<segment_name>{})--(?P<file_name>[a-z]+\.[a-z0-9]+)$'.format(SEGMENT_NAME) | ||
OP_SEGMENT_DIR = r'^(?P<segment_name>{})$'.format(SEGMENT_NAME) | ||
|
||
def timestamp_to_datetime(t: str) -> datetime.datetime: | ||
""" | ||
Convert an openpilot route timestamp to a python datetime | ||
""" | ||
return datetime.datetime.strptime(t, TIME_FMT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters