package com.mobile.countme.framework;

import android.location.Location;

import java.util.ArrayList;

/**
 * Created by Kristian on 11/09/2015.
 * Renamed by Torgeir on 19/10/2015.
 */
public class GPSFilter {

    public static void filterTrip(ArrayList<Location> trip, ArrayList<Integer> modes){
        Location end = trip.get(trip.size() - 1);
        Location almostEnd;
        float accumulator = 0.0f;
        float lengthSegment;
        for(int i = trip.size() - 2; i >= 0; i --){
            almostEnd = trip.get(i);
            lengthSegment = almostEnd.distanceTo(end);
            if(lengthSegment < 20.0f){
                accumulator += lengthSegment;
            }
            if( accumulator < 100.0f){
                trip.remove(i + 1);
                modes.remove(i + 1);
            }
            else{
                break;
            }
            end = almostEnd;


        }
        Location start = trip.get(0);
        Location next;
        int lastIndex = 0;
        accumulator = 0.0f;
        for(int i = 1; i < trip.size(); i ++){
            next = trip.get(i);
            lengthSegment = start.distanceTo(next);
            if(lengthSegment < 20.0f){
                accumulator += lengthSegment;
            }
            if( accumulator > 100.0f){
                lastIndex = i - 1;
                break;
            }
            start = next;


        }
        for(int i = lastIndex; i >= 0; i--){
            trip.remove(i);
            modes.remove(i);
        }

    }

}

@@ -290,18 +290,19 @@
 %3E modes)
+ 
 %7B%0A
-
         
@@ -437,32 +437,33 @@
 ent;%0A        for
+ 
 (int i = trip.si
@@ -485,12 +485,12 @@
 0; i
- 
 --)
+ 
 %7B%0A  
@@ -585,32 +585,33 @@
 ;%0A            if
+ 
 (lengthSegment %3C
@@ -609,32 +609,33 @@
 Segment %3C 20.0f)
+ 
 %7B%0A              
@@ -684,51 +684,8 @@
   %7D%0A
-            if( accumulator %3C 100.0f)%7B%0A    
     
@@ -716,36 +716,32 @@
 1);%0A            
-    
 modes.remove(i +
@@ -737,32 +737,33 @@
 .remove(i + 1);%0A
+%0A
             %7D%0A  
@@ -762,26 +762,35 @@
     
-%7D%0A            else
+if (accumulator %3E= 100.0f) 
 %7B%0A  
@@ -984,32 +984,33 @@
 .0f;%0A        for
+ 
 (int i = 1; i %3C 
@@ -1027,12 +1027,12 @@
 ); i
- 
 ++)
+ 
 %7B%0A  
@@ -1127,16 +1127,17 @@
       if
+ 
 (lengthS
@@ -1147,24 +1147,25 @@
 ent %3C 20.0f)
+ 
 %7B%0A          
@@ -1374,16 +1374,17 @@
      for
+ 
 (int i =
@@ -1407,16 +1407,17 @@
  0; i--)
+ 
 %7B%0A      

correct indices for gps filter