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

Some sorting for places

parent 982cf160
No related branches found
No related tags found
No related merge requests found
...@@ -4,11 +4,14 @@ import android.app.NotificationManager; ...@@ -4,11 +4,14 @@ import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.icu.util.RangeValueIterator;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.util.Log; import android.util.Log;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
...@@ -74,7 +77,58 @@ public class DataAnalysis { ...@@ -74,7 +77,58 @@ public class DataAnalysis {
private void placeAnalysis(Context context){ private void placeAnalysis(Context context){
List<Place> places = SaveFile.getPlaces(context); List<Place> places = SaveFile.getPlaces(context);
Place[] sortedPlaces = (Place[])(quicksort(places.toArray(), 0, places.size()-1));
int popularType = getPopularElement(sortedPlaces);
} }
private Object[] quicksort(Object[] array, int low, int high) {
if (low < high) {
int p = partition(array, low, high);
quicksort(array, low, p - 1);
quicksort(array, p + 1, high);
}
return array;
}
private int partition(Object[] array, int low, int high){
int pivot = ((Place) array[high]).getType();
int i = low - 1;
for(int j = low; j < high - 1; j++){
if(((Place)array[j]).getType() < pivot){
i++;
Place swap = ((Place)array[j]);
array[j] = array[i];
array[i] = swap;
}
}
Place swap = ((Place) array[i+1]);
array[i+1] = array[high];
array[high] = swap;
return i+1;
}
private int getPopularElement(Place[] a)
{
int count = 1;
int tempCount;
int popular = a[0].getType();
int temp = 0;
for (int i = 0; i < (a.length - 1); i++)
{
temp = a[i].getType();
tempCount = 0;
for (int j = 1; j < a.length; j++)
{
if (temp == a[j].getType())
tempCount++;
}
if (tempCount > count)
{
popular = temp;
count = tempCount;
}
}
return popular;
}
} }
\ No newline at end of file
...@@ -441,10 +441,15 @@ public class SaveFile { ...@@ -441,10 +441,15 @@ 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) {
items = line.split(" "); items = line.split(" ");
//Need to get other 2 places for(int i = 0; i < 3; i++) {
com.notificationFramework.sedentary.frontEnd.Place place = new com.notificationFramework.sedentary.frontEnd.Place( try {
items[2], Float.parseFloat(items[4]), Integer.parseInt(items[3])); com.notificationFramework.sedentary.frontEnd.Place place = new com.notificationFramework.sedentary.frontEnd.Place(
places.add(place); items[i + 2], Float.parseFloat(items[i + 4]), Integer.parseInt(items[i + 3]));
places.add(place);
}catch(NumberFormatException e){
}
}
} }
} }
}catch(IOException e){ }catch(IOException e){
......
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