diff --git a/cloud_functions/big_query.py b/cloud_functions/big_query.py index 58d6a259..2c99624f 100644 --- a/cloud_functions/big_query.py +++ b/cloud_functions/big_query.py @@ -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: diff --git a/data_gateway/configuration.py b/data_gateway/configuration.py index e770130c..06dd7eda 100644 --- a/data_gateway/configuration.py +++ b/data_gateway/configuration.py @@ -1,7 +1,5 @@ import copy -from data_gateway.exceptions import WrongNumberOfSensorCoordinatesError - BASE_STATION_ID = "base-station" @@ -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: @@ -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 @@ -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() @@ -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 diff --git a/data_gateway/dummy_serial/dummy_serial.py b/data_gateway/dummy_serial/dummy_serial.py index adecd2e3..7c53b775 100755 --- a/data_gateway/dummy_serial/dummy_serial.py +++ b/data_gateway/dummy_serial/dummy_serial.py @@ -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") @@ -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] diff --git a/data_gateway/exceptions.py b/data_gateway/exceptions.py index 99bb2012..98fe44ef 100644 --- a/data_gateway/exceptions.py +++ b/data_gateway/exceptions.py @@ -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.""" diff --git a/docs/source/usage/configuration_files.rst b/docs/source/usage/configuration_files.rst index 797f1f10..744567ec 100644 --- a/docs/source/usage/configuration_files.rst +++ b/docs/source/usage/configuration_files.rst @@ -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", @@ -330,4 +207,3 @@ Here is an example of a more extensive configuration file. "description": null } } - diff --git a/pyproject.toml b/pyproject.toml index a6e0f9d5..d4feee3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/test_cloud_functions/test_main.py b/tests/test_cloud_functions/test_main.py index 883a7ed3..7be92ab0 100644 --- a/tests/test_cloud_functions/test_main.py +++ b/tests/test_cloud_functions/test_main.py @@ -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"}, } ) @@ -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"}, } ) @@ -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"}, } ) diff --git a/tests/valid_configuration.json b/tests/valid_configuration.json index ed87da87..1a4691ce 100644 --- a/tests/valid_configuration.json +++ b/tests/valid_configuration.json @@ -221,136 +221,13 @@ "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",