Cortex Android
|
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< Coach > | getCoaches () |
List< Coach > | getRunningCoaches () |
Coach.TYPE | getCoachAdvice () |
List< Task > | getPastTasks (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 () |
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.
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.
coach_type | The type of Coach to create |
adaptive | Set coach's ability to adapt |
init | Initialize the coach with a specific goal |
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.
coach_type | The type of Coach to create |
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.
The email address of the user | |
password | The password md5 hash |
user_info | The extra coaching and application specific user information |
secret_code | The secret registration code |
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.
|
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.
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
BACKEND_RELEASE nl.sense_os.cortex.coaching.CoachingEngine.getBackendRelease | ( | ) |
Returns the selected backend release
By default the production backend is selected for communication.
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.
coach_type | The type of coach to return. |
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.
List<Coach> nl.sense_os.cortex.coaching.CoachingEngine.getCoaches | ( | ) |
Returns a list of active Coach objects
Historian nl.sense_os.cortex.coaching.CoachingEngine.getHistorian | ( | ) |
Returns an instance of the Historian.
|
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.
sensePlatform | An already initialized 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.
sensePlatform | An 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.
start_time | The epoch start time in seconds |
end_time | The epoch end time in seconds |
Psychologist nl.sense_os.cortex.coaching.CoachingEngine.getPsychologist | ( | ) |
Returns an instance of the Psychologist.
List<Coach> nl.sense_os.cortex.coaching.CoachingEngine.getRunningCoaches | ( | ) |
Returns a list of currently running Coaches
SharedPreferences nl.sense_os.cortex.coaching.CoachingEngine.getSharedPrefs | ( | ) |
Get Coaching Engine preferences
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.
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.
SharedPreferences nl.sense_os.cortex.coaching.CoachingEngine.getUserSharedPrefs | ( | ) |
Get user preferences
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.
coach_type | The Coach.TYPE to check |
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.
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.
forcefull | When 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. |
IllegalStateException | When the logout at the SenseService fails |
RemoteException | When the logout at the SenseService fails |
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.
key | The 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.
release | The backend release to communicate with. |