AIM
 All Classes Functions Variables Typedefs Enumerations
CoachingEngine::Coach Class Reference

#include <Coach.h>

Inheritance diagram for CoachingEngine::Coach:
AIM CoachingEngine::BiorhythmCoach CoachingEngine::CalibrationCoach CoachingEngine::ExerciseCoach CoachingEngine::JetLagCoach CoachingEngine::MentalResilienceCoach CoachingEngine::ShiftWorkCoach CoachingEngine::SleepDurationCoach

Public Types

enum  Type {
  PHYSICAL_ACTIVITY, MENTAL_RESILIENCE, SLEEP_DURATION, JETLAG,
  SHIFTWORK, CALIBRATION, NONE, BIORHYTHM
}
 
enum  InitializationType { MANUAL_GOAL, POPULATION_GOAL, PERSONAL_GOAL }
 
enum  Status { UNINITIALIZED, GOAL_INITIALIZED, READY, PAUSED }
 
- 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 Member Functions

 Coach (const Coach &other)
 
Coachoperator= (const Coach &rhs)
 
void addData (const AIMData &data)
 
void doTick ()
 
std::vector< AIMValuegetRequirements () const
 
bool requirementsAreUpdated (bool reset) const
 
virtual void setGoal (InitializationType type, const AIMValue &init, bool dynamic=true)
 
virtual AIMValue getGoal () const
 
virtual std::vector
< TaskDescription
getCurrentTasks () const
 
virtual std::vector
< TaskDescription
getFutureTasks (double start, double end)
 
virtual Status getStatus () const
 
virtual Type getType ()
 
virtual const std::map
< std::string, AIMValue > & 
getProperties ()
 
virtual std::map< std::string,
AIMValue
getMemberDataAsProperties () const
 
virtual void setProperties (const std::map< std::string, AIMValue > &properties)
 
virtual void pause (double time)
 
virtual void resume (double time)
 
virtual TaskDescription setTaskValueManually (std::string taskType, double taskStartDate, 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 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
 

Static Public Attributes

static const std::string PROP_COMPLETED_TASKS = "completed_tasks"
 
static const std::string PROP_ACTIVE_TASKS = "active_tasks"
 
static const std::string PROP_STATUS = "status"
 
static const std::string PROP_GOAL = "goal"
 
static const std::string PROP_BASELINE = "baseline"
 
static const std::string PROP_DYNAMIC_COACH = "dynamic_coach"
 
static const std::string PROP_GOAL_TYPE = "goal_type"
 
static const std::string PROP_START_DATE = "start_date"
 
static const std::string PROP_END_DATE = "end_date"
 
static const std::string PROP_TOTAL_DAYS = "total_days"
 
static const std::string PROP_GAIN = "gain"
 
static const std::string PROP_CURRENT_TIME = "clock"
 
static const std::string PROP_START_PAUSE = "start_pause"
 
static const std::string OUTPUT_FIELD_COACH_TYPE = "coach_type"
 
static const std::string PROP_PAUSED_SECONDS = "paused_seconds"
 
- Static Public Attributes inherited from AIM
static const std::string VERSION = AIM_VERSION
 

Protected Types

typedef std::map< std::string,
std::unordered_set< Task * > > 
SensorRoutes
 

Protected Member Functions

 Coach (Type coachType, std::string name="coach")
 
virtual void processDateValue (const std::string &sensor, const AIMValue &dateValue)
 
virtual void addActiveTask (Task &task)
 
virtual void removeActiveTask (Task *task)
 
virtual double calculateTargetValue (int week, double goalValue, double lastValue, double speed=(2.0/3.0))
 
virtual int getWeek (double date)
 
virtual double calculateGoal (std::string taskType, double currentValue, int weeksLeft)
 
virtual void decreaseGain (std::string taskType)
 
virtual void increaseGain (std::string taskType)
 
virtual void handleCompletedTask (Task *task)
 
virtual bool checkAndHandleNewWeek ()
 
virtual double calculateAverage (std::string taskType, double startDate, double endDate, int min_values=1, int nr_values=-1)
 
virtual void createNewTask (std::string taskType)
 
virtual std::pair< double, double > calculateTaskPeriod (double currentTime, std::string taskType="")
 
virtual void removeRoutesForTask (Task *task)
 
virtual TaskgetTask (TaskDescription::Type type)
 
- 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

const Type type
 
Status status
 
std::vector< Task * > activeTasks
 
std::vector< Task * > completedTasks
 
SensorRoutes routes
 
AIMValue goal
 
AIMValue baseline
 
Clock clock
 
bool dynamicCoach
 
InitializationType goalType
 
double end_date
 
double start_date
 
int total_days
 
AIMValue gain
 
- 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
 

Detailed Description

Base class for coaches. Facilitates task and requirement management.

Member Enumeration Documentation

Type used for initialization of the goal.

MANUAL_GOAL: init = {{"goal",{"Task.TYPE", "value"}}}

PERSONAL_GOAL: init = {{"goal",{"Task.TYPE", "value"}}, {"baseline",{"Task.TYPE", "value"}}, {"days",84}}

POPULATION_GOAL: init = {{"goal",{"Task.TYPE", "value"}}, {"baseline",{"Task.TYPE", "value"}}, {"days",84}}

Status of the coach.

Coach types. Needs to be in sync with the cloud database.

Constructor & Destructor Documentation

CoachingEngine::Coach::Coach ( Type  coachType,
std::string  name = "coach" 
)
protected

Construct a new coach.

Parameters
coachTypeThe type identification for the new instance.
nameName of the AI Module.

Member Function Documentation

void CoachingEngine::Coach::addActiveTask ( Task task)
protectedvirtual

Add a task to the pool of managed tasks. After adding the task requirements and data forwarding will be handled by the Coach.

Reimplemented in CoachingEngine::MentalResilienceCoach.

void CoachingEngine::Coach::addData ( const AIMData data)
virtual

Add data

This method adds data to the input queue of the AI-module The AIMData object

Parameters
AIMDatadata The input data

Reimplemented from AIM.

double CoachingEngine::Coach::calculateAverage ( std::string  taskType,
double  startDate,
double  endDate,
int  min_values = 1,
int  nr_values = -1 
)
protectedvirtual

compute average task value for tasks active in the specified period

Parameters
taskTypeThe Task.Type to compute the average for
startDateThe start time of the period to search for tasks
endDateThe end time of the period to search for tasks
min_valuesThe minimum amount of values needed, otherwise use the baseline
nr_valuesThe amount of latest values in a period to use (disabled by default)
Returns
Average of the current values of the past tasks if min_values is satisfied, otherwise the baseline
double CoachingEngine::Coach::calculateGoal ( std::string  taskType,
double  currentValue,
int  weeksLeft 
)
protectedvirtual

update the goal when the coach is dynamic

double CoachingEngine::Coach::calculateTargetValue ( int  week,
double  goalValue,
double  lastValue,
double  speed = (2.0/3.0) 
)
protectedvirtual

calculate the target value for personalized targets

std::pair< double, double > CoachingEngine::Coach::calculateTaskPeriod ( double  currentTime,
std::string  taskType = "" 
)
protectedvirtual

function to calculate the start and end time of a task

Reimplemented in CoachingEngine::SleepDurationCoach, and CoachingEngine::MentalResilienceCoach.

bool CoachingEngine::Coach::checkAndHandleNewWeek ( )
protectedvirtual

check if a new week has started

void CoachingEngine::Coach::createNewTask ( std::string  taskType)
protectedvirtual

function to call to create new tasks

void CoachingEngine::Coach::decreaseGain ( std::string  taskType)
protectedvirtual

decrease the gain

void CoachingEngine::Coach::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.

vector< TaskDescription > CoachingEngine::Coach::getCurrentTasks ( ) const
virtual

Return a list of all currently active tasks.

Returns
A list of all active tasks.
vector< TaskDescription > CoachingEngine::Coach::getFutureTasks ( double  start,
double  end 
)
virtual

Return planned tasks for the specified time range.

Parameters
startStart date as Unix timestmap for the range to get planned tasks for,
endEnd date as Unix timestamp for the range to get planned tasks for.
Returns
A list of the tasks planned for the specified period.

Reimplemented in CoachingEngine::JetLagCoach, CoachingEngine::ShiftWorkCoach, CoachingEngine::CalibrationCoach, and CoachingEngine::BiorhythmCoach.

virtual AIMValue CoachingEngine::Coach::getGoal ( ) const
inlinevirtual

Return the goal set for this coach.

Returns
The value set for this goal.
const std::map< std::string, AIMValue > & CoachingEngine::Coach::getProperties ( )
inlinevirtual

get the properties of the coach

Reimplemented from AIM.

Reimplemented in CoachingEngine::JetLagCoach, CoachingEngine::ShiftWorkCoach, and CoachingEngine::BiorhythmCoach.

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

Get the requirements of the module.

Returns
vector<AIMValue> The list of requirements.

Reimplemented from AIM.

virtual Status CoachingEngine::Coach::getStatus ( ) const
inlinevirtual

Return the status of the coach.

Returns
The status of the coach.
virtual Type CoachingEngine::Coach::getType ( )
inlinevirtual

Return the coach type. The coach type is used to identify the coach type to the outside world.

Returns
Type of the coach.
int CoachingEngine::Coach::getWeek ( double  date)
protectedvirtual

calculate the week based on the date

void CoachingEngine::Coach::handleCompletedTask ( Task task)
protectedvirtual

handle a completed task

void CoachingEngine::Coach::increaseGain ( std::string  taskType)
protectedvirtual

increase the gain

void CoachingEngine::Coach::pause ( double  time)
virtual

Pause the coach

Parameters
timeThe current time

Reimplemented in CoachingEngine::CalibrationCoach.

void CoachingEngine::Coach::processDateValue ( const std::string &  sensor,
const AIMValue dateValue 
)
protectedvirtual
void CoachingEngine::Coach::removeActiveTask ( Task task)
protectedvirtual

Remove a task.

bool CoachingEngine::Coach::requirementsAreUpdated ( bool  reset) 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::Coach::resume ( double  time)
virtual

Un-pause the coach

Parameters
timeThe current time

Reimplemented in CoachingEngine::CalibrationCoach.

void CoachingEngine::Coach::setGoal ( InitializationType  type,
const AIMValue init,
bool  dynamic = true 
)
virtual

Set the goal for the coach.

A coach can be initialized with a specific type. With a corresponding init value.

MANUAL_GOAL: init = {{"goal",{"Task.TYPE", "value"}}}

PERSONAL_GOAL: init = {{"goal",{"Task.TYPE", "value"}}, {"baseline",{"Task.TYPE", "value"}}, {"days",84}}

POPULATION_GOAL: init = {{"goal",{"Task.TYPE", "value"}}, {"baseline",{"Task.TYPE", "value"}}, {"days",84}}

Parameters
typeThe InitializationType of the coach
initThe AIMValue map with initialization data
dynamicUpdate the goal based on the progress

Reimplemented in CoachingEngine::JetLagCoach, CoachingEngine::ShiftWorkCoach, CoachingEngine::CalibrationCoach, CoachingEngine::BiorhythmCoach, CoachingEngine::SleepDurationCoach, CoachingEngine::ExerciseCoach, and CoachingEngine::MentalResilienceCoach.

void CoachingEngine::Coach::setProperties ( const std::map< std::string, AIMValue > &  properties)
virtual

set the properties of the coach

Reimplemented from AIM.

Reimplemented in CoachingEngine::CalibrationCoach, CoachingEngine::JetLagCoach, CoachingEngine::ShiftWorkCoach, and CoachingEngine::BiorhythmCoach.

TaskDescription CoachingEngine::Coach::setTaskValueManually ( std::string  taskType,
double  taskStartDate,
const AIMValue data 
)
virtual

Override the value of a task.

The status will be re-evaluated and set, and if the task is currently active, a message will be send about the status

Parameters
taskTypeThe Task::Type as string
taskStartDatethe start date of the task
dataThe sensor data
Returns
The updated Task will be returned as TaskDescritpion

Reimplemented in CoachingEngine::CalibrationCoach.


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