Domain model
Study protocols, triggers, tasks, measures, devices and measurements in the CAMS domain model.
The carp_mobile_sensing library uses and extends the carp_core domain model. The CAMS domain model has two parts:
- The
carp_coredomain model, a Dart implementation of the overall CARP Core Domain Model. - The
carp_mobile_sensingdomain model.
This page covers the parts of the CARP domain models that CAMS uses: the domain classes related to a study protocol, data transformers, sampling configurations and collected measurements. Sampling produces Measurement streams with typed Data payloads.
Defining a study protocol
Data collection is configured as a StudyProtocol. A study protocol is always executed by one or more primary devices (for example a smartphone) and can use a set of connected devices (for example a heart rate monitor).
A study protocol holds a set of triggers. Each trigger can trigger one or more tasks, and each task holds a set of measures to collect. A measure can be configured with a sampling configuration.
| Element | Configures | Example |
|---|---|---|
| Trigger | When to collect data | Every hour |
| Task | How to collect data | Which device to use |
| Measure | What to collect | Location |
Study protocol
A StudyProtocol holds the entire definition of the study, including the owner and name of the study, where to store the data, and which primary device is responsible for data collection.
See Data managers for the available data managers and endpoints.
Tip
To describe a protocol and the nature of a study in more detail, specify a StudyDescription. It includes the study purpose, homepage, privacy and responsible researcher.
Triggers
Triggers are configured through a TriggerConfiguration and define the temporal configuration of a study, that is, when data sampling is done. CAMS includes these triggers:
| Trigger | Description |
|---|---|
ImmediateTrigger | Starts sampling immediately. |
OneTimeTrigger | Triggers only once during a deployment. |
DelayedTrigger | Delays sampling for the specified delay, measured from sensing start. |
ElapsedTimeTrigger | Delays sampling for the specified delay, measured from study deployment start. |
PassiveTrigger | Started manually with resume and paused with pause. |
PeriodicTrigger | Runs periodically with a fixed period. |
DateTimeTrigger | Schedules sampling at a specific date and time. |
RecurrentScheduledTrigger | Schedules sampling with a recurrent date/time pattern. |
CronScheduledTrigger | Resumes and pauses sampling based on a cron expression. |
SamplingEventTrigger | Starts when a sampling event occurs, for example entering a geofence. |
ConditionalSamplingEventTrigger | Resumes or pauses based on the result of a Dart function. |
ConditionalPeriodicTrigger | Periodically checks whether an app-specific condition is met. |
RandomRecurrentTrigger | Triggers a random number of times within a defined daily period. |
UserTaskTrigger | Triggers based on the state of a UserTask. |
NoUserTaskTrigger | Triggers when a certain user task is not on the task list. |
AppLifecycleTrigger | Triggers when the life cycle of the app changes, as defined in AppLifecycleState. |
To add your own triggers, see Adding new triggers.
Tasks and task controls
A task is defined through a TaskConfiguration and configures which measures to collect. For example, a task can sample accelerometer and gyroscope measures from the smartphone during a tremor assessment, or heart rate and ECG data from a wearable device.
CAMS has two basic types of tasks:
| Task | Type | Description |
|---|---|---|
BackgroundTask | Passive sensing | Starts collecting data as specified in its measures when the task is resumed. Used for background mobile sensing that does not involve the user. |
AppTask | Active user task | Involves the app, and potentially the user, in data sampling. Notifies the app when resumed or paused. For example, if a PeriodicTrigger resumes an AppTask with a survey measure, the survey is handed over to the app whenever the trigger resumes. See the app task model. |
A TaskControl configures how to collect data and links a trigger, a task and a device. A task control controls (starts or stops) when a task is triggered on a device.
Measures
A Measure defines what to measure. It specifies the type of data to collect, which at runtime maps to a specific probe that can collect this type of data. See Measure types for the available types.
CAMS follows a reactive programming model: all sampled data is collected in streams by listening to the underlying sensors. This is configured with the Measure class. Some probes, however, need to poll data and must be configured with a sampling frequency. For example, the MemoryProbe needs a sampling frequency, set with an IntervalSamplingConfiguration in the sampling schema.
Most CAMS users do not need this low-level configuration. It is handled through a SamplingConfiguration and the default sampling schemas, described in Sampling configurations and schemas.
Sampling configurations and schemas
CAMS includes default sampling configurations for all measures. These are collected in DataTypeSamplingScheme schemas for each sampling package. For example, the SensorSamplingPackage provides a map of default samplingSchemes for its measures.
To change a default configuration, override it with the overrideSamplingConfiguration property of a measure. For example, the default configuration of the light measure is 10 seconds of sampling every 5 minutes:
Devices
Devices are configured in the study protocol. The CAMS domain model has two types of devices:
- Primary devices aggregate, synchronize and optionally upload incoming data received from one or more connected devices (potentially just itself). In CAMS, the smartphone is typically the primary device.
- Connected devices are any devices connected to a primary device, such as a wearable heart rate monitor.
CAMS and its sampling packages include predefined device descriptors, such as the Smartphone primary device descriptor or the PolarDevice device descriptor in the Polar sampling package.
A study protocol that uses a Polar device as a connected device of the phone:
As a wearable device, the Polar device is a connected device, connected to the phone as the primary device.
Note
Connected devices must connect to the phone (for example over BLE) at runtime before data can be collected from them. The DeviceController handles this.
Protocol examples
A study protocol is a list of triggers and tasks with a set of measures:
Measurements and data
CAMS models data according to the data subsystem of the CARP Core domain model. Data collected during sampling is modeled as a Measurement, which holds a Data object of a specific DataType.
In CAMS, all data objects are of type Data. For example, BatteryState holds the state of the phone's battery, such as battery level and charging status. A data object is measured either at a point in time or over a time span.
All measurement and data objects can be serialized to and from JSON:
sensorStartTime is the timestamp of the measurement in microseconds, and __type holds the data type.
Ambient light is measured over a time period, so both sensorStartTime and sensorEndTime are specified.
Timestamps
- CARP recommends microseconds (over milliseconds) since epoch. This gives greater precision, especially in high-frequency sampling.
- Sensor timestamps (start and end time) are provided by the sensor, if available. Depending on the unit of the sensor timestamp, the phone may translate it to microseconds before storing it in a measurement.
- If the sensor does not provide a timestamp, the phone time-stamps the data through the
Measurement.fromDatamethod. - A
Dataobject may itself contain time information, modeled with the DartDateTimeformat; see for example thedateFromproperties inHealthDatain the health package. These timestamps use Zulu (UTC) format, such as2023-11-15T22:00:25.864650Z.