-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define schema for sensor data table #112
Comments
@lidderupk @mrodrise - table definitions for the sensor log and analytics output... Key points:
CREATE TABLE `firefighter_status_analytics` (
`timestamp_mins` timestamp NOT NULL,
`firefighter_id` VARCHAR(20) NOT NULL,
`device_id` VARCHAR(20) DEFAULT NULL,
`device_battery_level` FLOAT DEFAULT NULL,
`temperature` SMALLINT DEFAULT NULL,
`humidity` SMALLINT DEFAULT NULL,
`device_timestamp` timestamp DEFAULT NULL,
`device_status_LED` SMALLINT DEFAULT NULL,
`analytics_status_LED` SMALLINT DEFAULT NULL,
`carbon_monoxide` FLOAT DEFAULT NULL,
`carbon_monoxide_twa_10min` FLOAT DEFAULT NULL,
`carbon_monoxide_twa_30min` FLOAT DEFAULT NULL,
`carbon_monoxide_twa_60min` FLOAT DEFAULT NULL,
`carbon_monoxide_twa_240min` FLOAT DEFAULT NULL,
`carbon_monoxide_twa_480min` FLOAT DEFAULT NULL,
`carbon_monoxide_gauge_10min` SMALLINT DEFAULT NULL,
`carbon_monoxide_gauge_30min` SMALLINT DEFAULT NULL,
`carbon_monoxide_gauge_60min` SMALLINT DEFAULT NULL,
`carbon_monoxide_gauge_240min` SMALLINT DEFAULT NULL,
`carbon_monoxide_gauge_480min` SMALLINT DEFAULT NULL,
`nitrogen_dioxide` FLOAT DEFAULT NULL,
`nitrogen_dioxide_twa_10min` FLOAT DEFAULT NULL,
`nitrogen_dioxide_twa_30min` FLOAT DEFAULT NULL,
`nitrogen_dioxide_twa_60min` FLOAT DEFAULT NULL,
`nitrogen_dioxide_twa_240min` FLOAT DEFAULT NULL,
`nitrogen_dioxide_twa_480min` FLOAT DEFAULT NULL,
`nitrogen_dioxide_gauge_10min` SMALLINT DEFAULT NULL,
`nitrogen_dioxide_gauge_30min` SMALLINT DEFAULT NULL,
`nitrogen_dioxide_gauge_60min` SMALLINT DEFAULT NULL,
`nitrogen_dioxide_gauge_240min` SMALLINT DEFAULT NULL,
`nitrogen_dioxide_gauge_480min` SMALLINT DEFAULT NULL,
`formaldehyde` FLOAT DEFAULT NULL,
`formaldehyde_twa_10min` FLOAT DEFAULT NULL,
`formaldehyde_twa_30min` FLOAT DEFAULT NULL,
`formaldehyde_twa_60min` FLOAT DEFAULT NULL,
`formaldehyde_twa_240min` FLOAT DEFAULT NULL,
`formaldehyde_twa_480min` FLOAT DEFAULT NULL,
`formaldehyde_gauge_10min` SMALLINT DEFAULT NULL,
`formaldehyde_gauge_30min` SMALLINT DEFAULT NULL,
`formaldehyde_gauge_60min` SMALLINT DEFAULT NULL,
`formaldehyde_gauge_240min` SMALLINT DEFAULT NULL,
`formaldehyde_gauge_480min` SMALLINT DEFAULT NULL,
`acrolein` FLOAT DEFAULT NULL,
`acrolein_twa_10min` FLOAT DEFAULT NULL,
`acrolein_twa_30min` FLOAT DEFAULT NULL,
`acrolein_twa_60min` FLOAT DEFAULT NULL,
`acrolein_twa_240min` FLOAT DEFAULT NULL,
`acrolein_twa_480min` FLOAT DEFAULT NULL,
`acrolein_gauge_10min` SMALLINT DEFAULT NULL,
`acrolein_gauge_30min` SMALLINT DEFAULT NULL,
`acrolein_gauge_60min` SMALLINT DEFAULT NULL,
`acrolein_gauge_240min` SMALLINT DEFAULT NULL,
`acrolein_gauge_480min` SMALLINT DEFAULT NULL,
`benzene` FLOAT DEFAULT NULL,
`benzene_twa_10min` FLOAT DEFAULT NULL,
`benzene_twa_30min` FLOAT DEFAULT NULL,
`benzene_twa_60min` FLOAT DEFAULT NULL,
`benzene_twa_240min` FLOAT DEFAULT NULL,
`benzene_twa_480min` FLOAT DEFAULT NULL,
`benzene_gauge_10min` SMALLINT DEFAULT NULL,
`benzene_gauge_30min` SMALLINT DEFAULT NULL,
`benzene_gauge_60min` SMALLINT DEFAULT NULL,
`benzene_gauge_240min` SMALLINT DEFAULT NULL,
`benzene_gauge_480min` SMALLINT DEFAULT NULL,
PRIMARY KEY (`timestamp_mins`, `firefighter_id`)
) ENGINE=InnoDB DEFAULT CHARSET= UTF8mb4;
CREATE TABLE `firefighter_sensor_log` (
`timestamp_mins` timestamp NOT NULL,
`firefighter_id` VARCHAR(20) NOT NULL,
`device_id` VARCHAR(20) DEFAULT NULL,
`device_battery_level` FLOAT DEFAULT NULL,
`temperature` SMALLINT DEFAULT NULL,
`humidity` SMALLINT DEFAULT NULL,
`carbon_monoxide` FLOAT DEFAULT NULL,
`nitrogen_dioxide` FLOAT DEFAULT NULL,
`formaldehyde` FLOAT DEFAULT NULL,
`acrolein` FLOAT DEFAULT NULL,
`benzene` FLOAT DEFAULT NULL,
`device_timestamp` timestamp DEFAULT NULL,
`device_status_LED` SMALLINT DEFAULT NULL,
PRIMARY KEY (`timestamp_mins`, `firefighter_id`)
) DEFAULT CHARSET= UTF8mb4; |
Thanks @JSegrave-IBM! Yes, the database and each table should be UTF-8. We may have to dump data and recreate it: CREATE DATABASE IF NOT EXISTS prometeo character set UTF8mb4 collate utf8mb4_unicode_ci; |
Thanks for all, great work. I consider that we should add a field for the device id that is sending the data Maybe we can add fields for the status color that gives the algorithm in that moment, only to have the history We can change the name of the table... I never liked metrics... we can rename to firefighters_status_readings... or whatever... |
Thanks @mrodrise - table name is now 'firefighter_status_analytics' - is that OK? (mix of calculated values and 'cleaned' sensor values - e.g. dropout-refilled, minute-aligned ). Also added 'device_id' and 'device_battery_level' so all the screen display data is in one place. |
Thanks @krook - I presume all the CREATE TABLE statements should have DEFAULT CHARSET=UTF8mb4; in kind? |
@JSegrave-IBM correct. But it may automatically cascade as the default. Looking at another database I have: |
Changes: (FYI - @mrodrise @lidderupk )
|
Normally the
For both @mrodrise - is 80% OK for the default? (it can easily be configured to 75% or any other percentage of an AEGL-2 limit). |
Pull request: Pyrrha-Platform/Pyrrha-Database#3 |
Modified DB field names to make them less sensitive to configuration changes. Fields for the different time-window TWAs are now named the after the number of minutes in that window (stable) and not by the display name (less stable and prone to SQL issues). |
Proposed Schema below.
Key points:
firefighter_sensor_log
where each row is the raw/unmodified sensor readings associated withfirefighter_id
during the minutetimestamp_mins
- we never modify this datafirefighter_status_analytics
- where each row the same data as the sensor log, plus all the analytic information aboutfirefighter_id
during the minutetimestamp_mins
. This is a kind of one-stop-shop for data analysis - everything about the firefighter in one place. Making it a separate table tofirefighter_sensor_log
allows us to keep an untouched record of what was sent. It also removes a few potential contention points between the processes that read and write information.timestamp_mins
,firefighter_id
) - note the ID change from previousSensorID
timestamp_mins
is a minute-quantized timestamp. Important that these keys be minute-quantized - e.g. '10/02/2020 09:40' not '10/02/2020 09:40:34'. Also note the name change - because plain 'ol timestamp is an SQL keyworddevice_timestamp
is the unmodified original device timestamp.device_status_LED
andanalytics_status_LED
(i.e. the LED colors) will be the same, but in a disconnected scenario, they may be different. We're capturing both. Associated values are { 1 = green ; 2 = yellow ; 3 = red } and for this release, 'yellow' is a configurable percentage, currently defaulting to 80% (i.e. any gas reaching 80% of any AEGL-2 time-period limit will cause the LED to go yellow)UTF8mb4;
as per discussion with Dan about internationalization.See Table definition for details below
The text was updated successfully, but these errors were encountered: