-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ff1523
commit 4d3eb96
Showing
39 changed files
with
2,304 additions
and
363 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
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
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
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
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,4 @@ | ||
log_substring_contains: | ||
contains($1, $2) | ||
is_even: | ||
mod($1, 2) == 0 |
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 |
---|---|---|
|
@@ -4,25 +4,25 @@ ingestion_client_key: lunar_vehicle_426 | |
channels: | ||
log_channel: &log_channel | ||
name: log | ||
data_type: CHANNEL_DATA_TYPE_STRING | ||
data_type: string | ||
description: asset logs | ||
|
||
velocity_channel: &velocity_channel | ||
name: velocity | ||
data_type: CHANNEL_DATA_TYPE_DOUBLE | ||
data_type: double | ||
description: speed | ||
unit: Miles Per Hour | ||
component: mainmotor | ||
|
||
voltage_channel: &voltage_channel | ||
name: voltage | ||
data_type: CHANNEL_DATA_TYPE_INT_32 | ||
data_type: int32 | ||
description: voltage at the source | ||
unit: Volts | ||
|
||
vehicle_state_channel: &vehicle_state_channel | ||
name: vehicle_state | ||
data_type: CHANNEL_DATA_TYPE_ENUM | ||
data_type: enum | ||
description: vehicle state | ||
unit: vehicle state | ||
enum_types: | ||
|
@@ -35,7 +35,7 @@ channels: | |
|
||
gpio_channel: &gpio_channel | ||
name: gpio | ||
data_type: CHANNEL_DATA_TYPE_BIT_FIELD | ||
data_type: bit_field | ||
description: on/off values for pins on gpio | ||
bit_field_elements: | ||
- name: 12v | ||
|
@@ -51,6 +51,37 @@ channels: | |
index: 7 | ||
bit_count: 1 | ||
|
||
rules: | ||
- name: overheating | ||
description: Checks for vehicle overheating | ||
expression: $1 == "Accelerating" && $2 > 80 | ||
channel_references: | ||
- $1: *vehicle_state_channel | ||
- $2: *voltage_channel | ||
type: review | ||
|
||
- name: speeding | ||
description: Checks high vehicle speed | ||
type: phase | ||
expression: $1 > 20 | ||
channel_references: | ||
- $1: *velocity_channel | ||
|
||
- name: failures | ||
description: Checks for failure logs | ||
type: review | ||
assignee: [email protected] | ||
expression: | ||
name: log_substring_contains | ||
channel_references: | ||
- $1: *log_channel | ||
sub_expressions: | ||
- $2: ERROR | ||
tags: | ||
- foo | ||
- bar | ||
- baz | ||
|
||
flows: | ||
- name: readings | ||
channels: | ||
|
@@ -67,3 +98,4 @@ flows: | |
- name: logs | ||
channels: | ||
- <<: *log_channel | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
""" | ||
INTERNAL MODULE | ||
Everything inside of this module is not meant to be used publicly. Proceed at your own risk. | ||
Everything inside of this module is not meant to be used publicly. | ||
""" |
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,24 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from abc import ABC, abstractmethod | ||
from typing import Any | ||
|
||
|
||
class AsJson(ABC): | ||
""" | ||
Utility sub-types that require custom-serialization meant to be used in conjunction with the | ||
`to_json` function. Sub-types should implement `as_json` which should return the object that | ||
you want passed to `json.dumps`. | ||
""" | ||
|
||
@abstractmethod | ||
def as_json(self) -> Any: | ||
pass | ||
|
||
|
||
def to_json(value: Any) -> str: | ||
""" | ||
Serializes `value` to a JSON string uses the `AsJson.as_json` implementation of the type. | ||
""" | ||
return json.dumps(value, default=lambda x: x.as_json()) |
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 |
---|---|---|
@@ -1,35 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import Generic, Type, TypeVar | ||
|
||
from google.protobuf.message import Message | ||
from typing import cast, Optional, Type, TypeVar | ||
|
||
ProtobufMessage = Message | ||
|
||
T = TypeVar("T", bound=ProtobufMessage) | ||
|
||
|
||
class AsProtobuf(ABC): | ||
class AsProtobuf(ABC, Generic[T]): | ||
""" | ||
Abstract base class used to create create sub-types that can be treated | ||
as an object that can be converted into an instance of `ProtobufMessage`. | ||
If there are multiple possible protobuf targets then `as_pb` may be overloaded. | ||
""" | ||
|
||
@abstractmethod | ||
def as_pb(self, klass: Type[ProtobufMessage]) -> Optional[ProtobufMessage]: | ||
def as_pb(self, klass: Type[T]) -> T: | ||
""" | ||
Performs the conversion into a sub-type of `ProtobufMessage`. Should return `None` | ||
if conversion fails. | ||
Performs the conversion into a sub-type of `ProtobufMessage`. | ||
""" | ||
pass | ||
|
||
|
||
T = TypeVar("T", bound=ProtobufMessage) | ||
|
||
|
||
def try_cast_pb(value: AsProtobuf, target_klass: Type[T]) -> T: | ||
""" | ||
Tries to cast the `value` to `target_klass`, otherwise, returns a `TypeError`. | ||
""" | ||
value_pb = value.as_pb(target_klass) | ||
if isinstance(value_pb, target_klass): | ||
return cast(target_klass, value_pb) | ||
raise TypeError( | ||
f"Expected a '{target_klass.__module__}{target_klass.__name__}' but got {value.__module__}{value.__class__.__name__}" | ||
) | ||
@classmethod | ||
@abstractmethod | ||
def from_pb(cls, message: Type[T]) -> T: | ||
""" | ||
Converts a protobuf object to the type of the sub-class class. | ||
""" | ||
pass |
File renamed without changes.
Oops, something went wrong.