AIM
 All Classes Functions Variables Typedefs Enumerations
CoachingEngine::Task Class Referenceabstract

#include <Task.h>

Inheritance diagram for CoachingEngine::Task:
AIM CoachingEngine::TaskDescription CoachingEngine::BiorhythmTask CoachingEngine::CalibrationTask CoachingEngine::JetLagTask CoachingEngine::MentalResilienceTask CoachingEngine::ShiftWorkTask CoachingEngine::SleepDurationTask CoachingEngine::TimeActiveTask

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< AIMDataAIMDataQueue
 
typedef std::queue< AIMValueAIMValueQueue
 
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< AIMValuegetRequirements () 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)
 
AIMoperator= (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 AIMgetDataSubscriber (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< AIMValuerequirements
 
bool requirementsUpdated
 
std::map< std::string, AIM * > dataSubscribers
 
std::map< std::string, AIMValueproperties
 
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)
 

Detailed Description

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.

Member Enumeration Documentation

All known message types. Has to be in sync with the cloud database.

Constructor & Destructor Documentation

CoachingEngine::Task::Task ( TaskDescription::Type  taskType,
double  startDate,
double  endDate,
AIMValue  target 
)

Constrcut a new task.

Parameters
taskTypeThe type identifier of the task.
startDateDate that the task is started as a Unix timestamp.
endDateDate that the task ends as a Unix timestamp.
descriptionA human-readable description of the task.
targetThe target of the task.
CoachingEngine::Task::~Task ( )
virtual

Desctruct a task.

Member Function Documentation

void CoachingEngine::Task::addTrigger ( std::function< bool(double, AIMValue)>  triggerFunction)
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.

Parameters
triggerFunctionA function that accepts a date and value. The function should return true when the trigger fires so it won't be evaluated again.
void CoachingEngine::Task::doTick ( )
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.

void CoachingEngine::Task::evaluateTriggers ( double  time,
AIMValue  data 
)
protectedvirtual

Function that evaluates all triggers. Called from doTick()

Parameters
dataThe AIMValue map data with a date, value key holding the epoch date and value of the data.
void CoachingEngine::Task::finishTask ( )
virtual

Finish the task so it's completed. Once the task is finished all requirements, timers and triggers will be cleared.

const std::map< std::string, AIMValue > & CoachingEngine::Task::getProperties ( )
virtual

TODO: create function import properties

  • read the properties from a JSON string (easier to call setProperty from Java/IOS)

Reimplemented from AIM.

vector< AIMValue > CoachingEngine::Task::getRequirements ( ) const
virtual

Get the requirements of the module.

Returns
vector<AIMValue> The list of requirements.

Reimplemented from AIM.

virtual void CoachingEngine::Task::initializeTriggers ( )
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.

virtual void CoachingEngine::Task::processDateValue ( const std::string &  sensor,
const AIMValue dateValue 
)
inlineprotectedvirtual
bool CoachingEngine::Task::requirementsAreUpdated ( bool  reset = true) const
virtual

Return wether the requirements have been updated since the last call to this function.

Parameters
resetIf false, don't reset wether the requirements have been updated.
Returns
true if the requirements are updated since the last call to this function, otherwise false.

Reimplemented from AIM.

void CoachingEngine::Task::sendMessage ( double  timestamp,
Task::MsgType  msgType 
)
virtual

Send a message from the task. A public method so it can be called from within the trigger.

Parameters
timestampUnix timestamp that the message is generated at.
msgTypeType of the message to be send.
void CoachingEngine::Task::setFinalStatus ( Status  finalStatus)
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)

Parameters
finalStatusThe new status of the task.
void CoachingEngine::Task::setProperties ( const std::map< std::string, AIMValue > &  properties)
virtual

Set the module properties

Set the defined properties. Old property values will remain if no new values are specified for a property.

Parameters
mapproperties The properties to set

Reimplemented from AIM.

void CoachingEngine::Task::setValueManually ( const AIMValue data)
virtual

Manually set the current value of the task

This sets the final value and status of the task

Reimplemented in CoachingEngine::CalibrationTask.

Member Data Documentation

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.

std::vector<std::function<bool (double, AIMValue)> > CoachingEngine::Task::triggers
protected

Triggers for this task.


The documentation for this class was generated from the following files: