Cortex Android
 All Classes Namespaces Functions Variables
nl.sense_os.cortex.coaching.CoachingEngine Class Reference

Classes

enum  BACKEND_RELEASE
 
enum  STATUS
 

Public Member Functions

Psychologist getPsychologist ()
 
Historian getHistorian ()
 
synchronized void handleRequirementsUpdate ()
 
User createUser (String email, String password, JSONObject user_info, String secret_code) throws Exception
 
User getUser () throws Exception
 
boolean deleteUser ()
 
Coach createCoach (Coach.TYPE coach_type, boolean adaptive, GOAL_INITIALIZATION init)
 
Coach createCoach (Coach.TYPE coach_type)
 
boolean isCreated (Coach.TYPE coach_type)
 
Coach getCoach (Coach.TYPE coach_type)
 
List< CoachgetCoaches ()
 
List< CoachgetRunningCoaches ()
 
Coach.TYPE getCoachAdvice ()
 
List< TaskgetPastTasks (double start_time, double end_time)
 
String getApplicationKey ()
 
void setApplicationKey (String key)
 
SharedPreferences getUserSharedPrefs ()
 
SharedPreferences getSharedPrefs ()
 
boolean isUserLoggedIn ()
 
CoachingEngine.STATUS getStatus ()
 
boolean logout (boolean forcefull) throws IllegalStateException, RemoteException
 
void setBackendRelease (BACKEND_RELEASE release)
 
BACKEND_RELEASE getBackendRelease ()
 

Static Public Member Functions

static synchronized CoachingEngine getInstance (SensePlatform sensePlatform)
 
static synchronized CoachingEngine getNewInstance (SensePlatform sensePlatform)
 

Static Public Attributes

static boolean returnDummyData = false
 

Protected Member Functions

void checkFirstTimeLogin ()
 
boolean firstTimeInit ()
 

Static Protected Attributes

static final String PREFERENCES_BASENAME = "CoachingEngine"
 
static final String PREFERENCES_APP_KEY = "application_key"
 
static final String PREFERENCES_FIRST_LOGIN = "first_login"
 
static final String PREFERENCES_COACHES_SYNCED = "coachingengine_coaches_synced"
 
static final String PREFERENCES_BACKEND_RELEASE = "backend_release"
 

Detailed Description

The Coaching Engine

This class initializes the Coaching Engine.
It makes sure the SenseService with the sensors needed by the coaches are enabled with the right sample rates.
A Coaching Engine instance is stateless, it's properties are stored as shared preferences,
and coaches will be kept in the SenseService.

Author
ted@s.nosp@m.ense.nosp@m.-os.n.nosp@m.l
Date
24-06-2014

Member Function Documentation

Coach nl.sense_os.cortex.coaching.CoachingEngine.createCoach ( Coach.TYPE  coach_type,
boolean  adaptive,
GOAL_INITIALIZATION  init 
)

Creates a new Coach

Creates a Coach by creating a specific Coach instance and initializing it.
If the Coach already exists the existing Coach is re-initialized.
The state of the CoachingEngine should be READY.

Parameters
coach_typeThe type of Coach to create
adaptiveSet coach's ability to adapt
initInitialize the coach with a specific goal
Returns
A new or already existing Coach. Returns null if the coach could not be created or initialized, then check the getCoachAdvice() method.
Coach nl.sense_os.cortex.coaching.CoachingEngine.createCoach ( Coach.TYPE  coach_type)

Creates a new Coach

Creates a Coach by creating a specific Coach instance.
If the Coach already exists the existing Coach is enabled and returned.
The state of the CoachingEngine should be READY.

Parameters
coach_typeThe type of Coach to create
Returns
A new or already existing Coach. Returns null if the coach could not be created
User nl.sense_os.cortex.coaching.CoachingEngine.createUser ( String  email,
String  password,
JSONObject  user_info,
String  secret_code 
) throws Exception

Create a new Sense / Coaching user

This will create a new CommonSense account which can be used to also login to the Coaching API.
This function blocks this thread until it is finished.

Parameters
emailThe email address of the user
passwordThe password md5 hash
user_infoThe extra coaching and application specific user information
secret_codeThe secret registration code
Returns
The newly created user. Returns null if the user could not be registered
boolean nl.sense_os.cortex.coaching.CoachingEngine.deleteUser ( )

Delete user

Removes a user from the Coaching Engine locally and in the back-end and deletes all traces of him also in CommonSense.
It first disables all the running coaches and then does a logout on the SenseService after which the account and data will be delete.

Returns
True if the user was successfully removed from the back-end and local storage.
boolean nl.sense_os.cortex.coaching.CoachingEngine.firstTimeInit ( )
protected

First time initialization

When this is the first run on this phone for this user, a check will be performed whether this users has old coaches to be downloaded.

Returns
True if the initialization was successful. False if it failed.
String nl.sense_os.cortex.coaching.CoachingEngine.getApplicationKey ( )

Get the Application key

Returns the application key which is used to identify the application in the back-end

Returns
The application key
BACKEND_RELEASE nl.sense_os.cortex.coaching.CoachingEngine.getBackendRelease ( )

Returns the selected backend release

By default the production backend is selected for communication.

Returns
The selected BACKEND_RELEASE
Coach nl.sense_os.cortex.coaching.CoachingEngine.getCoach ( Coach.TYPE  coach_type)

Returns a specific Coach instance

Will return the instance of the specific Coach if it has been created.

Parameters
coach_typeThe type of coach to return.
Returns
An instance of the Coach if it has been created. Null if the Coach.TYPE does not exists or if the coach has not been created
Coach.TYPE nl.sense_os.cortex.coaching.CoachingEngine.getCoachAdvice ( )

Get the advised Coach

Based on the current baseline of the user a Coach is advised. If the application has not determined a baseline for the user, then the CalibrationCoach is advised. Coaches can only be initialized with the PERSONAL initialization type after a calibration phase.

Returns
The advised Coach to create or initialize. If no advice is available, null is returned.
List<Coach> nl.sense_os.cortex.coaching.CoachingEngine.getCoaches ( )

Returns a list of active Coach objects

Returns
The list of active coaches
Historian nl.sense_os.cortex.coaching.CoachingEngine.getHistorian ( )

Returns an instance of the Historian.

Returns
The Psychologist instance
static synchronized CoachingEngine nl.sense_os.cortex.coaching.CoachingEngine.getInstance ( SensePlatform  sensePlatform)
static

This returns the coaching engine instance

When the SenseService is started an instance of the CoachingEngine is retrieved after which all the needed coaches are started.
Start the CoachingEngine with a SensePlatform object which is already binded to the SenseService.
The CoachingEngine can be in 3 different states: UNINITIALIZED, INITIALIZING, READY.

After the application key is set and a user has logged in, the status of the CoachingEngine is INITIALIZING.
Before this it will be UNINITIALIZED.
When the CoachingEngine is ready for operation the status READY is returned.
Until that time no coaches can be created.

When an existing user logs in for the first time, all it's data is downloaded, the CoachingEngine can therefore be in in the state INITIALIZING for some time. Initialization will be retried for some time (10x), if it keeps failing the user is logged out and needs to login again, and the state will go to UNINITIALIZED.

Parameters
sensePlatformAn already initialized sensePlatform
static synchronized CoachingEngine nl.sense_os.cortex.coaching.CoachingEngine.getNewInstance ( SensePlatform  sensePlatform)
static

This class starts the coaching engine and re-enables the coaches

Start the CoachingEngine with a SensePlatform object which is already binded to the SenseService.

Parameters
sensePlatformAn already initialized sensePlatform
List<Task> nl.sense_os.cortex.coaching.CoachingEngine.getPastTasks ( double  start_time,
double  end_time 
)

Get the Completed tasks

Get the Tasks which where active in the given time range. Currently active tasks will not be returned, nor future tasks.

Parameters
start_timeThe epoch start time in seconds
end_timeThe epoch end time in seconds
Returns
Psychologist nl.sense_os.cortex.coaching.CoachingEngine.getPsychologist ( )

Returns an instance of the Psychologist.

Returns
The Psychologist instance
List<Coach> nl.sense_os.cortex.coaching.CoachingEngine.getRunningCoaches ( )

Returns a list of currently running Coaches

Returns
The list of running coaches
SharedPreferences nl.sense_os.cortex.coaching.CoachingEngine.getSharedPrefs ( )

Get Coaching Engine preferences

Returns
The SharedPreferences object for the CoachingEngine
CoachingEngine.STATUS nl.sense_os.cortex.coaching.CoachingEngine.getStatus ( )

Get the status of the CoachingEngine

After the application key is set and a user has logged in, the status of the CoachingEngine is INITIALIZING.
Before this it will be UNINITIALIZED.
When the CoachingEngine is ready for operation the status READY is returned.
Until that time no coaches can be created.

Returns
The status of the CoachingEngine
User nl.sense_os.cortex.coaching.CoachingEngine.getUser ( ) throws Exception

Returns the user object

This will return the Coaching API enabled CommonSense user.
This will only return a user if the user is logged in via the SensePlatfor or SenseService.
This method will throw an Exception when the request for the user fails.

Returns
The currently logged in user
SharedPreferences nl.sense_os.cortex.coaching.CoachingEngine.getUserSharedPrefs ( )

Get user preferences

Returns
The SharedPereferences object for the user.
synchronized void nl.sense_os.cortex.coaching.CoachingEngine.handleRequirementsUpdate ( )

Handle changed requirements

Only SenseService related sensors are handled.
The Coach handles it's own requirements.
This function is internally used by in the CoachingEngine

boolean nl.sense_os.cortex.coaching.CoachingEngine.isCreated ( Coach.TYPE  coach_type)

Check is a Coach is created.

This checks the local preference. There does not have to be an actual instance.

Parameters
coach_typeThe Coach.TYPE to check
Returns
True if this coach has a preference set to true, false otherwise.
boolean nl.sense_os.cortex.coaching.CoachingEngine.isUserLoggedIn ( )

Check whether the user is logged in

It checks the Authentication settings of the Sense Service for a username and session id.
If both are available then the user is considered to be logged in.

Returns
True if the user is logged in, false if not.
boolean nl.sense_os.cortex.coaching.CoachingEngine.logout ( boolean  forcefull) throws IllegalStateException, RemoteException

Logout from the CoachingEngine and SenseService

This function tries to flush the local data to the back-end before it stops all the coaches and does a logout at the SenseService.

Parameters
forcefullWhen set to true it will try to flush the data but still does a logout when the flush fails. When set to false it will only try the logout at the SenseService if the flush succeeded.
Exceptions
IllegalStateExceptionWhen the logout at the SenseService fails
RemoteExceptionWhen the logout at the SenseService fails
Returns
True if the data flush was successful, false otherwise.
void nl.sense_os.cortex.coaching.CoachingEngine.setApplicationKey ( String  key)

Set the Application key

This sets the application key which is used to identify the application in the back-end.
The application key will also be set for the SenseService which needs this key for the login.

Parameters
keyThe application key
void nl.sense_os.cortex.coaching.CoachingEngine.setBackendRelease ( BACKEND_RELEASE  release)

Set the backend to use

Select the backend release to communicate with.
The application key associated with the selected release should be set.
Also the SensePlatform DEV_MODE will be enabled/disabled based on the selected release.

Parameters
releaseThe backend release to communicate with.

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