TABLE SETUP:
ALARM_T | DEVICE_ID | ALARM_ID | |||
BEHAVIOR_CHARACTERISTICS_T | CHARACTERISTIC_ID | CHARACTERISTIC_NAME | CHARACTERISTIC_TYPE | ||
BEHAVIOR_NAME_T | BEHAVIOR_ID | BEHAVIOR_NAME | |||
BEHAVIOR_SET_T | BEHAVIOR_SET_ID | BEHAVIOR_TYPE_ID | BEHAVIOR_SET_NAME | ||
BEHAVIOR_T | BEHAVIOR_TYPE_ID | BEHAVIOR_CHARACTERISTIC | BEHAVIOR_ID | ||
BEHAVIOR_SET_NAME_T | BEHAVIOR_SET_ID | SEHAVIOR_SET_NAME | |||
DEVICE_SYSTEM_T | DEVICE_ID | SYSTEM_ID | |||
DEVICE_T | DEVICE_ID | DEVICE_NAME | LOCATION | BEHAVIOR_SET_ID | DESCRIPTION |
DEVICE_ZONE_T | DEVICE_ID | ZONE_ID | |||
SENSOR_READING_T | DEVICE_ID | SENSOR_ID | READING | ||
STATUS_T | DEVICE_ID | STATUS_ID | |||
SYSTEM_T | SYSTEM_ID | PARENT_ID | NAME | ||
USERS_T | FIRST_NAME | LAST_NAME | USER_TYPE | PASSWORD | USER_ID |
ZONE_SYSTEM_T | ZONE_ID | SYSTEM_ID | |||
ZONE_T | ZONE_ID | ZONE_NAME |
VIEW SETUP:
BEHAVIOR_CHARACTERISTICS_V | BEHVIOR_ID | CHARACTERISTIC_ID | CHARACTERISTIC_NAME | BEHAVIOR_NAME | CHARACTERISTIC_TYPE |
BEHAVIOR_V | BEHAVIOR_SET_ID | BEHAVIOR_SET_NAME | BEHAVIOR_ID | BEHAVIOR_NAME | |
DEVICE_SYSTEM_V | DEVICE_ID | SYSTEM_ID | DEVICE_NAME | ||
DEVICE_ZONE_V | DEVICE_ID | ZONE_ID | DEVICE_NAME | ||
ZONE_SYSTEM_V | ZONE_ID | SYSTEM_ID | SYSTEM_NAME | ||
BEHAVIOR_CONSTRAINTS_V | DEVICE_ID | CHARACTERISTIC_ID |
TABLE CONSTRAINTS:
ALARM_T:
DEVICE_ID | INTEGER | Foreign Key (DEVICE_T) |
ALARM_ID | INTEGER | Foreign Key (BEHAVIOR_CHARACTERISTICS_T) |
BEHAVIOR_CHARACTERISTICS_T:
CHARACTERISTIC_ID | INTEGER | Foreign Key (DEVICE_T) |
CHARACTERISTIC_NAME | VARCHAR (16) | |
CHARACTERISTIC_TYPE | INTEGER |
BEHAVIOR_NAME_T:
BEHAVIOR_ID | INTEGER | Primary Key |
BEHAVIOR_NAME | VARCHAR (16) |
BEHAVIOR_SET_T:
BEHAVIOR_SET_ID | INTEGER | Primary Key |
BEHAVIOR_TYPE_ID | INTEGER | Foreign Key (BEHAVIOR_T) |
BEHAVIOR_T:
BEHAVIOR_TYPE_ID | INTEGER | Primary Key |
BEHAVIOR_CHARACTERISTIC | INTEGER | |
BEHAVIOR_ID | INTEGER | Foreign Key (BEHAVIOR_NAME_T) |
BEHAVIOR_SET_NAME_T:
BEHAVIOR_SET_ID | INTEGER | Foreign Key (BEHAVIOR_SET_T) |
BEHAVIOR_SET_NAME | VARCHAR (50) |
DEVICE_SYSTEM_T:
DEVICE_ID | INTEGER | Foreign Key (DEVICE_T) |
SYSTEM_ID | INTEGER | Foreign Key (SYSTEM_T) |
DEVICE_T:
DEVICE_ID | INTEGER | Primary Key |
DEVICE_NAME | VARCHAR (50) | |
LOCATION | VARCHAR (50) | |
BEHAVIOR_SET_ID | INTEGER | Foreign Key (BEHAVIOR_SET_T) |
DEVICE_ZONE_T:
DEVICE_ID | INTEGER | Foreign Key (DEVICE_T) |
ZONE_ID | INTEGER | Foreign Key (ZONE_T) |
SENSOR_READING_T:
DEVICE_ID | INTEGER | Foreign Key (DEVICE_T) |
SENSOR_ID | INTEGER | Foreign Key (SENSOR_READING_CONSTANTS_T) |
READING | FLOAT |
STATUS_T:
DEVICE_ID | INTEGER | Foreign Key (DEVICE_T) |
STATUS_ID | INTEGER | Foreign Key (BEHAVIOR_CHARACTERISTICS_T) |
SYSTEM_T:
SYSTEM_ID | INTEGER | Primary Key |
PARENT | INTEGER | |
NAME | VARCHAR (50) |
USERS_T:
FIRST_NAME | VARCHAR (50) | |
LAST_NAME | VARCHAR (50) | |
USER_ID | VARCHAR (10) | Primary Key |
USER_TYPE | INTEGER | |
PASSWORD | VARCHAR (10) |
ZONE_SYSTEM_T:
ZONE_ID | INTEGER | Foreign Key (ZONE_T) |
SYSTEM_ID | INTEGER | Foreign Key (SYSTEM_T) |
ZONE_T:
ZONE_ID | INTEGER | Primary Key |
ZONE_NAME | VARCHAR (50) |
Database Design Description
Behavior Characteristics are broken down into three categories: Sensor (type 0), Alarm (type 1), and Status (type 2). All of these characteristics have a characteristic ID, name, and type. In the Behavior Characteristics Table, an example sensor would be [ 1 , "Air Temperature" , 0 ]. An example alarm would be [ 2 , "Low Power" , 1 ]. Of course, an example status would be [ 3 , "On" , 2 ]. Each type of characteristic is stored in it's own table. Storing the three different characteristic types in three different tables makes look up more efficient, which is important. For example, it makes attaining all devices currently in alarm state very fast (select * from ALARM_T).
The alarm table and status table are the same in that a device is in a given status/alarm or it isn't. Sensors are a bit different, because you have to know both what is being sensed (air temp) and what the value is ( 73 degrees). In breaking down devices behaviors into these components, advanced devices can be easily added in the future.
Devices are stored in a Device Table, each containing a unique Device ID. Further, each device has a name field, a location field, and a map to a Behavior Set ID, defining the devices various behaviors. Devices can be members of Systems and Zones. If a device is a member of a system, its device ID is stored in the Device System Table. Similairly, if a device is a member of a zone, its device ID is stored with the corresponding Zone ID in the Device Zone Table. Devices can also be "Standalone" devices. Systems are groups of devices which work together throughout the ship. Systems are stored in the System Table, each having a unique System ID, as well as a Parent ID, which, if the system is standalone, has a value of "0". An example of a system is the Air Conditioning System. Systems can be members of other systems, or they can be members of zones. Zones differ from systems in that zones are physical sections of a ship. Systems may be members of multiple zones, or multiple other systems. The systems in each zone are kept in a Zone System Table, which holds the zone ID and the corresponding system ID for the system belonging to the zone.
Finally, a User Table is kept which maintains information about registered users in the system, such as their name, their unique User ID, what type of user they are, used to determine the level of security access they have, and the user's login password. A security model may be implemented by future groups on this project.
We created several Views as well in SQL which enabled us to use the data in existing tables to create "virtual tables" with special data groupings.
A behavior may contain characteristics “on” and “off”.A device that can assume this behavior should be able to be “on” or “off” but not both at the same time.We were going to go about this by making views and putting constraints on the tables SENSOR_T, STATUS_T, and ALARM_T based of this view.You could make a view that had the device ID and its behavior Ids and characteristic ids.That would have worked out very nice, but we couldn’t figure out how to but a foreign key constraint on a table that mapped to a view.
Also we were never clear on how these devices will be putting information into this database.Will it be by the Device ID that our database assigns them, or by some special ID that each device has?We assumed it was by the device ID we assigned them.Alternatively, another field in the Device_T (serial #?) could be used to store device readings/statuses/alarms.
Database SQL Code
UI Code