Skip to content

Commit

Permalink
MRG: Merge pull request #125 from aerosense-ai/feature/add-support-fo…
Browse files Browse the repository at this point in the history
…r-sensor-coordinates-table

Add support for sensor coordinates table
  • Loading branch information
cortadocodes committed May 31, 2023
2 parents 9497a30 + 2f0d677 commit 18801c3
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 294 deletions.
3 changes: 2 additions & 1 deletion cloud_functions/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def add_sensor_data(self, data, node_id, configuration_id, installation_referenc
batches = [rows[i : i + INSERT_BATCH_SIZE] for i in range(0, len(rows), INSERT_BATCH_SIZE)]
for batch in batches:
errors = self.client.insert_rows(
table=self.client.get_table(self.table_names["sensor_data"]), rows=batch
table=self.client.get_table(self.table_names["sensor_data"]),
rows=batch,
)

if errors:
Expand Down
23 changes: 2 additions & 21 deletions data_gateway/configuration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import copy

from data_gateway.exceptions import WrongNumberOfSensorCoordinatesError


BASE_STATION_ID = "base-station"

Expand Down Expand Up @@ -214,7 +212,7 @@ class NodeConfiguration:
:param dict|None samples_per_packet: A map for each sensor, giving the number of samples sent in a packet from that sensor
:param dict|None sensor_commands:
:param dict|None sensor_conversion_constants:
:param dict|None sensor_coordinates:
:param dict sensor_coordinates: a mapping of sensor name to sensor coordinates reference
:param list|None sensor_names: List of sensors present on the measurement node
:param dict|None sleep_state:
:return None:
Expand Down Expand Up @@ -268,6 +266,7 @@ def __init__(
self.mics_bm = mics_bm
self.mics_freq = mics_freq
self.node_firmware_version = node_firmware_version
self.sensor_coordinates = sensor_coordinates

# Set default dictionaries
self.decline_reason = decline_reason or DEFAULT_DECLINE_REASONS
Expand All @@ -280,18 +279,6 @@ def __init__(
self.sensor_names = sensor_names or DEFAULT_SENSOR_NAMES
self.sleep_state = sleep_state or DEFAULT_SLEEP_STATES

# Set calculated defaults
self.sensor_coordinates = sensor_coordinates or self._get_default_sensor_coordinates()

for sensor, coordinates in self.sensor_coordinates.items():
number_of_sensors = self.number_of_sensors[sensor]

if len(coordinates) != number_of_sensors:
raise WrongNumberOfSensorCoordinatesError(
f"The number of sensors for the {sensor!r} sensor type is {number_of_sensors} but coordinates "
f"were only given for {len(coordinates)} sensors. Coordinates must be given for every sensor."
)

# Ensure conversion constants are consistent
self._expand_sensor_conversion_constants()

Expand Down Expand Up @@ -324,12 +311,6 @@ def to_dict(self):
"""
return {**vars(self), "periods": self.periods}

def _get_default_sensor_coordinates(self):
return {
sensor_name: [(0, 0, 0)] * number_of_sensors
for sensor_name, number_of_sensors in self.number_of_sensors.items()
}

def _check(self):
"""Serialise self to JSON then make sure it matches a schema"""
# NOT IMPLEMENTED YET
Expand Down
7 changes: 6 additions & 1 deletion data_gateway/dummy_serial/dummy_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def set_buffer_size(self, rx_size=4096, tx_size=None):
"""
pass

def reset_input_buffer(self):
pass

def reset_output_buffer(self):
pass

def open(self):
"""Open the dummy serial port"""
logger.debug("Opening port")
Expand Down Expand Up @@ -163,7 +169,6 @@ def in_waiting(self):
return len(self._waiting_data)

def _check_response(self, data_in):

data_out = constants.NO_DATA_PRESENT
if data_in in self.responses:
data_out = self.responses[data_in]
Expand Down
6 changes: 0 additions & 6 deletions data_gateway/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,5 @@ class UnknownSensorNameError(GatewayError, ValueError):
"""Raise if an unknown sensor name is used."""


class WrongNumberOfSensorCoordinatesError(GatewayError, ValueError):
"""Raise if the number of sensor coordinates given for a sensor does not equal the number of sensors specified in
the `number_of_sensors` configuration field.
"""


class DataMustBeSavedError(GatewayError, ValueError):
"""Raise if options are given to the packet reader that mean no data will be saved locally or uploaded to the cloud."""
138 changes: 7 additions & 131 deletions docs/source/usage/configuration_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,136 +176,13 @@ Here is an example of a more extensive configuration file.
"battery_info": [1e6, 100, 256]
},
"sensor_coordinates": {
"Mics": [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
"Baros_P": [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
"Baros_T": [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
"Diff_Baros": [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
"Acc": [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
"Gyro": [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
"Mag": [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
"Analog Vbat": [[0, 0, 0]],
"Constat": [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
"battery_info": [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
"Mics": "mics_coordinate_reference",
"Baros_P": "baros_coordinate_reference",
"Baros_T": "baros_coordinate_reference",
"Diff_Baros": "baros_coordinate_reference",
"Acc": "accelerometers_coordinate_reference",
"Gyro": "gyroscopes_coordinate_reference",
"Mag": "magnetometers_coordinate_reference"
},
"sensor_names": [
"Mics",
Expand All @@ -330,4 +207,3 @@ Here is an example of a more extensive configuration file.
"description": null
}
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "data-gateway"
version = "0.16.4"
version = "0.16.3"
repository = "https://github.com/aerosense-ai/data-gateway"
description = "A data gateway that runs on-nacelle for relaying data streams from aerosense nodes to cloud."
readme = "README.md"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cloud_functions/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def test_error_raised_if_installation_reference_already_exists(self):
"reference": "hello",
"receiver_firmware_version": "0.0.1",
"turbine_id": "0",
"sensor_coordinates": {"blah_sensor": [[0, 0, 0]]},
"sensor_coordinates": {"blah_sensor": "coordinate_reference"},
}
)

Expand All @@ -408,7 +408,7 @@ def test_error_raised_if_internal_server_error_occurs(self):
"reference": "hello",
"receiver_firmware_version": "0.0.1",
"turbine_id": "0",
"sensor_coordinates": {"blah_sensor": [[0, 0, 0]]},
"sensor_coordinates": {"blah_sensor": "coordinate_reference"},
}
)

Expand Down Expand Up @@ -444,7 +444,7 @@ def test_create_installation_with_only_required_inputs(self):
"reference": "hello",
"receiver_firmware_version": "0.0.1",
"turbine_id": "0",
"sensor_coordinates": {"blah_sensor": [[0, 0, 0]]},
"sensor_coordinates": {"blah_sensor": "coordinate_reference"},
}
)

Expand Down
Loading

0 comments on commit 18801c3

Please sign in to comment.