Search in sources :

Example 1 with RouteSegment

use of cl.smartcities.isci.transportinspector.map.model.RouteSegment in project androidApp by InspectorIncognito.

the class GridHelper method getRouteSegmentInGrid.

private List<RouteSegment> getRouteSegmentInGrid(LinkedHashSet<Integer> indexes, String serviceWithDirection) {
    ArrayList<RouteSegment> routeSegments = new ArrayList<>(indexes.size());
    for (Integer index : indexes) {
        String segments = index + "," + (index + 1);
        List<ComparableLocation> segmentPoints = getRouteSegments(serviceWithDirection, segments);
        routeSegments.add(new RouteSegment(index, segmentPoints.get(0), segmentPoints.get(1)));
    }
    return routeSegments;
}
Also used : ArrayList(java.util.ArrayList) ComparableLocation(cl.smartcities.isci.transportinspector.map.model.ComparableLocation) RouteSegment(cl.smartcities.isci.transportinspector.map.model.RouteSegment)

Example 2 with RouteSegment

use of cl.smartcities.isci.transportinspector.map.model.RouteSegment in project androidApp by InspectorIncognito.

the class DirectionEngine method getNearestRouteSegment.

@Nullable
private RouteSegment getNearestRouteSegment(Location location, List<RouteSegment> segments) {
    if (segments.isEmpty()) {
        return null;
    }
    double minDistance = Double.MAX_VALUE;
    RouteSegment nearestSegment = null;
    for (RouteSegment segment : segments) {
        double distance = distanceToSegment(segment, location);
        if (minDistance > distance) {
            minDistance = distance;
            nearestSegment = segment;
        }
    }
    if (minDistance > 40) {
        return null;
    }
    return nearestSegment;
}
Also used : RouteSegment(cl.smartcities.isci.transportinspector.map.model.RouteSegment) Nullable(android.support.annotation.Nullable)

Example 3 with RouteSegment

use of cl.smartcities.isci.transportinspector.map.model.RouteSegment in project androidApp by InspectorIncognito.

the class DirectionEngine method getDetectedDirection.

public String getDetectedDirection(Location newLocation) {
    GridHelper helper = new GridHelper(TranSappApplication.getAppContext());
    if (previousLocation == null) {
        Pair<List<RouteSegment>, List<RouteSegment>> segments = helper.getRouteSegmentInGrid(service, newLocation);
        previousISegment = getNearestRouteSegment(newLocation, segments.first);
        previousRSegment = getNearestRouteSegment(newLocation, segments.second);
        previousLocation = newLocation;
        return null;
    }
    Pair<List<RouteSegment>, List<RouteSegment>> segments = helper.getRouteSegmentInGrid(service, newLocation);
    RouteSegment routeISegment = getNearestRouteSegment(newLocation, segments.first);
    RouteSegment routeRSegment = getNearestRouteSegment(newLocation, segments.second);
    iScores.add(getSegmentScore(previousISegment, routeISegment, previousLocation, newLocation));
    rScores.add(getSegmentScore(previousRSegment, routeRSegment, previousLocation, newLocation));
    Log.d("DirectionEngine", "i score: " + sumScore(iScores));
    Log.d("DirectionEngine", "r score: " + sumScore(rScores));
    Log.d("DirectionEngine", "--");
    if (iScores.size() > neededScores) {
        double iScore = (sumScore(iScores) * 1.0) / neededScores;
        double rScore = (sumScore(rScores) * 1.0) / neededScores;
        if (iScore >= 0.7 && rScore <= 0.3) {
            return "I";
        }
        if (rScore >= 0.7 && iScore <= 0.3) {
            return "R";
        }
        rScores.removeFirst();
        iScores.removeFirst();
    }
    previousISegment = routeISegment;
    previousRSegment = routeRSegment;
    previousLocation = newLocation;
    return null;
}
Also used : GridHelper(cl.smartcities.isci.transportinspector.database.GridHelper) List(java.util.List) LinkedList(java.util.LinkedList) RouteSegment(cl.smartcities.isci.transportinspector.map.model.RouteSegment)

Aggregations

RouteSegment (cl.smartcities.isci.transportinspector.map.model.RouteSegment)3 Nullable (android.support.annotation.Nullable)1 GridHelper (cl.smartcities.isci.transportinspector.database.GridHelper)1 ComparableLocation (cl.smartcities.isci.transportinspector.map.model.ComparableLocation)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1