Your application must deal with two types of things.
- Sensors = what type, where in the engine and even parameters, such as polling frequency, etc.
- Reads = individual records with time stamps from one (or several?) Sensors.
There are a few things to consider:
- How can we find ways to abstract the concept of the sensor ? The idea is that we could then identify and process sensor instances through their properties, rather than know where they are in the database.
- It is best to store all measurements for a given timestamp in a single βReadβ record or have one record per sensor for reading, even if the set includes several measurements.
A quick answer to the last question is that one-way read-write seems to be more flexible ; in the same way, we can process both groups of dimensions that are systematically polled at the same time, and other dimensions that are asynchronous to the first. Even if right now, all measurements come at once, the ability to simply add sensors without changing the database schema and to process them in the same mode is attractive.
Perhaps the following design will be closer to what you need:
tblSensors
SensorId PK
Name clear text description of the sensor ("Oil Temp.")
LongName longer description ("Oil Temperarure, Sensor TH-B14 in crankshaft")
SensorType enumeration ("TEMP", "PRESSURE", "VELOCITY" ...)
SensorSubType enumeration ("OIL", "AIR" ...)
Location enumeration ("ENGINE", "GENERAL", "EXHAUST" ...)
OtherCrit other crietrias which may be used to identify / seach for the sensor.
tblReads
Readid PK
Datetime
SensorId FK to tblSensors
Measurment INTeger value
Measurement2 optional extra meassurement (maybe to handle say, all
of a GPS sensor read as one "value"
Measurement3 ... also may have multiple columns for different types of
variables (real-valued?)
In addition to the above, you will have several tables where "enumerations" for various types of sensors will be defined, and binding to the application logic will be carried out using mnemonic "keys", these enumerations. eg.
SELECT S.Name, R.DateTime, R.Measurement FROM tblReads R JOIN tblSensors S ON S.SensorId = R.SensorID WHERE S.SensorType IN ('Temp', 'Pres') AND S.Location = "ENG" AND R.DateTime > '04/07/2009' ORDER BY R.DateTime
This will not stop you from also calling sensors by their identifier and grouping the readings in the same line of results. eg.
SELECT R1.DateTime, R1.Measurement AS OilTemp, R2.Measurement AS OilPress, R3.Measurement AS MotorRpms FROM tblReads R1 LEFT OUTER JOIN tblReads R2 ON R1.DateTime = R2.DateTime LEFT OUTER JOIN tblReads R3 ON R1.DateTime = R3.DateTime WHERE R1.SensorId = 17 AND R2.SensorId = 11 AND R3.SensorId = 44 AND R1.DateTime > '04/07/2009' AND R1.DateTime < '04/08/2009' ORDER BY R3.Measurement DESC