androidwekaactivity-recognition

How to make Human Activity Recognition less sensitive in Android


I am developing an Android app that is recognising the activity the user us doing every 3 seconds (has to be that frequent by design) (e.g. static, walking, running). I have an Activity table in my database that increments the following values:

private int activeTime;
private int longestInactivityInterval;
private int currentInactivityInterval;
private int averageInactInterval;

Those are presented in a fragment. Currently, it is very "sensitive". For example, if the user is static (i.e. laying on their bed) and they pull their phone out of the pocket it will recognise activity like "walking". The history of recognised activities would look like that:

static
static
walking
static
static

How can I make sure that this incidental "walking" recognised activity is recognised as "static". Is there a way how I can correct that?

This is the class that is doing the Activity monitoring (incrementing values depending on what activity is recognised.

public class ActivityMonitor implements Observer, IActivityMonitor {
private User mUser;
private IActivityDataManager mDataManager;

public ActivityMonitor(IActivityDataManager dataManager) {
    mDataManager = dataManager;
}

@Override
public void update(Observable observable, Object activity) {
    monitorActivity(activity);
}

private void monitorActivity(Object activityClass) {

    switch ((int) activityClass) {
        case 0:
            //activity = "walking";
        case 1:
            //activity = "running";
        case 3:
            //activity = "cycling";
            mDataManager.incActiveTime();
            mDataManager.clearCurrentInacInterval();
            break;
        case 2:
            //activity = "static";
            mDataManager.incCurrentInacInterval();
            break;
    }

}

Solution

  • I found a solution to the problem myself. I am using apache's common CircularFifoQueue with set size to 2.

    This is how my solution looks like:

    private void monitorActivity(Object activityClass) {
        int activityInt = (int) activityClass;
        correctionList.add(activityInt);
        int correctResult = applyCorrection(activityInt);
    
        if (correctResult == correctionList.size()) {
            mDataManager.incActiveTime();
            mDataManager.clearCurrentInacInterval();
        } else {
            mDataManager.incCurrentInacInterval();
        }
    
    
    }
    
    
    private int applyCorrection(int classInt) {
        int count = 0;
        for (int item : correctionList) {
            if (item == 0 || item == 1 || item == 3) {
                count++;
            }
        }
    
        return count;
    }
    

    Basically, it adds the classInt which could be (0,1,2 or 3) - walking = 0, running = 1, cycling = 3 and static = 2. The applyCorrection method looks through the queue with size 2 (this plays the role of the factor, 2 works great for me) and counts and checks the integers. If the returned count correctResult is 2 that means that the activity is for sure of time ACTIVE (1,2,3) and not STATIC (2).