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

Added some data analysis

parent 5ef7b584
No related branches found
No related tags found
No related merge requests found
...@@ -95,7 +95,7 @@ public abstract class Notification extends Service { ...@@ -95,7 +95,7 @@ public abstract class Notification extends Service {
mBuilder.setContentIntent(resultPendingIntent); mBuilder.setContentIntent(resultPendingIntent);
nm.notify(snId, mBuilder.build()); nm.notify(snId, mBuilder.build());
//To record information about the notification sent //To record information about the notification sent
SaveFile.recordNotification(1, 0, 0, this); SaveFile.recordNotification(1, 0, 0, 0,this);
SaveFile.recordNotificationType(this); SaveFile.recordNotificationType(this);
//Stops this service //Stops this service
stopSelf(); stopSelf();
......
...@@ -16,7 +16,7 @@ import com.notificationFramework.sedentary.frontEnd.R; ...@@ -16,7 +16,7 @@ import com.notificationFramework.sedentary.frontEnd.R;
/** /**
* Created by Peter De Jonckheere on 09/01/2018. * Created by Peter De Jonckheere on 09/01/2018.
* <p> * <p>
* The concrete implementation of the Notification class which provides the propertis when the * The concrete implementation of the Notification class which provides the properties when the
* notification is to be sent when the user has been sedentary for a prolonged period of time. * notification is to be sent when the user has been sedentary for a prolonged period of time.
* </p> * </p>
*/ */
......
package com.notificationFramework.sedentary.frontEnd;
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.
*/
public class DataAnalysis {
static boolean analyse(String line, Calendar cal){
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){
Log.e("ANALYSING", "PARSINGERROR");
}
compCal.add(Calendar.MINUTE, -6);
if(compCal.before(cal.getTime())){
return true;
}else{
return false;
}
}
}
...@@ -42,7 +42,7 @@ public class NotificationClicked extends AppCompatActivity { ...@@ -42,7 +42,7 @@ public class NotificationClicked extends AppCompatActivity {
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
SaveFile.recordNotification(0, 1, 0, this); SaveFile.recordNotification(0, 1, 0,0, this);
} }
/** /**
......
...@@ -40,7 +40,6 @@ public class SaveFile { ...@@ -40,7 +40,6 @@ public class SaveFile {
* 0 otherwise * 0 otherwise
* @param clicked 1 if a notification has been clicked on, 1 if a goal notification has been * @param clicked 1 if a notification has been clicked on, 1 if a goal notification has been
* sent, 0 otherwise * sent, 0 otherwise
* @param acknowledged 1 if a movement has been registered, 0 otherwise
* @param context the application context which the method has been called from and which will * @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 * be used to access and write to the external storage of the device
*/ */
...@@ -48,6 +47,8 @@ public class SaveFile { ...@@ -48,6 +47,8 @@ public class SaveFile {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
ArrayList<String> contents = new ArrayList<String>(); ArrayList<String> contents = new ArrayList<String>();
String line; String line;
String prevLine = null;
String[] items;
//Checks for external storage //Checks for external storage
if (isExternalStorageMounted()) { if (isExternalStorageMounted()) {
File dir = getDirectory(context); File dir = getDirectory(context);
...@@ -66,6 +67,17 @@ public class SaveFile { ...@@ -66,6 +67,17 @@ public class SaveFile {
BufferedReader br = new BufferedReader(new FileReader(file)); BufferedReader br = new BufferedReader(new FileReader(file));
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
contents.add(line + '\n'); contents.add(line + '\n');
prevLine = line;
}
try {
items = prevLine.split(" ");
if (items[6].equals("10")){
if(DataAnalysis.analyse(prevLine, cal)){
recordNotification(0,0,0,1, context);
}
}
}catch(NullPointerException e){
} }
} }
//Adds the new log to the file up to 1000 items. At 1000 items the oldest is removed //Adds the new log to the file up to 1000 items. At 1000 items the oldest is removed
...@@ -77,7 +89,7 @@ public class SaveFile { ...@@ -77,7 +89,7 @@ public class SaveFile {
for (String ts : contents) { for (String ts : contents) {
bw.write(ts); bw.write(ts);
} }
bw.write(cal.getTime().toString() + " " + sent + "" + clicked); bw.write(cal.getTime().toString() + " " + sent + "" + clicked + " " + acknowledged);
bw.close(); bw.close();
} }
...@@ -96,13 +108,15 @@ public class SaveFile { ...@@ -96,13 +108,15 @@ public class SaveFile {
* sent 0 otherwise * sent 0 otherwise
* @param clicked 1 if a notification has been clicked on, 1 if a goal notification has * @param clicked 1 if a notification has been clicked on, 1 if a goal notification has
* been sent, 0 otherwise * been sent, 0 otherwise
* @param acknowledged 1 if a movement has been registered, 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 context the application context which the method has been called from and which * @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 * will be used to access and write to the external storage of the device
*/ */
public static void recordNotification(int sent, int clicked, int acknowledged, Context context){ public static void recordNotification(int sent, int clicked, int movement, int acknowledged, Context context){
int ns = 0; int ns = 0;
int nc = 0; int nc = 0;
int nm = 0;
int na = 0; int na = 0;
//Checks if external storage is present //Checks if external storage is present
if (isExternalStorageMounted()) { if (isExternalStorageMounted()) {
...@@ -120,6 +134,7 @@ public class SaveFile { ...@@ -120,6 +134,7 @@ public class SaveFile {
try { try {
ns = Integer.parseInt(br.readLine()); ns = Integer.parseInt(br.readLine());
nc = Integer.parseInt(br.readLine()); nc = Integer.parseInt(br.readLine());
nm = Integer.parseInt(br.readLine());
na = Integer.parseInt(br.readLine()); na = Integer.parseInt(br.readLine());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e("FILEERROR", "COULD NOT READ FILE"); Log.e("FILEERROR", "COULD NOT READ FILE");
...@@ -129,11 +144,14 @@ public class SaveFile { ...@@ -129,11 +144,14 @@ public class SaveFile {
BufferedWriter bw = new BufferedWriter(new FileWriter(file)); BufferedWriter bw = new BufferedWriter(new FileWriter(file));
ns += sent; ns += sent;
nc += clicked; nc += clicked;
nm += movement;
na += acknowledged; na += acknowledged;
bw.write(String.valueOf(ns)); bw.write(String.valueOf(ns));
bw.newLine(); bw.newLine();
bw.write(String.valueOf(nc)); bw.write(String.valueOf(nc));
bw.newLine(); bw.newLine();
bw.write(String.valueOf(nm));
bw.newLine();
bw.write(String.valueOf(na)); bw.write(String.valueOf(na));
bw.close(); bw.close();
} }
......
...@@ -165,7 +165,7 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv ...@@ -165,7 +165,7 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv
PendingIntent pi = PendingIntent.getBroadcast(getBaseContext(), PendingIntent pi = PendingIntent.getBroadcast(getBaseContext(),
R.integer.alarm_rc, i, PendingIntent.FLAG_UPDATE_CURRENT); R.integer.alarm_rc, i, PendingIntent.FLAG_UPDATE_CURRENT);
am.cancel(pi); am.cancel(pi);
SaveFile.recordNotification(0, 0, 1, this); SaveFile.recordNotification(0, 0, 1,0, this);
setUpClock(); setUpClock();
} }
...@@ -177,7 +177,7 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv ...@@ -177,7 +177,7 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv
public void goalNotify() { public void goalNotify() {
Intent i = new Intent(getBaseContext(), Intent i = new Intent(getBaseContext(),
com.notificationFramework.stimulus.GoalStimulus.class); com.notificationFramework.stimulus.GoalStimulus.class);
SaveFile.recordNotification(1, 1, 0, this); SaveFile.recordNotification(1, 1, 0, 0, this);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.sendBroadcast(i); lbm.sendBroadcast(i);
} }
......
...@@ -149,7 +149,7 @@ public class SigMotionDetect extends Service implements StimulusStrategy { ...@@ -149,7 +149,7 @@ public class SigMotionDetect extends Service implements StimulusStrategy {
PendingIntent pi = PendingIntent.getBroadcast(this, PendingIntent pi = PendingIntent.getBroadcast(this,
R.integer.alarm_rc, i, 0); R.integer.alarm_rc, i, 0);
am.cancel(pi); am.cancel(pi);
SaveFile.recordNotification(0, 0, 1, this); SaveFile.recordNotification(0, 0, 1, 0, this);
setUpClock(); setUpClock();
prevSeconds = seconds; prevSeconds = seconds;
} }
...@@ -250,7 +250,7 @@ public class SigMotionDetect extends Service implements StimulusStrategy { ...@@ -250,7 +250,7 @@ public class SigMotionDetect extends Service implements StimulusStrategy {
public void goalNotify() { public void goalNotify() {
Intent i = new Intent(getBaseContext(), Intent i = new Intent(getBaseContext(),
com.notificationFramework.stimulus.GoalStimulus.class); com.notificationFramework.stimulus.GoalStimulus.class);
SaveFile.recordNotification(1, 1, 0, this); SaveFile.recordNotification(1, 1, 0, 0, this);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.sendBroadcast(i); lbm.sendBroadcast(i);
} }
......
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