Fix compilation errors
This commit is contained in:
parent
a43dae3a58
commit
461a54ece3
2 changed files with 185 additions and 355 deletions
|
@ -7,58 +7,185 @@ import net.osmand.render.RenderingRulesStorage;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class RouteStatisticsHelper {
|
||||
|
||||
public static final String UNDEFINED_ATTR = "undefined";
|
||||
private static final double H_STEP = 5;
|
||||
private static final double H_SLOPE_APPROX = 100;
|
||||
private static final int MIN_INCLINE = -100;
|
||||
private static final int MIN_DIVIDED_INCLINE = -20;
|
||||
private static final int MAX_INCLINE = 100;
|
||||
private static final int MAX_DIVIDED_INCLINE = 20;
|
||||
private static final int STEP = 4;
|
||||
private static final int NUM;
|
||||
private static final int[] BOUNDARIES_ARRAY;
|
||||
|
||||
static {
|
||||
NUM = ((MAX_DIVIDED_INCLINE - MIN_DIVIDED_INCLINE) / STEP) + 3;
|
||||
BOUNDARIES_ARRAY = new int[NUM];
|
||||
BOUNDARIES_ARRAY[0] = MIN_INCLINE;
|
||||
for (int i = 1; i < NUM - 1; i++) {
|
||||
BOUNDARIES_ARRAY[i] = MIN_DIVIDED_INCLINE + (i - 1) * STEP;
|
||||
}
|
||||
BOUNDARIES_ARRAY[NUM - 1] = MAX_INCLINE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class RouteStatistics {
|
||||
public final List<RouteSegmentAttribute> elements;
|
||||
public final Map<String, RouteSegmentAttribute> partition;
|
||||
public final float totalDistance;
|
||||
|
||||
private RouteStatistics(List<RouteSegmentAttribute> elements,
|
||||
Map<String, RouteSegmentAttribute> partition,
|
||||
float totalDistance) {
|
||||
this.elements = elements;
|
||||
this.partition = partition;
|
||||
this.totalDistance = totalDistance;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RouteSegmentWithIncline {
|
||||
RouteDataObject obj;
|
||||
float dist;
|
||||
float h;
|
||||
float[] interpolatedHeightByStep;
|
||||
float[] slopeByStep;
|
||||
}
|
||||
|
||||
public static List<RouteStatistics> calculateRouteStatistic(List<RouteSegmentResult> route, RenderingRulesStorage currentRenderer,
|
||||
RenderingRulesStorage defaultRenderer, RenderingRuleSearchRequest currentSearchRequest,
|
||||
RenderingRuleSearchRequest defaultSearchRequest) {
|
||||
List<RouteSegmentWithIncline> routeSegmentWithInclines = calculateInclineRouteSegments(route);
|
||||
List<String> attributeNames = new ArrayList<>();
|
||||
for (String s : currentRenderer.getRenderingAttributeNames()) {
|
||||
if (s.startsWith("routeInfo_")) {
|
||||
attributeNames.add(s);
|
||||
}
|
||||
}
|
||||
if(attributeNames.isEmpty()) {
|
||||
for (String s : defaultRenderer.getRenderingAttributeNames()) {
|
||||
if (s.startsWith("routeInfo_")) {
|
||||
attributeNames.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<RouteStatistics> result = new ArrayList<>();
|
||||
|
||||
String[] colorAttrNames = {"surfaceColor", "roadClassColor", "smoothnessColor"};
|
||||
|
||||
for (int i = 0; i < colorAttrNames.length; i++) {
|
||||
String colorAttrName = colorAttrNames[i];
|
||||
// "steepnessColor", "surfaceColor", "roadClassColor", "smoothnessColor"
|
||||
// steepness=-19_-16
|
||||
List<RouteStatistics> result = new ArrayList<>();
|
||||
for(String attributeName : attributeNames) {
|
||||
RouteStatisticComputer statisticComputer =
|
||||
new RouteStatisticComputer(route, colorAttrName, currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest);
|
||||
result.add(statisticComputer.computeStatistic());
|
||||
new RouteStatisticComputer(currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest);
|
||||
result.add(statisticComputer.computeStatistic(routeSegmentWithInclines, attributeName));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class RouteSegmentClass {
|
||||
private static List<RouteSegmentWithIncline> calculateInclineRouteSegments(List<RouteSegmentResult> route) {
|
||||
List<RouteSegmentWithIncline> input = new ArrayList<>();
|
||||
float prevHeight = 0;
|
||||
int totalArrayHeightsLength = 0;
|
||||
for(RouteSegmentResult r : route) {
|
||||
float[] heightValues = r.getHeightValues();
|
||||
RouteSegmentWithIncline incl = new RouteSegmentWithIncline();
|
||||
incl.dist = r.getDistance();
|
||||
incl.obj = r.getObject();
|
||||
input.add(incl);
|
||||
float prevH = prevHeight;
|
||||
int indStep = 0;
|
||||
if(incl.dist > H_STEP) {
|
||||
incl.interpolatedHeightByStep = new float[(int) (incl.dist / H_STEP) - 1];
|
||||
totalArrayHeightsLength += incl.interpolatedHeightByStep.length;
|
||||
}
|
||||
if(heightValues != null && heightValues.length > 0) {
|
||||
int indH = 2;
|
||||
float distCum = 0;
|
||||
prevH = heightValues[1];
|
||||
incl.h = prevH ;
|
||||
while(indStep < incl.interpolatedHeightByStep.length && indH < heightValues.length) {
|
||||
float dist = heightValues[indH] + distCum;
|
||||
if(dist > (indStep + 1) * H_STEP) {
|
||||
if(dist == distCum) {
|
||||
incl.interpolatedHeightByStep[indStep] = prevH;
|
||||
} else {
|
||||
incl.interpolatedHeightByStep[indStep] = (float) (prevH +
|
||||
((indStep + 1) * H_STEP - distCum) *
|
||||
(heightValues[indH + 1] - prevH) / (dist - distCum));
|
||||
}
|
||||
indStep++;
|
||||
} else {
|
||||
distCum = dist;
|
||||
prevH = heightValues[indH + 1];
|
||||
indH += 2;
|
||||
}
|
||||
}
|
||||
|
||||
String className;
|
||||
int color;
|
||||
} else {
|
||||
incl.h = prevH;
|
||||
}
|
||||
while(indStep < incl.interpolatedHeightByStep.length) {
|
||||
incl.interpolatedHeightByStep[indStep++] = prevH;
|
||||
}
|
||||
prevHeight = prevH;
|
||||
}
|
||||
int slopeSmoothShift = (int) (H_SLOPE_APPROX / (2 * H_STEP));
|
||||
float[] heightArray = new float[totalArrayHeightsLength];
|
||||
int iter = 0;
|
||||
for(int i = 0; i < input.size(); i ++) {
|
||||
RouteSegmentWithIncline rswi = input.get(i);
|
||||
for(int k = 0; rswi.interpolatedHeightByStep != null &&
|
||||
k < rswi.interpolatedHeightByStep.length; k++) {
|
||||
heightArray[iter++] = rswi.interpolatedHeightByStep[k];
|
||||
}
|
||||
}
|
||||
iter = 0;
|
||||
for(int i = 0; i < input.size(); i ++) {
|
||||
RouteSegmentWithIncline rswi = input.get(i);
|
||||
if(rswi.interpolatedHeightByStep != null) {
|
||||
rswi.slopeByStep = new float[rswi.interpolatedHeightByStep.length];
|
||||
for (int k = 0; k < rswi.slopeByStep.length; k++) {
|
||||
if (iter > slopeSmoothShift && iter + slopeSmoothShift < heightArray.length) {
|
||||
rswi.slopeByStep[k] =
|
||||
(float) ((heightArray[iter + slopeSmoothShift] - heightArray[iter - slopeSmoothShift]) * 100
|
||||
/ H_SLOPE_APPROX);
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
private static class RouteStatisticComputer {
|
||||
|
||||
final List<RouteSegmentResult> route;
|
||||
final String colorAttrName;
|
||||
final RenderingRulesStorage currentRenderer;
|
||||
final RenderingRulesStorage defaultRenderer;
|
||||
final RenderingRuleSearchRequest currentRenderingRuleSearchRequest;
|
||||
final RenderingRuleSearchRequest defaultRenderingRuleSearchRequest;
|
||||
|
||||
RouteStatisticComputer(List<RouteSegmentResult> route, String colorAttrName,
|
||||
RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer,
|
||||
RouteStatisticComputer(RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer,
|
||||
RenderingRuleSearchRequest currentRenderingRuleSearchRequest, RenderingRuleSearchRequest defaultRenderingRuleSearchRequest) {
|
||||
this.route = route;
|
||||
this.colorAttrName = colorAttrName;
|
||||
this.currentRenderer = currentRenderer;
|
||||
this.defaultRenderer = defaultRenderer;
|
||||
this.currentRenderingRuleSearchRequest = currentRenderingRuleSearchRequest;
|
||||
this.defaultRenderingRuleSearchRequest = defaultRenderingRuleSearchRequest;
|
||||
}
|
||||
|
||||
|
||||
public RouteStatistics computeStatistic(List<RouteSegmentWithIncline> route, String attribute) {
|
||||
List<RouteSegmentAttribute> routeAttributes = processRoute(route, attribute);
|
||||
Map<String, RouteSegmentAttribute> partition = makePartition(routeAttributes);
|
||||
float totalDistance = computeTotalDistance(routeAttributes);
|
||||
return new RouteStatistics(routeAttributes, partition, totalDistance);
|
||||
}
|
||||
|
||||
Map<String, RouteSegmentAttribute> makePartition(List<RouteSegmentAttribute> routeAttributes) {
|
||||
Map<String, RouteSegmentAttribute> partition = new TreeMap<>();
|
||||
for (RouteSegmentAttribute attribute : routeAttributes) {
|
||||
|
@ -80,58 +207,44 @@ public class RouteStatisticsHelper {
|
|||
return distance;
|
||||
}
|
||||
|
||||
protected List<RouteSegmentAttribute> processRoute() {
|
||||
int index = 0;
|
||||
protected List<RouteSegmentAttribute> processRoute(List<RouteSegmentWithIncline> route, String attribute) {
|
||||
List<RouteSegmentAttribute> routes = new ArrayList<>();
|
||||
RouteSegmentClass prev = null;
|
||||
for (RouteSegmentResult segment : route) {
|
||||
RouteSegmentClass current = getAttribute(segment);
|
||||
if (prev != null && prev.className != null && !prev.className.equals(current.className)) {
|
||||
index++;
|
||||
RouteSegmentAttribute prev = null;
|
||||
for (RouteSegmentWithIncline segment : route) {
|
||||
RouteSegmentAttribute current = classifySegment(attribute, segment);
|
||||
if (prev != null && prev.getPropertyName() != null &&
|
||||
prev.getPropertyName().equals(current.getPropertyName())) {
|
||||
prev.incrementDistanceBy(current.distance);
|
||||
} else {
|
||||
routes.add(current);
|
||||
prev = current;
|
||||
}
|
||||
if (index >= routes.size()) {
|
||||
routes.add(new RouteSegmentAttribute(index, current.className, current.color));
|
||||
}
|
||||
RouteSegmentAttribute surface = routes.get(index);
|
||||
surface.incrementDistanceBy(segment.getDistance());
|
||||
prev = current;
|
||||
}
|
||||
return routes;
|
||||
}
|
||||
|
||||
RouteStatistics computeStatistic() {
|
||||
List<RouteSegmentAttribute> routeAttributes = processRoute();
|
||||
Map<String, RouteSegmentAttribute> partition = makePartition(routeAttributes);
|
||||
float totalDistance = computeTotalDistance(routeAttributes);
|
||||
return new RouteStatistics(routeAttributes, partition, totalDistance);
|
||||
}
|
||||
|
||||
RenderingRuleSearchRequest getSearchRequest(boolean useCurrentRenderer) {
|
||||
return new RenderingRuleSearchRequest(useCurrentRenderer ? currentRenderingRuleSearchRequest : defaultRenderingRuleSearchRequest);
|
||||
}
|
||||
|
||||
public RouteSegmentClass getAttribute(RouteSegmentResult segment) {
|
||||
RenderingRuleSearchRequest currentRequest = getSearchRequest(true);
|
||||
RouteSegmentClass res = new RouteSegmentClass();
|
||||
res.className = UNDEFINED_ATTR;
|
||||
if (searchRenderingAttribute(currentRenderer, currentRequest, segment)) {
|
||||
|
||||
res.className = currentRequest.getStringPropertyValue(currentRenderer.PROPS.R_ATTR_STRING_VALUE);
|
||||
res.color = currentRequest.getIntPropertyValue(currentRenderer.PROPS.R_ATTR_COLOR_VALUE);
|
||||
public RouteSegmentAttribute classifySegment(String attribute, RouteSegmentWithIncline segment) {
|
||||
RouteSegmentAttribute res = new RouteSegmentAttribute(UNDEFINED_ATTR, 0);
|
||||
RenderingRuleSearchRequest currentRequest = new RenderingRuleSearchRequest(currentRenderingRuleSearchRequest);
|
||||
if (searchRenderingAttribute(attribute, currentRenderer, currentRequest, segment)) {
|
||||
res = new RouteSegmentAttribute(currentRequest.getStringPropertyValue(currentRenderer.PROPS.R_ATTR_STRING_VALUE),
|
||||
currentRequest.getIntPropertyValue(currentRenderer.PROPS.R_ATTR_COLOR_VALUE));
|
||||
} else {
|
||||
RenderingRuleSearchRequest defaultRequest = getSearchRequest(false);
|
||||
if (searchRenderingAttribute(defaultRenderer, defaultRequest, segment)) {
|
||||
res = new RouteSegmentClass();
|
||||
res.className = defaultRequest.getStringPropertyValue(defaultRenderer.PROPS.R_ATTR_STRING_VALUE);
|
||||
res.color = defaultRequest.getIntPropertyValue(defaultRenderer.PROPS.R_ATTR_COLOR_VALUE);
|
||||
RenderingRuleSearchRequest defaultRequest = new RenderingRuleSearchRequest(defaultRenderingRuleSearchRequest);
|
||||
if (searchRenderingAttribute(attribute, defaultRenderer, defaultRequest, segment)) {
|
||||
res = new RouteSegmentAttribute(defaultRequest.getStringPropertyValue(defaultRenderer.PROPS.R_ATTR_STRING_VALUE),
|
||||
defaultRequest.getIntPropertyValue(defaultRenderer.PROPS.R_ATTR_COLOR_VALUE));
|
||||
}
|
||||
}
|
||||
res.distance = segment.dist;
|
||||
return res;
|
||||
}
|
||||
|
||||
protected boolean searchRenderingAttribute(RenderingRulesStorage rrs, RenderingRuleSearchRequest req, RouteSegmentResult segment) {
|
||||
protected boolean searchRenderingAttribute(String attribute,
|
||||
RenderingRulesStorage rrs, RenderingRuleSearchRequest req, RouteSegmentWithIncline segment) {
|
||||
//String additional = attrName + "=" + attribute;
|
||||
RouteDataObject obj = segment.getObject();
|
||||
RouteDataObject obj = segment.obj;
|
||||
int[] tps = obj.getTypes();
|
||||
String additional = "";
|
||||
for (int k = 0; k < tps.length; k++) {
|
||||
|
@ -148,126 +261,34 @@ public class RouteStatisticsHelper {
|
|||
}
|
||||
}
|
||||
req.setStringFilter(rrs.PROPS.R_ADDITIONAL, additional);
|
||||
return req.searchRenderingAttribute(colorAttrName);
|
||||
return req.searchRenderingAttribute(attribute);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static class RouteBoundariesStatisticComputer extends RouteStatisticComputer {
|
||||
|
||||
private final List<Incline> inclines;
|
||||
|
||||
public RouteBoundariesStatisticComputer(List<Incline> inclines, String colorAttrName,
|
||||
RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer,
|
||||
RenderingRuleSearchRequest currentSearchRequest, RenderingRuleSearchRequest defaultSearchRequest) {
|
||||
super(null, colorAttrName, currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest);
|
||||
this.inclines = inclines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RouteSegmentAttribute> processRoute() {
|
||||
List<RouteSegmentAttribute> routeInclines = new ArrayList<>();
|
||||
int index = 0;
|
||||
Boundaries prev = null;
|
||||
Incline prevIncline = null;
|
||||
for (Incline incline : inclines) {
|
||||
Boundaries current = incline.getBoundaries();
|
||||
if (prev != null && !prev.equals(current)) {
|
||||
index++;
|
||||
}
|
||||
if (index >= routeInclines.size()) {
|
||||
String propertyName = getPropertyName(current);
|
||||
int color = 0;//getColor(current);
|
||||
RouteSegmentAttribute attribute = new RouteSegmentAttribute(index, propertyName, color);
|
||||
if (prevIncline != null) {
|
||||
attribute.setInitDistance(prevIncline.getDistance());
|
||||
}
|
||||
routeInclines.add(attribute);
|
||||
}
|
||||
RouteSegmentAttribute routeIncline = routeInclines.get(index);
|
||||
routeIncline.relativeSum(incline.getDistance());
|
||||
prev = current;
|
||||
prevIncline = incline;
|
||||
}
|
||||
return routeInclines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RouteSegmentClass getAttribute(RouteSegmentResult segment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getPropertyName(Boundaries attribute) {
|
||||
int lowerBoundary = Math.round(attribute.getLowerBoundary());
|
||||
int upperBoundary = Math.round(attribute.getUpperBoundary());
|
||||
if (lowerBoundary >= Boundaries.MIN_DIVIDED_INCLINE) {
|
||||
lowerBoundary++;
|
||||
}
|
||||
return String.format(Locale.US, "%d%% ... %d%%", lowerBoundary, upperBoundary);
|
||||
}
|
||||
|
||||
public boolean searchRenderingAttribute(RenderingRulesStorage rrs, RenderingRuleSearchRequest req, Boundaries attribute) {
|
||||
int lowerBoundary = Math.round(attribute.getLowerBoundary());
|
||||
int upperBoundary = Math.round(attribute.getUpperBoundary());
|
||||
StringBuilder range = new StringBuilder();
|
||||
if (lowerBoundary >= Boundaries.MIN_DIVIDED_INCLINE) {
|
||||
lowerBoundary++;
|
||||
} else {
|
||||
lowerBoundary = Boundaries.MIN_INCLINE;
|
||||
}
|
||||
if (upperBoundary > Boundaries.MAX_DIVIDED_INCLINE) {
|
||||
upperBoundary = Boundaries.MAX_INCLINE;
|
||||
}
|
||||
range.append(lowerBoundary);
|
||||
range.append(upperBoundary < 0 ? "_" : "-");
|
||||
range.append(upperBoundary);
|
||||
//String additional = attrName + "=" + range;
|
||||
//req.setStringFilter(rrs.PROPS.R_ADDITIONAL, additional);
|
||||
return req.searchRenderingAttribute(colorAttrName);
|
||||
}
|
||||
}
|
||||
|
||||
public static class RouteSegmentAttribute {
|
||||
|
||||
private final int index;
|
||||
private final int color;
|
||||
private final String propertyName;
|
||||
|
||||
private float distance;
|
||||
private float initDistance;
|
||||
|
||||
RouteSegmentAttribute(int index, String propertyName, int color) {
|
||||
this.index = index;
|
||||
RouteSegmentAttribute(String propertyName, int color) {
|
||||
this.propertyName = propertyName;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
RouteSegmentAttribute(RouteSegmentAttribute segmentAttribute) {
|
||||
this.index = segmentAttribute.getIndex();
|
||||
this.propertyName = segmentAttribute.getPropertyName();
|
||||
this.color = segmentAttribute.getColor();
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public float getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public void setInitDistance(float initDistance) {
|
||||
this.initDistance = initDistance;
|
||||
}
|
||||
|
||||
public void incrementDistanceBy(float distance) {
|
||||
this.distance += distance;
|
||||
}
|
||||
|
||||
public void relativeSum(float distance) {
|
||||
this.distance = this.distance + ((distance - this.initDistance) - this.distance);
|
||||
}
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
@ -279,162 +300,12 @@ public class RouteStatisticsHelper {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "RouteSegmentAttribute{" +
|
||||
"index=" + index +
|
||||
", propertyName='" + propertyName + '\'' +
|
||||
"propertyName='" + propertyName + '\'' +
|
||||
", color='" + color + '\'' +
|
||||
", distance=" + distance +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class Incline {
|
||||
|
||||
private final float inclineValue;
|
||||
private final float distance;
|
||||
private Boundaries boundaries;
|
||||
|
||||
public Incline(float inclineValue, float distance) {
|
||||
this.inclineValue = inclineValue;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public void computeBoundaries(float minIncline, float maxIncline) {
|
||||
this.boundaries = Boundaries.newBoundariesFor(inclineValue, minIncline, maxIncline);
|
||||
}
|
||||
|
||||
public float getValue() {
|
||||
return inclineValue;
|
||||
}
|
||||
|
||||
public float getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public Boundaries getBoundaries() {
|
||||
return this.boundaries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Incline{" +
|
||||
", incline=" + inclineValue +
|
||||
", distance=" + distance +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class Boundaries implements Comparable<Boundaries> {
|
||||
|
||||
private static final int MIN_INCLINE = -100;
|
||||
private static final int MIN_DIVIDED_INCLINE = -20;
|
||||
private static final int MAX_INCLINE = 100;
|
||||
private static final int MAX_DIVIDED_INCLINE = 20;
|
||||
private static final int STEP = 4;
|
||||
private static final int NUM;
|
||||
private static final int[] BOUNDARIES_ARRAY;
|
||||
|
||||
static {
|
||||
NUM = ((MAX_DIVIDED_INCLINE - MIN_DIVIDED_INCLINE) / STEP) + 3;
|
||||
BOUNDARIES_ARRAY = new int[NUM];
|
||||
BOUNDARIES_ARRAY[0] = MIN_INCLINE;
|
||||
for (int i = 1; i < NUM - 1; i++) {
|
||||
BOUNDARIES_ARRAY[i] = MIN_DIVIDED_INCLINE + (i - 1) * STEP;
|
||||
}
|
||||
BOUNDARIES_ARRAY[NUM - 1] = MAX_INCLINE;
|
||||
}
|
||||
|
||||
private final float upperBoundary;
|
||||
private final float lowerBoundary;
|
||||
|
||||
private Boundaries(float upperBoundary, float lowerBoundary) {
|
||||
this.upperBoundary = upperBoundary;
|
||||
this.lowerBoundary = lowerBoundary;
|
||||
}
|
||||
|
||||
public static Boundaries newBoundariesFor(float incline, float minIncline, float maxIncline) {
|
||||
int maxRoundedIncline = Math.round(maxIncline);
|
||||
int minRoundedIncline = Math.round(minIncline);
|
||||
if (incline > MAX_INCLINE) {
|
||||
return new Boundaries(MAX_INCLINE, MAX_DIVIDED_INCLINE);
|
||||
}
|
||||
if (incline < MIN_INCLINE) {
|
||||
return new Boundaries(MIN_DIVIDED_INCLINE, MIN_INCLINE);
|
||||
}
|
||||
for (int i = 1; i < NUM; i++) {
|
||||
if (incline >= BOUNDARIES_ARRAY[i - 1] && incline < BOUNDARIES_ARRAY[i]) {
|
||||
if (i == 1) {
|
||||
return new Boundaries(BOUNDARIES_ARRAY[i], minRoundedIncline);
|
||||
} else if (i == NUM - 1) {
|
||||
return new Boundaries(maxRoundedIncline, BOUNDARIES_ARRAY[i - 1]);
|
||||
} else {
|
||||
return new Boundaries(BOUNDARIES_ARRAY[i], BOUNDARIES_ARRAY[i - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public float getUpperBoundary() {
|
||||
return upperBoundary;
|
||||
}
|
||||
|
||||
public float getLowerBoundary() {
|
||||
return lowerBoundary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Boundaries that = (Boundaries) o;
|
||||
|
||||
if (Float.compare(that.upperBoundary, upperBoundary) != 0) return false;
|
||||
return Float.compare(that.lowerBoundary, lowerBoundary) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (upperBoundary != +0.0f ? Float.floatToIntBits(upperBoundary) : 0);
|
||||
result = 31 * result + (lowerBoundary != +0.0f ? Float.floatToIntBits(lowerBoundary) : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Boundaries boundaries) {
|
||||
return (int) (getLowerBoundary() - boundaries.getLowerBoundary());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(Locale.US, "%d%% ... %d%%", Math.round(getLowerBoundary()), Math.round(getUpperBoundary()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class RouteStatistics {
|
||||
|
||||
private final List<RouteSegmentAttribute> elements;
|
||||
private final Map<String, RouteSegmentAttribute> partition;
|
||||
private final float totalDistance;
|
||||
|
||||
private RouteStatistics(List<RouteSegmentAttribute> elements,
|
||||
Map<String, RouteSegmentAttribute> partition,
|
||||
float totalDistance) {
|
||||
this.elements = elements;
|
||||
this.partition = partition;
|
||||
this.totalDistance = totalDistance;
|
||||
}
|
||||
|
||||
public float getTotalDistance() {
|
||||
return totalDistance;
|
||||
}
|
||||
|
||||
public List<RouteSegmentAttribute> getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public Map<String, RouteSegmentAttribute> getPartition() {
|
||||
return partition;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -89,7 +89,6 @@ import net.osmand.render.RenderingRuleSearchRequest;
|
|||
import net.osmand.render.RenderingRulesStorage;
|
||||
import net.osmand.router.RouteSegmentResult;
|
||||
import net.osmand.router.RouteStatisticsHelper;
|
||||
import net.osmand.router.RouteStatisticsHelper.Incline;
|
||||
import net.osmand.router.RouteStatisticsHelper.RouteStatistics;
|
||||
import net.osmand.router.TransportRoutePlanner.TransportRouteResult;
|
||||
import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment;
|
||||
|
@ -363,34 +362,24 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
|
|||
buildRowDivider(cardsContainer, false);
|
||||
slopeDataSet = statisticCard.getSlopeDataSet();
|
||||
elevationDataSet = statisticCard.getElevationDataSet();
|
||||
if (gpx.hasAltitude) {
|
||||
List<RouteSegmentResult> route = app.getRoutingHelper().getRoute().getOriginalRoute();
|
||||
if (route != null) {
|
||||
RenderingRulesStorage currentRenderer = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||
RenderingRulesStorage defaultRender = app.getRendererRegistry().defaultRender();
|
||||
|
||||
MapRenderRepositories maps = app.getResourceManager().getRenderer();
|
||||
RenderingRuleSearchRequest currentSearchRequest = maps.getSearchRequestWithAppliedCustomRules(currentRenderer, isNightMode());
|
||||
RenderingRuleSearchRequest defaultSearchRequest = maps.getSearchRequestWithAppliedCustomRules(defaultRender, isNightMode());
|
||||
List<RouteSegmentResult> route = app.getRoutingHelper().getRoute().getOriginalRoute();
|
||||
if (route != null) {
|
||||
RenderingRulesStorage currentRenderer = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||
RenderingRulesStorage defaultRender = app.getRendererRegistry().defaultRender();
|
||||
|
||||
List<RouteStatistics> routeStatistics = RouteStatisticsHelper.calculateRouteStatistic(route, currentRenderer, defaultRender, currentSearchRequest, defaultSearchRequest);
|
||||
GPXTrackAnalysis analysis = gpx.getAnalysis(0);
|
||||
MapRenderRepositories maps = app.getResourceManager().getRenderer();
|
||||
RenderingRuleSearchRequest currentSearchRequest = maps.getSearchRequestWithAppliedCustomRules(currentRenderer, isNightMode());
|
||||
RenderingRuleSearchRequest defaultSearchRequest = maps.getSearchRequestWithAppliedCustomRules(defaultRender, isNightMode());
|
||||
|
||||
for (RouteStatistics statistic : routeStatistics) {
|
||||
RouteInfoCard routeClassCard = new RouteInfoCard(mapActivity, statistic, analysis);
|
||||
addRouteCard(cardsContainer, routeClassCard);
|
||||
}
|
||||
List<RouteStatistics> routeStatistics = RouteStatisticsHelper.calculateRouteStatistic(route,
|
||||
currentRenderer, defaultRender, currentSearchRequest, defaultSearchRequest);
|
||||
GPXTrackAnalysis analysis = gpx.getAnalysis(0);
|
||||
|
||||
/*
|
||||
if (slopeDataSet != null) {
|
||||
List<Incline> inclines = createInclinesAndAdd100MetersWith0Incline(slopeDataSet.getValues(), slopeDataSet.getDivX());
|
||||
RouteInfoCard routeSteepnessCard = new RouteInfoCard(mapActivity, routeStatistics.getRouteSteepnessStatistic(inclines), analysis);
|
||||
addRouteCard(cardsContainer, routeSteepnessCard);
|
||||
}
|
||||
|
||||
RouteInfoCard routeSmoothnessCard = new RouteInfoCard(mapActivity, routeStatistics.getRouteSmoothnessStatistic(), analysis);
|
||||
addRouteCard(cardsContainer, routeSmoothnessCard);
|
||||
*/
|
||||
for (RouteStatistics statistic : routeStatistics) {
|
||||
RouteInfoCard routeClassCard = new RouteInfoCard(mapActivity, statistic, analysis);
|
||||
addRouteCard(cardsContainer, routeClassCard);
|
||||
}
|
||||
}
|
||||
routeDetailsMenu = new RouteDetailsMenu();
|
||||
|
@ -1519,36 +1508,6 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
|
|||
((LinearLayout) view).addView(horizontalLine);
|
||||
}
|
||||
|
||||
private List<Incline> createInclinesAndAdd100MetersWith0Incline(List<Entry> entries, float divX) {
|
||||
float minIncline = 0;
|
||||
float maxIncline = 0;
|
||||
int size = entries.size();
|
||||
List<Incline> inclines = new ArrayList<>();
|
||||
for (Entry entry : entries) {
|
||||
float inclineValue = entry.getY();
|
||||
maxIncline = Math.max(inclineValue, maxIncline);
|
||||
minIncline = Math.min(inclineValue, minIncline);
|
||||
|
||||
Incline incline = new Incline(inclineValue, entry.getX() * divX);
|
||||
inclines.add(incline);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
float distance = i * 5;
|
||||
inclines.add(i, new Incline(0f, distance));
|
||||
}
|
||||
if (slopeDataSet != null) {
|
||||
float lastDistance = slopeDataSet.getEntryForIndex(size - 1).getX();
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
float distance = lastDistance * divX + i * 5f;
|
||||
inclines.add(new Incline(0f, distance));
|
||||
}
|
||||
}
|
||||
for (Incline incline : inclines) {
|
||||
incline.computeBoundaries(minIncline, maxIncline);
|
||||
}
|
||||
return inclines;
|
||||
}
|
||||
|
||||
private void makeGpx() {
|
||||
OsmandApplication app = requireMyApplication();
|
||||
gpx = GpxUiHelper.makeGpxFromRoute(app.getRoutingHelper().getRoute(), app);
|
||||
|
|
Loading…
Reference in a new issue