|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | from __future__ import annotations |
3 | 3 |
|
4 | | -import json |
5 | 4 | import sqlite3 |
6 | 5 | from time import sleep |
7 | 6 |
|
8 | 7 | import pioreactor.background_jobs.leader.mqtt_to_db_streaming as m2db |
9 | | -import pytest |
10 | 8 | from pioreactor import mureq |
11 | 9 | from pioreactor import structs |
12 | 10 | from pioreactor.automations import temperature # noqa: F401 |
13 | 11 | from pioreactor.background_jobs.base import BackgroundJob |
14 | | -from pioreactor.background_jobs.growth_rate_calculating import GrowthRateCalculator |
15 | | -from pioreactor.background_jobs.od_reading import start_od_reading |
16 | 12 | from pioreactor.config import config |
17 | | -from pioreactor.config import temporary_config_changes |
18 | 13 | from pioreactor.pubsub import collect_all_logs_of_level |
19 | 14 | from pioreactor.pubsub import publish |
20 | | -from pioreactor.utils import local_persistent_storage |
21 | 15 | from pioreactor.utils.timing import current_utc_datetime |
22 | 16 | from pioreactor.whoami import get_testing_experiment_name |
23 | 17 | from pioreactor.whoami import get_unit_name |
@@ -96,7 +90,6 @@ def test_updated_heater_dc() -> None: |
96 | 90 | assert len(results) == 1 |
97 | 91 |
|
98 | 92 |
|
99 | | -@pytest.mark.xfail() |
100 | 93 | def test_dosing_events_land_in_db() -> None: |
101 | 94 | from pioreactor.actions.pump import add_media |
102 | 95 |
|
@@ -153,88 +146,6 @@ def test_dosing_events_land_in_db() -> None: |
153 | 146 | assert len(results) == 2 |
154 | 147 |
|
155 | 148 |
|
156 | | -@pytest.mark.xfail(reason="we stopped adding to kalman filter table in 25.1.x release") |
157 | | -def test_kalman_filter_entries() -> None: |
158 | | - with temporary_config_changes( |
159 | | - config, |
160 | | - [ |
161 | | - ("storage", "database", "test.sqlite"), |
162 | | - ("od_reading.config", "samples_per_second", "0.2"), |
163 | | - ("od_config.photodiode_channel", "1", "135"), |
164 | | - ("od_config.photodiode_channel", "2", "90"), |
165 | | - ], |
166 | | - ): |
167 | | - unit = "unit" |
168 | | - exp = "test_kalman_filter_entries" |
169 | | - |
170 | | - # init the database |
171 | | - connection = sqlite3.connect(config["storage"]["database"]) |
172 | | - cursor = connection.cursor() |
173 | | - |
174 | | - cursor.executescript("DROP TABLE IF EXISTS kalman_filter_outputs;") |
175 | | - cursor.executescript( |
176 | | - mureq.get( |
177 | | - "https://raw.githubusercontent.com/Pioreactor/CustoPiZer/pioreactor/workspace/scripts/files/sql/create_tables.sql" |
178 | | - ).content.decode("utf-8") |
179 | | - ) |
180 | | - connection.commit() |
181 | | - |
182 | | - with local_persistent_storage("od_normalization_mean") as cache: |
183 | | - cache[exp] = json.dumps({"1": 0.5, "2": 0.5}) |
184 | | - |
185 | | - with local_persistent_storage("od_normalization_variance") as cache: |
186 | | - cache[exp] = json.dumps({"1": 1e-6, "2": 1e-4}) |
187 | | - |
188 | | - # turn on our mqtt to db |
189 | | - parsers = [ |
190 | | - m2db.TopicToParserToTable( |
191 | | - "pioreactor/+/+/growth_rate_calculating/kalman_filter_outputs", |
192 | | - m2db.parse_kalman_filter_outputs, |
193 | | - "kalman_filter_outputs", |
194 | | - ) |
195 | | - ] |
196 | | - |
197 | | - # turn on data collection |
198 | | - interval = 0.5 |
199 | | - |
200 | | - with ( |
201 | | - start_od_reading( |
202 | | - {"1": "135", "2": "90"}, |
203 | | - interval=interval, |
204 | | - fake_data=True, |
205 | | - unit=unit, |
206 | | - experiment=exp, |
207 | | - ), |
208 | | - GrowthRateCalculator(unit=unit, experiment=exp), |
209 | | - m2db.MqttToDBStreamer(unit, exp, parsers), |
210 | | - ): |
211 | | - # let data collect |
212 | | - sleep(10) |
213 | | - |
214 | | - cursor.execute("SELECT * FROM kalman_filter_outputs WHERE experiment = ?", (exp,)) |
215 | | - results = cursor.fetchall() |
216 | | - assert len(results) > 0 |
217 | | - |
218 | | - cursor.execute( |
219 | | - "SELECT state_0, state_1, state_2 FROM kalman_filter_outputs WHERE experiment = ? ORDER BY timestamp DESC LIMIT 1", |
220 | | - (exp,), |
221 | | - ) |
222 | | - results = cursor.fetchone() |
223 | | - assert results[0] != 0.0 |
224 | | - assert results[1] != 0.0 |
225 | | - assert results[2] != 0.0 |
226 | | - |
227 | | - cursor.execute( |
228 | | - "SELECT cov_00, cov_11, cov_22 FROM kalman_filter_outputs WHERE experiment = ? ORDER BY timestamp DESC LIMIT 1", |
229 | | - (exp,), |
230 | | - ) |
231 | | - results = cursor.fetchone() |
232 | | - |
233 | | - assert results[0] != 0.0 |
234 | | - assert results[1] != 0.0 |
235 | | - assert results[2] != 0.0 |
236 | | - |
237 | | - |
238 | 149 | def test_empty_payload_is_filtered_early() -> None: |
239 | 150 | unit = "unit" |
240 | 151 | exp = "test_empty_payload_is_filtered_early" |
|
0 commit comments