Okay, next, we need specify (in yaml) what database table it should look at. The data is in a format right now that’s not accessible (see my screen shot above), so we are going to create a VIEW on top of this table that looks better.
But first, here’s an example. I open up pio db
, and enter the following:
SELECT timestamp, experiment, event_name, pioreactor_unit, data
FROM dosing_automation_events;
I get something like this (your data will look slightly different, but squint you should see the similarity) . The data
column is a JSON representation of the dictionary in Python we talked about above (JSON is just a serialization format):
timestamp |
experiment |
event_name |
pioreactor_unit |
data |
2022-12-09T21:28:32.465374Z |
demoo |
NoEvent |
leader6 |
|
2022-12-09T21:28:58.982423Z |
demoo |
NoEvent |
leader6 |
|
2023-01-04T20:32:32.891195Z |
pwm tests |
NoEvent |
worker1 |
|
2023-01-04T20:35:32.485015Z |
pwm tests |
NoEvent |
worker1 |
|
2023-01-04T20:40:23.109093Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:41:05.931800Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:43:05.824067Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:45:05.694384Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:47:05.945823Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:49:05.622566Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:51:05.792569Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:53:05.851546Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:55:05.709735Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:57:05.614472Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:59:06.747484Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T21:01:05.720854Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T21:03:05.808914Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T21:05:05.519326Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
Let’s apply a WHERE filter to filter out the empty data
rows:
SELECT timestamp, experiment, event_name, pioreactor_unit, data
FROM dosing_automation_events
WHERE data != "";
timestamp |
experiment |
event_name |
pioreactor_unit |
data |
2023-01-04T20:40:23.109093Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:41:05.931800Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:43:05.824067Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:45:05.694384Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:47:05.945823Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:49:05.622566Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:51:05.792569Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:53:05.851546Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:55:05.709735Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:57:05.614472Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T20:59:06.747484Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T21:01:05.720854Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T21:03:05.808914Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T21:05:05.519326Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T21:07:05.883444Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
2023-01-04T21:09:05.822024Z |
pwm tests |
DilutionEvent |
worker1 |
{“volume_actually_cycled”: 0.5} |
Okay, great, but in order for the UI to display the data, we need a single table column of numbers, not this JSON data. We can use the SQL function json_extract
to extract the field we want:
SELECT
timestamp,
experiment,
pioreactor_unit,
event_name,
data,
json_extract(data, '$.volume_actually_cycled') as volume_cycled
FROM dosing_automation_events
WHERE data != "";
timestamp |
experiment |
pioreactor_unit |
event_name |
data |
volume_cycled |
2023-01-04T20:40:23.109093Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T20:41:05.931800Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T20:43:05.824067Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T20:45:05.694384Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T20:47:05.945823Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T20:49:05.622566Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T20:51:05.792569Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T20:53:05.851546Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T20:55:05.709735Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T20:57:05.614472Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T20:59:06.747484Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
2023-01-04T21:01:05.720854Z |
pwm tests |
worker1 |
DilutionEvent |
{“volume_actually_cycled”: 0.5} |
0.5 |
Great! This looks like how we want it. But this isn’t a table, it’s just a result from a query - we need to tell our database to create a permanent VIEW of this query. Let’s call this new VIEW growth_per_intervals
.
CREATE VIEW growth_per_intervals AS
SELECT
timestamp,
experiment,
pioreactor_unit,
event_name,
data,
json_extract(data, '$.volume_actually_cycled') as volume_cycled
FROM dosing_automation_events
WHERE data != "";
Now, I can query this just like a table:
SELECT * FROM growth_per_intervals
Okay, now the yaml file.
- We have the
data_source
now, it’s growth_per_intervals
.
- We have the
column_name
, it’s volume_cycled
-
mqtt_topic
we can’t do, just yet, maybe later.
-
payload_key
is for MQTT, so we’ll skip that for now.
And I think that’s it. Try this out, and let me know if you are stuck somewhere or need more clarification!
There are other ways to get data into SQL in Pioreactor, but this is still the easiest for your context.