AIM
|
#include <Task.h>
Public Types | |
enum | MsgType { TASK_START = 0, TASK_COMPLETE, TASK_SUCCESS, TASK_FAIL, TASK_ENCOURAGEMENT, TASK_REMINDER, TASK_STATUS_UNKNOWN } |
Public Types inherited from AIM | |
typedef std::pair< std::string, AIMValue > | AIMData |
typedef std::queue< AIMData > | AIMDataQueue |
typedef std::queue< AIMValue > | AIMValueQueue |
typedef std::map< std::string, AIMValueQueue > | InputDataQueue |
Public Types inherited from CoachingEngine::TaskDescription | |
enum | Status { UNKNOWN, SUCCEEDED, FAILED } |
enum | Type { NONE = 0, BE_ACTIVE, SLEEP, BE_RESILIENT, CALIBRATING, SLEEP_PERIOD_STAY_AWAKE, SLEEP_PERIOD_GO_TO_SLEEP, TAKE_MELATONIN, SLEEPY, UNWINDING, WAKING_UP, ACTIVE, BRIGHT_LIGHT, DIMMED_LIGHT, EXERCISE, TAKE_CAFFEINE, HAVE_BREAKFAST, HAVE_LUNCH, HAVE_DINNER, HAVE_SNACK, EAT_EXTRA_TODAY, FIRST_NIGHT_MELATONIN, FULLY_ADJUSTED, TASK_MR_WORRIES, TASK_MR_CONTROL, TASK_MR_SUPPORT, TASK_MR_FLEXIBILITY, TASK_MR_CONFIDENCE, TASK_MR_MOTIVATION, TASK_MR_RELAXATION } |
Public Member Functions | |
Task (TaskDescription::Type taskType, double startDate, double endDate, AIMValue target) | |
virtual | ~Task () |
virtual void | doTick () |
virtual std::vector< AIMValue > | getRequirements () const |
virtual bool | requirementsAreUpdated (bool reset=true) const |
virtual void | addTrigger (std::function< bool(double, AIMValue)> triggerFunction) |
virtual void | sendMessage (double timestamp, MsgType msgType) |
virtual void | setFinalStatus (Status finalStatus) |
virtual void | finishTask () |
virtual const std::map < std::string, AIMValue > & | getProperties () |
virtual void | setProperties (const std::map< std::string, AIMValue > &properties) |
virtual void | setValueManually (const AIMValue &data) |
virtual void | setTarget (const AIMValue &data) |
Public Member Functions inherited from AIM | |
AIM (std::string name="") | |
AIM (const AIM &other) | |
AIM & | operator= (const AIM &rhs) |
virtual void | addDataSubscriber (const std::string &key, AIM *subscriber) |
virtual void | removeDataSubscriber (const std::string &key) |
virtual AIMValue | setProperty (const std::string &key, AIMValue value) |
virtual AIMValue | getProperty (std::string key) const |
virtual void | sendData () |
virtual void | addData (const AIMData &data) |
virtual std::string | exportProperties () |
virtual std::vector< std::pair < std::string, AIMValue > > | getOutputData (bool clear_output=false) |
virtual std::vector< std::pair < std::string, AIMValue > > | getInputData (bool clear_input=false) |
virtual AIM * | getDataSubscriber (std::string subscriber) |
virtual std::string | getName () const |
Public Member Functions inherited from CoachingEngine::TaskDescription | |
TaskDescription (Type taskTypeId, double startDate, double endDate, std::string description, AIMValue target) | |
TaskDescription (const TaskDescription &other) | |
TaskDescription () | |
virtual double | getStartDate () const |
virtual double | getEndDate () const |
virtual std::string | getDescription () const |
virtual AIMValue | getTarget () const |
virtual AIMValue | getCurrentValue () const |
virtual Status | getStatus () const |
virtual Type | getTaskType () const |
virtual bool | isCompleted () |
virtual AIMValue | aimValueRepresentation () |
Public Attributes | |
Clock | clock |
Static Public Attributes | |
static const std::string | MSG_FIELD_TASK_TYPE = "task_type" |
static const std::string | MSG_FIELD_TASK_START_TIME = "task_start_time" |
static const std::string | MSG_FIELD_TYPE = "msg_type" |
static const std::string | MSG_FIELD_VALUE = "value" |
static const std::string | MSG_FIELD_TARGET = "target" |
static const std::string | MSG_FIELD_GENERATION_TIME = "generation_time" |
static const std::string | MSG_FIELD_TRIGGER_TIME = "trigger_time" |
static const std::string | PROP_TASK_TYPE = "task_type" |
static const std::string | PROP_START_TIME = "start_time" |
static const std::string | PROP_END_TIME = "end_time" |
static const std::string | PROP_DESCRIPTION = "description" |
static const std::string | PROP_TARGET = "target" |
static const std::string | PROP_VALUE = "value" |
static const std::string | PROP_STATUS = "status" |
static const std::string | PROP_COMPLETED = "completed" |
static const std::string | PROP_LAST_DATA = "last_data" |
static const std::string | PROP_HAS_MANUAL_VALUE = "has_manual_value" |
Static Public Attributes inherited from AIM | |
static const std::string | VERSION = AIM_VERSION |
Protected Member Functions | |
virtual void | processDateValue (const std::string &sensor, const AIMValue &dateValue) |
virtual void | evaluateTriggers (double time, AIMValue data) |
virtual void | initializeTriggers ()=0 |
Protected Member Functions inherited from AIM | |
void | setDataSubscribers (const std::map< std::string, AIM * > &subscribers) |
void | setInputDataQueue (const InputDataQueue &inputDataQueue) |
void | setOutputDataQueue (const AIMDataQueue &outputDataQueue) |
Protected Attributes | |
std::vector< std::function < bool(double, AIMValue)> > | triggers |
bool | triggersInitialized |
Protected Attributes inherited from AIM | |
std::string | name |
std::vector< AIMValue > | requirements |
bool | requirementsUpdated |
std::map< std::string, AIM * > | dataSubscribers |
std::map< std::string, AIMValue > | properties |
InputDataQueue | inputDataQueue |
AIMDataQueue | outputDataQueue |
Protected Attributes inherited from CoachingEngine::TaskDescription | |
Type | taskType |
double | startDate |
double | endDate |
std::string | description |
AIMValue | target |
AIMValue | currentValue |
Status | status |
bool | completed |
Additional Inherited Members | |
Static Public Member Functions inherited from CoachingEngine::TaskDescription | |
static std::string | taskTypeToString (Type taskType) |
static Type | stringToTaskType (std::string taskType) |
A base class to represents a task set by the coach and is responsible for generating the messaged associated with the task. To evaluate progress sets requirements and processes sensor data.
All known message types. Has to be in sync with the cloud database.
CoachingEngine::Task::Task | ( | TaskDescription::Type | taskType, |
double | startDate, | ||
double | endDate, | ||
AIMValue | target | ||
) |
Constrcut a new task.
taskType | The type identifier of the task. |
startDate | Date that the task is started as a Unix timestamp. |
endDate | Date that the task ends as a Unix timestamp. |
description | A human-readable description of the task. |
target | The target of the task. |
|
virtual |
Desctruct a task.
|
virtual |
Add a trigger to the task. The trigger function will be evaluated with the latest timestamp and data whenever there's new data or time.
triggerFunction | A function that accepts a date and value. The function should return true when the trigger fires so it won't be evaluated again. |
|
virtual |
Do an AIM tick
This method is called to tick the AI-module to do its processing. During this tick the AI module grabs it's input data, does its processing, and sends the data to its data receivers. This method can be used in combination with AIM priorities, to streamline the data flow and timers for timed AI modules.
Reimplemented from AIM.
|
protectedvirtual |
|
virtual |
Finish the task so it's completed. Once the task is finished all requirements, timers and triggers will be cleared.
|
virtual |
TODO: create function import properties
Reimplemented from AIM.
|
virtual |
Get the requirements of the module.
Reimplemented from AIM.
|
protectedpure virtual |
Function to initialize the triggers Will be called after the clock has been initialized in the doTick function.
Implemented in CoachingEngine::SleepDurationTask, CoachingEngine::MentalResilienceTask, CoachingEngine::BiorhythmTask, CoachingEngine::CalibrationTask, CoachingEngine::JetLagTask, CoachingEngine::ShiftWorkTask, and CoachingEngine::TimeActiveTask.
|
inlineprotectedvirtual |
Function to process date value. This function should be implemented by the Task implementation.
Reimplemented in CoachingEngine::SleepDurationTask, CoachingEngine::MentalResilienceTask, CoachingEngine::BiorhythmTask, CoachingEngine::CalibrationTask, CoachingEngine::JetLagTask, CoachingEngine::ShiftWorkTask, and CoachingEngine::TimeActiveTask.
|
virtual |
Return wether the requirements have been updated since the last call to this function.
reset | If false, don't reset wether the requirements have been updated. |
Reimplemented from AIM.
|
virtual |
Send a message from the task. A public method so it can be called from within the trigger.
timestamp | Unix timestamp that the message is generated at. |
msgType | Type of the message to be send. |
|
virtual |
Set the status of the task. Public so it can be called from the trigger. Once set, the status may not be overridden. (Although there's no check for that)
finalStatus | The new status of the task. |
|
virtual |
Set the module properties
Set the defined properties. Old property values will remain if no new values are specified for a property.
map | properties The properties to set |
Reimplemented from AIM.
|
virtual |
Manually set the current value of the task
This sets the final value and status of the task
Reimplemented in CoachingEngine::CalibrationTask.
Clock CoachingEngine::Task::clock |
Clock used by the task. The clock is made public so that it can be used to set a timer that's needed to evaluate a trigger.
|
protected |
Triggers for this task.