Skip to content
Snippets Groups Projects
Commit 7da0fdef authored by Peter Joseph De Jonckheere CESM2014's avatar Peter Joseph De Jonckheere CESM2014
Browse files

Added some more data analysis

parent 81cd4412
No related branches found
No related tags found
No related merge requests found
package com.notificationFramework.sedentary.frontEnd;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
* Created by pharmacy on 19/06/2018.
* Created by Peter De Jonckheere on 19/06/2018.
*/
public class DataAnalysis {
static boolean analyse(String line, Calendar cal){
static boolean analyse(String line, Calendar cal, Context context) {
Calendar compCal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEEMMMddHH:mm:sszyyyy", Locale.ENGLISH);
String items[] = line.split(" ");
String dateString = items[0] + items[1] + items[2] + items[3] + items[4] + items[5];
try {
compCal.setTime(sdf.parse(dateString));
}catch(ParseException e){
} catch (ParseException e) {
Log.e("ANALYSING", "PARSINGERROR");
}
compCal.add(Calendar.MINUTE, -6);
if(compCal.before(cal.getTime())){
if (compCal.before(cal.getTime())) {
//Remove notification
//Give new notification saying well done?
logAcknowledgement(context);
return true;
}else{
} else {
return false;
}
}
}
private static void logAcknowledgement(Context context) {
SharedPreferences sharedPref = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
int totalAck = sharedPref.getInt(context.getString(R.string.ack_total), 0);
int ackDays = sharedPref.getInt(context.getString(R.string.ack_days), 1);
float avgAck;
int currentDay = Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
if (currentDay != sharedPref.getInt(context.getString(R.string.progress_day), 0)) {
avgAck = totalAck / ackDays;
ackDays++;
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(context.getString(R.string.progress_day), currentDay);
editor.putInt(context.getString(R.string.ack_total), totalAck);
editor.putInt(context.getString(R.string.ack_days), ackDays);
editor.putFloat(context.getString(R.string.avg_ack), avgAck);
editor.commit();
}
totalAck++;
}
}
\ No newline at end of file
......@@ -109,7 +109,7 @@ public class SaveFile {
* @param clicked 1 if a notification has been clicked on, 1 if a goal notification has
* been sent, 0 otherwise
* @param movement 1 if a movement has been registered, 0 otherwise
* @param acknowledged 1 if a notification has been acknowledged by a movement
* @param acknowledged 1 if a notification has been acknowledged by a movement, 0 otherwise
* @param context the application context which the method has been called from and which
* will be used to access and write to the external storage of the device
*/
......
......@@ -28,6 +28,8 @@ public class SedentaryStimulus extends BroadcastReceiver implements Stimulus {
*/
private static StimulusStrategy strategy;
private final int threshold = 10;
/**
* Empty constructor required by the manifest to define this class as a broadcast receiver
*/
......@@ -84,7 +86,8 @@ public class SedentaryStimulus extends BroadcastReceiver implements Stimulus {
public void onReceive(Context context, Intent intent) {
SharedPreferences shared =
context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
if ((checkTime(shared, context)) && (shared.getBoolean(context.getString(R.string.notf_switch), true))) {
if ((checkTime(shared, context)) && (shared.getBoolean(context.getString(R.string.notf_switch), true))
&& checkAcknowledged(shared, context)) {
Intent i = new Intent(context.getApplicationContext(),
com.notificationFramework.notification.SedentaryNotification.class);
context.getApplicationContext().startService(i);
......@@ -146,4 +149,18 @@ public class SedentaryStimulus extends BroadcastReceiver implements Stimulus {
return true;
}
}
//Returns true if notification is to be sent
private boolean checkAcknowledged(SharedPreferences shared, Context context){
int period = shared.getInt(context.getString(R.string.daily_goal), context.getResources().getInteger(R.integer.daily_goal_minutes));
float ackThreshold = (24/period) * threshold;
float avgAck = shared.getFloat(context.getString(R.string.avg_ack), 4);
if(avgAck < ackThreshold){
//Send well done notification
//Record unsent notification for fading and behavioural analysis purposes??
return false;
}else{
return true;
}
}
}
......@@ -43,4 +43,7 @@
<string name="strat_switch">Switch detection method</string>
<string name="strategy">Current strategy</string>
<string name="goal_met">Daily Goal Met</string>
<string name="ack_total">Acknowledgement Total</string>
<string name="ack_days">Acknowledgement Day Count</string>
<string name="avg_ack">Acknowledgements per day</string>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment