package cl.smartcities.isci.transportinspector.onBusService.filters;

import android.util.Log;

import java.util.Collections;
import java.util.List;
import java.util.Locale;

import cl.smartcities.isci.transportinspector.onBusService.ActivityLocation;

/**
 * Created by Agustin on 2/11/2017.
 */

public class NestedLocationFilter {
    private static final String TAG = NestedLocationFilter.class.getSimpleName();
    private TemporalRansacFilter temporalFilter;
    private DistanceToRouteFilter routeFilter;
    private InstantVelocityFilter velocityFilter;


    public NestedLocationFilter(String route) {
        temporalFilter = new TemporalRansacFilter();
        routeFilter = new DistanceToRouteFilter(route);
        velocityFilter = new InstantVelocityFilter(200);
    }

    public List<ActivityLocation> filter(List<ActivityLocation> locations) {
        List<ActivityLocation> filteredTimeLocations = temporalFilter.filter(locations);

        if (filteredTimeLocations.size() < locations.size()*.4) {
            Log.d(TAG, String.format(Locale.getDefault(),
                    "TemporalRansacFilter: Filtered to many locations, original: %d, filtered %d",
                    locations.size(), filteredTimeLocations.size()));
            return Collections.emptyList();
        }

        List<ActivityLocation> filteredRouteLocations = routeFilter.filter(filteredTimeLocations);

        if (filteredRouteLocations.size() < filteredTimeLocations.size()*.4) {
            Log.d(TAG, String.format(Locale.getDefault(),
                    "DistanceToRouteFilter: Filtered to many locations, original: %d, filtered %d",
                    filteredTimeLocations.size(), filteredRouteLocations.size()));
            return Collections.emptyList();
        }

        return velocityFilter.filter(filteredRouteLocations);
    }
}
