diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java index eadbfbf9e2cc2c881b8eeeddd70ff767254242a2..3d3f0824269c15675334f75d6172310c3834635f 100644 --- a/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java @@ -1,36 +1,58 @@ 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 diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java index 3df862878e5d29cf72f764b4fd7461e3c4245964..1592b7839a6fcc4fd5d1627ffcf2020b11f4bad8 100644 --- a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java @@ -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 */ diff --git a/src/main/java/com/notificationFramework/stimulus/SedentaryStimulus.java b/src/main/java/com/notificationFramework/stimulus/SedentaryStimulus.java index dfff0a0f7052d31013c70792a677cf597b36c51f..422bbe96741de1f3c07c6b83f03a276b02f330bd 100644 --- a/src/main/java/com/notificationFramework/stimulus/SedentaryStimulus.java +++ b/src/main/java/com/notificationFramework/stimulus/SedentaryStimulus.java @@ -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; + } + } } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 6354556173479f221037cc398423bf22c3b71344..4698da2bfec96f917acb63fb00f4d08b58b7be2e 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -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>