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;
}
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;
}
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;
}
Aggregations