diff --git a/.gitignore b/.gitignore index a3f83a6..aa44fc8 100644 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,4 @@ ENV/ # mypy .mypy_cache/ /python_driver/cal_data.db +/.pytest_cache diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..762b479 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "python.unitTest.promptToConfigure": false, + "python.unitTest.pyTestEnabled": false, + "python.unitTest.unittestEnabled": false, + "python.unitTest.nosetestsEnabled": false +} \ No newline at end of file diff --git a/html_templates/Scaling.html b/html_templates/Scaling.html index 4cfa93a..29edcf0 100644 --- a/html_templates/Scaling.html +++ b/html_templates/Scaling.html @@ -105,6 +105,31 @@ +
+
+

Level Offset (Ft.)

+
+
+ +
+ " + data-techname="<%=channels["pondlevel.setleveloffset"].techName %>" + data-name="<%= channels["pondlevel.setleveloffset"].name%>" + data-nodechannelcurrentId="<%= channels["pondlevel.setleveloffset"].nodechannelcurrentId %>" + id="<%= channels["pondlevel.setleveloffset"].channelId %>" + class="btn btn-large btn-theme animated setstatic material-icons">send +
+
+
+
diff --git a/python-driver/cal_data.db b/python-driver/cal_data.db new file mode 100644 index 0000000..b51c3d2 Binary files /dev/null and b/python-driver/cal_data.db differ diff --git a/python_driver/calibration_db.py b/python-driver/calibration_db.py similarity index 100% rename from python_driver/calibration_db.py rename to python-driver/calibration_db.py diff --git a/python_driver/channels_pondlevel.csv b/python-driver/channels_pondlevel.csv similarity index 100% rename from python_driver/channels_pondlevel.csv rename to python-driver/channels_pondlevel.csv diff --git a/python_driver/config.txt b/python-driver/config.txt similarity index 91% rename from python_driver/config.txt rename to python-driver/config.txt index 9bae922..5ae14e0 100644 --- a/python_driver/config.txt +++ b/python-driver/config.txt @@ -2,7 +2,7 @@ "driverFileName": "pondlevel.py", "deviceName": "pondlevel", "driverId": "0130", - "releaseVersion": "4", + "releaseVersion": "5", "files": { "file1": "pondlevel.py", "file2": "calibration_db.py", diff --git a/python_driver/device_base.py b/python-driver/device_base.py similarity index 100% rename from python_driver/device_base.py rename to python-driver/device_base.py diff --git a/python_driver/driverConfig.json b/python-driver/driverConfig.json similarity index 93% rename from python_driver/driverConfig.json rename to python-driver/driverConfig.json index 8f03a70..b9b174f 100644 --- a/python_driver/driverConfig.json +++ b/python-driver/driverConfig.json @@ -8,6 +8,6 @@ "utilities.py", "file_logger.py" ], - "version": 4, + "version": 5, "s3BucketName": "pondlevel" } \ No newline at end of file diff --git a/python_driver/file_logger.py b/python-driver/file_logger.py similarity index 100% rename from python_driver/file_logger.py rename to python-driver/file_logger.py diff --git a/python_driver/level_testing.py b/python-driver/level_testing.py similarity index 100% rename from python_driver/level_testing.py rename to python-driver/level_testing.py diff --git a/python_driver/persistence.py b/python-driver/persistence.py similarity index 100% rename from python_driver/persistence.py rename to python-driver/persistence.py diff --git a/python_driver/pondlevel.py b/python-driver/pondlevel.py similarity index 95% rename from python_driver/pondlevel.py rename to python-driver/pondlevel.py index ef807fe..018a8d1 100644 --- a/python_driver/pondlevel.py +++ b/python-driver/pondlevel.py @@ -30,12 +30,12 @@ scaling_persist = persistence.load(filename="scaling_persist.json") strapping_persist = persistence.load(filename="strapping_persist.json") -def scale_to_eu(inp_measurement, raw_max, raw_min, eu_max, eu_min): +def scale_to_eu(inp_measurement, raw_max, raw_min, eu_max, eu_min, offset=0.0): """Scale the inp_measurement to engineering units.""" m = (eu_max - eu_min) / (raw_max - raw_min) b = eu_max - raw_max * m scaled = inp_measurement * m + b - return scaled + return scaled + offset class start(threading.Thread, deviceBase): @@ -47,7 +47,7 @@ class start(threading.Thread, deviceBase): deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes) self.daemon = True - self.version = "4" + self.version = "5" self.finished = threading.Event() self.forceSend = False threading.Thread.start(self) @@ -59,6 +59,7 @@ class start(threading.Thread, deviceBase): self.PL_RAWMIN = 4.0 self.PL_EUMAX = 23.068 self.PL_EUMIN = 0.0 + self.PL_OFFSET = 0.0 self.PSI_RAWMAX = 10.0 self.PSI_RAWMIN = 0.0 @@ -67,10 +68,10 @@ class start(threading.Thread, deviceBase): # Strapping table format # { - # height: volume, - # height: volume, - # height: volume, - # etc... + # height: volume, + # height: volume, + # height: volume, + # etc... # } self.strapping_table = {} @@ -89,6 +90,7 @@ class start(threading.Thread, deviceBase): self.PL_RAWMIN = scaling_persist['raw_min'] self.PL_EUMAX = scaling_persist['eu_max'] self.PL_EUMIN = scaling_persist['eu_min'] + self.PL_OFFSET = scaling_persist['eu_offset'] except KeyError: log.warning("No persistence data for pond level scaling parameters.") except TypeError: @@ -127,6 +129,7 @@ class start(threading.Thread, deviceBase): self.sendtodb("setrawmin", self.PL_RAWMIN, 0) self.sendtodb("seteumax", self.PL_EUMAX, 0) self.sendtodb("seteumin", self.PL_EUMIN, 0) + self.sendtodb("setleveloffset", self.PL_OFFSET, 0) self.sendtodb("setpsirawmax", self.PSI_RAWMAX, 0) self.sendtodb("setpsirawmin", self.PSI_RAWMIN, 0) @@ -148,7 +151,7 @@ class start(threading.Thread, deviceBase): mcu_status = self.mcu.getDict() # Gets a dictionary of the IO states cloop_val = float(mcu_status['cloop']) analog1_val = float(mcu_status['analog1']) - temp_pl = scale_to_eu(cloop_val, self.PL_RAWMAX, self.PL_RAWMIN, self.PL_EUMAX, self.PL_EUMIN) + temp_pl = scale_to_eu(cloop_val, self.PL_RAWMAX, self.PL_RAWMIN, self.PL_EUMAX, self.PL_EUMIN, offset=self.PL_OFFSET) temp_psi = scale_to_eu(analog1_val, self.PSI_RAWMAX, self.PSI_RAWMIN, self.PSI_EUMAX, self.PSI_EUMIN) except AttributeError as err: log.error("Could not connect to MCU object, this device might not have an MCU: {}".format(err)) @@ -333,6 +336,13 @@ class start(threading.Thread, deviceBase): self.store_scaling_data() return(True) + def pondlevel_setleveloffset(self, name, value): + """Set the Pond level offset scaling value.""" + self.PL_OFFSET = float(value) + self.sendtodb("setleveloffset", self.PL_OFFSET, 0) + self.store_scaling_data() + return(True) + def pondlevel_setpsirawmin(self, name, value): """Set the raw min pressure scaling value.""" self.PSI_RAWMIN = float(value) diff --git a/python_driver/test.py b/python-driver/test.py similarity index 100% rename from python_driver/test.py rename to python-driver/test.py diff --git a/python_driver/utilities.py b/python-driver/utilities.py similarity index 100% rename from python_driver/utilities.py rename to python-driver/utilities.py