Skip to content

Commit

Permalink
Merge branch 'master' into rzr-click
Browse files Browse the repository at this point in the history
# Conflicts:
#	OsmAnd/res/values-de/phrases.xml
  • Loading branch information
Chumva committed Dec 2, 2024
2 parents 5c48f8d + 4df7169 commit 8e051f4
Show file tree
Hide file tree
Showing 139 changed files with 1,678 additions and 1,245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ public String getDestinationRef(String lang, boolean transliterate, boolean dire
int k = kt[i];
if (region.routeEncodingRules.size() > k) {
if (refTag.equals(region.routeEncodingRules.get(k).getTag())) {
return names.get(k);
return Algorithms.splitAndClearRepeats(names.get(k), ";");
}
if (refTagDefault.equals(region.routeEncodingRules.get(k).getTag())) {
refDefault = names.get(k);
}
}
}
if (refDefault != null) {
return refDefault;
return Algorithms.splitAndClearRepeats(refDefault, ";");
}
//return names.get(region.refTypeRule);
}
Expand Down
4 changes: 4 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/router/ExitInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public String getExitStreetName() {
public void setExitStreetName(String exitStreetName) {
this.exitStreetName = exitStreetName;
}

public boolean isEmpty() {
return ref == null && exitStreetName == null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ public void addTurnInfoDescriptions(List<RouteSegmentResult> result) {
if (!Algorithms.isEmpty(nm) || !Algorithms.isEmpty(ref)) {
streetName = String.format("onto %s %s " , nm, ref);
}
String to = result.get(prevSegment + 1).getDestinationName("", false, result, prevSegment + 1);
String to = result.get(prevSegment + 1).getDestinationName("", false, result, prevSegment + 1, true);
if(!Algorithms.isEmpty(to)) {
streetName = "to " + to;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ public String toString() {
return object.toString() + ": " + startPointIndex + "-" + endPointIndex;
}

public String getDestinationName(String lang, boolean transliterate, List<RouteSegmentResult> list, int routeInd) {
public String getDestinationName(String lang, boolean transliterate, List<RouteSegmentResult> list, int routeInd, boolean withRef) {
String dnRef = getObject().getDestinationRef(lang, transliterate, isForwardDirection());
String destinationName = getObject().getDestinationName(lang, transliterate, isForwardDirection());
if (Algorithms.isEmpty(destinationName)) {
Expand All @@ -678,10 +678,12 @@ public String getDestinationName(String lang, boolean transliterate, List<RouteS
}
}
}
if (!Algorithms.isEmpty(dnRef) && !Algorithms.isEmpty(destinationName)) {
destinationName = dnRef + ", " + destinationName;
} else if (!Algorithms.isEmpty(dnRef) && Algorithms.isEmpty(destinationName)) {
destinationName = dnRef;
if (withRef) {
if (!Algorithms.isEmpty(dnRef) && !Algorithms.isEmpty(destinationName)) {
destinationName = dnRef + ", " + destinationName;
} else if (!Algorithms.isEmpty(dnRef) && Algorithms.isEmpty(destinationName)) {
destinationName = dnRef;
}
}
return destinationName;
}
Expand Down
16 changes: 16 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java
Original file line number Diff line number Diff line change
Expand Up @@ -1349,4 +1349,20 @@ public static String[] deserializeStringArray(String serialized, String delimite
return resultList.toArray(new String[resultList.size()]);
}

public static String splitAndClearRepeats(String ref, String symbol) {
String[] arr = ref.split(symbol);
String res = "";
String prev = "";
for (String s : arr) {
if (Algorithms.isEmpty(s) || prev.equals(s))
continue;
if (!res.isEmpty()) {
res += symbol;
}
res += s;
prev = s;
}
return res;
}

}
44 changes: 26 additions & 18 deletions OsmAnd-java/src/test/java/net/osmand/router/RouteTestingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public void testRouting() throws Exception {
List<RouteSegmentResult> routeSegments = fe.searchRoute(ctx, te.getStartPoint(), te.getEndPoint(),
te.getTransitPoint()).detailed;
Set<Long> reachedSegments = new TreeSet<Long>();
Set<String> reachedSegmentPoints = new TreeSet<>();
Assert.assertNotNull(routeSegments);
int prevSegment = -1;
for (int i = 0; i <= routeSegments.size(); i++) {
Expand All @@ -159,7 +160,13 @@ public void testRouting() throws Exception {
prevSegment = i;
}
if (i < routeSegments.size()) {
reachedSegments.add(routeSegments.get(i).getObject().getId() >> (RouteResultPreparation.SHIFT_ID));
RouteSegmentResult seg = routeSegments.get(i);
long id = seg.getObject().getId() >> RouteResultPreparation.SHIFT_ID;
for (int point = Math.min(seg.getStartPointIndex(), seg.getEndPointIndex());
point <= Math.max(seg.getStartPointIndex(), seg.getEndPointIndex()); point++) {
reachedSegmentPoints.add(id + ":" + point);
}
reachedSegments.add(id);
}
}
Map<String, String> expectedResults = te.getExpectedResults();
Expand All @@ -170,32 +177,33 @@ public void testRouting() throws Exception {
checkRoutingTime(ctx, params);
for (Entry<String, String> es : expectedResults.entrySet()) {
long id = RouterUtilTest.getRoadId(es.getKey());
int point = RouterUtilTest.getRoadStartPoint(es.getKey());
String pointInSegment = id + ":" + point;
switch (es.getValue()) {
case "false":
Assert.assertFalse("Expected segment " + id + " was wrongly reached in route segments "
+ reachedSegments, reachedSegments.contains(id));
if (point == -1) {
Assert.assertFalse("Expected segment " + id + " was wrongly reached in route segments "
+ reachedSegments, reachedSegments.contains(id));
} else {
Assert.assertTrue("Unexpected pointInSegment " + pointInSegment + " is found in "
+ reachedSegmentPoints, !reachedSegmentPoints.contains(pointInSegment));
}
break;
case "true":
Assert.assertTrue("Expected segment " + id + " weren't reached in route segments "
+ reachedSegments, reachedSegments.contains(id));
if (point == -1) {
Assert.assertTrue("Expected segment " + id + " weren't reached in route segments "
+ reachedSegments, reachedSegments.contains(id));
} else {
Assert.assertTrue("Expected pointInSegment " + pointInSegment + " is not found in "
+ reachedSegmentPoints, reachedSegmentPoints.contains(pointInSegment));
}
break;
case "visitedSegments":
Assert.assertTrue("Expected segments visit " + id + " less then actually visited segments "
+ ctx.getVisitedSegments(), ctx.getVisitedSegments() < id);
break;
default: // case ID:N to check exact point within the ID's segment
boolean isFound = false;
int point = Integer.parseInt(es.getValue());
for (RouteSegmentResult seg : routeSegments) {
if (seg.getObject().getId() / 64 == id) {
if (point >= Math.min(seg.getStartPointIndex(), seg.getEndPointIndex()) &&
point <= Math.max(seg.getStartPointIndex(), seg.getEndPointIndex())) {
isFound = true;
break;
}
}
}
Assert.assertTrue("Expected point " + point + " is not found in segment " + id, isFound);
default:
Assert.assertTrue("Invalid key " + es.getKey() + " value " + es.getValue(), false);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TrackFolderLoaderTask(
if (!shouldLoadFolder(cachedRootFolder)) return cachedRootFolder!!

val start = currentTimeMillis()
log.info("Start loading tracks in ${folder.getDirName()}")
log.info("Start loading tracks in ${folder.getDirName(true)}")

folder.clearData()
loadingTime = currentTimeMillis()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import net.osmand.shared.gpx.filters.TrackFolderAnalysis

interface ComparableTracksGroup {
fun getFolderAnalysis(): TrackFolderAnalysis
fun getDirName(): String
fun getDirName(includingSubdirs: Boolean): String
fun lastModified(): Long
fun getDefaultOrder(): Int = -1
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import net.osmand.shared.util.KCollectionUtils

@Serializable
class SmartFolder(@Serializable var folderName: String) : TracksGroup, ComparableTracksGroup {
companion object {
const val ID_PREFIX = "SMART_FOLDER___"
}

@Transient
private var trackItems: List<TrackItem>? = null
Expand All @@ -25,6 +28,10 @@ class SmartFolder(@Serializable var folderName: String) : TracksGroup, Comparabl
@Transient
private var folderAnalysis: TrackFolderAnalysis? = null

override fun getId(): String {
return ID_PREFIX + folderName
}

override fun getName() = folderName

override fun getTrackItems(): List<TrackItem> {
Expand Down Expand Up @@ -52,7 +59,7 @@ class SmartFolder(@Serializable var folderName: String) : TracksGroup, Comparabl
return analysis
}

override fun getDirName() = folderName
override fun getDirName(includingSubdirs: Boolean) = folderName

override fun lastModified() = creationTime

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import net.osmand.shared.gpx.TrackItem
import net.osmand.shared.gpx.filters.TrackFolderAnalysis
import net.osmand.shared.io.KFile
import net.osmand.shared.util.KAlgorithms
import net.osmand.shared.util.KCollectionUtils
import kotlin.math.max

class TrackFolder(dirFile: KFile, parentFolder: TrackFolder?) :
Expand Down Expand Up @@ -37,6 +36,8 @@ class TrackFolder(dirFile: KFile, parentFolder: TrackFolder?) :
lastModified = folder.lastModified
}

override fun getId() = relativePath

override fun getName(): String {
return GpxHelper.getFolderName(dirFile, false)
}
Expand All @@ -50,15 +51,21 @@ class TrackFolder(dirFile: KFile, parentFolder: TrackFolder?) :
}

val relativePath: String
get() {
val dirName = getDirName()
val parentFolder = getParentFolder()
return if (parentFolder != null && !parentFolder.isRootFolder) parentFolder.relativePath + "/" + dirName else dirName
}
get() =
if (!isRootFolder) {
val dirName = dirFile.name()
val parent = getParentFolder()
if (parent?.isRootFolder == false) parent.relativePath + "/" + dirName else dirName
} else {
""
}


val isRootFolder: Boolean
get() = getParentFolder() == null

fun getRootFolder(): TrackFolder = getParentFolder()?.getRootFolder() ?: this

fun getParentFolder(): TrackFolder? {
return parentFolder
}
Expand Down Expand Up @@ -144,8 +151,8 @@ class TrackFolder(dirFile: KFile, parentFolder: TrackFolder?) :
return analysis
}

override fun getDirName(): String {
return dirFile.name()
override fun getDirName(includingSubdirs: Boolean): String {
return if (includingSubdirs) relativePath else dirFile.name()
}

fun getLastModified(): Long {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package net.osmand.shared.gpx.data
import net.osmand.shared.gpx.TrackItem

interface TracksGroup {
fun getId(): String

fun getName(): String

fun getTrackItems(): List<TrackItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TrackFolderAnalysis(folder: TracksGroup) {
timeSpan = timeSpanSum.toInt()
tracksCount = items.size

log.info(">>>> ${folder.getName()} = (tracks: $tracksCount, totalDistance: ${"%.2f".format(totalDistance)}, " +
log.info(">>>> ${folder.getId()} = (tracks: $tracksCount, totalDistance: ${"%.2f".format(totalDistance)}, " +
"timeSpan: $timeSpan, fileSize: $fileSize, diffElevationUp: ${"%.2f".format(diffElevationUp)}, diffElevationDown: ${"%.2f".format(diffElevationDown)}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ import net.osmand.shared.util.Localization
import net.osmand.shared.util.PlatformUtil


private const val FUEL_CONSUMPTION_DEFAULT_AVERAGE_TIME = 5 * 60

object OBDDataComputer {

private const val LITER_KM_CONSUMPTION_LIMIT = 100
private const val LITER_HOUR_CONSUMPTION_LIMIT = 100

private val log = LoggerFactory.getLogger("OBDDataComputer")

private val osmAndSettings: SettingsAPI = PlatformUtil.getOsmAndContext().getSettings()
Expand Down Expand Up @@ -117,17 +122,18 @@ object OBDDataComputer {
val locationNeeded: Boolean,
val requiredCommand: OBDCommand,
val nameId: String,
val formatter: OBDComputerWidgetFormatter
val formatter: OBDComputerWidgetFormatter,
val defaultAverageTime: Int = 0
) {
SPEED(
false,
OBD_SPEED_COMMAND,
"shared_string_speed",
"obd_widget_vehicle_speed",
OBDComputerWidgetFormatter("%.0f")),
RPM(
false,
OBD_RPM_COMMAND,
"obd_rpm",
"obd_widget_engine_speed",
OBDComputerWidgetFormatter("%d")),
ENGINE_RUNTIME(
false,
Expand All @@ -142,7 +148,7 @@ object OBDDataComputer {
FUEL_LEFT_KM(
true,
OBD_FUEL_LEVEL_COMMAND,
"obd_fuel_left_distance",
"remaining_fuel",
OBDComputerWidgetFormatter("%.0f")),
CALCULATED_ENGINE_LOAD(
false,
Expand All @@ -157,25 +163,28 @@ object OBDDataComputer {
FUEL_LEFT_PERCENT(
false,
OBD_FUEL_LEVEL_COMMAND,
"obd_fuel_left_percent",
"remaining_fuel",
OBDComputerWidgetFormatter("%.1f")),
FUEL_LEFT_LITER(
false,
OBD_FUEL_LEVEL_COMMAND,
"obd_fuel_left_liter",
"remaining_fuel",
OBDComputerWidgetFormatter("%.1f")),
FUEL_CONSUMPTION_RATE_PERCENT_HOUR(
false,
OBD_FUEL_LEVEL_COMMAND,
"obd_fuel_consumption_rate_percent_hour", OBDComputerWidgetFormatter("%.1f")),
"obd_fuel_consumption_rate_percent_hour", OBDComputerWidgetFormatter("%.1f"),
FUEL_CONSUMPTION_DEFAULT_AVERAGE_TIME),
FUEL_CONSUMPTION_RATE_LITER_KM(
true,
OBD_FUEL_LEVEL_COMMAND,
"obd_fuel_consumption_rate_l_km", OBDComputerWidgetFormatter("%.1f")),
"obd_fuel_consumption_rate_l_km", OBDComputerWidgetFormatter("%.1f"),
FUEL_CONSUMPTION_DEFAULT_AVERAGE_TIME),
FUEL_CONSUMPTION_RATE_LITER_HOUR(
false,
OBD_FUEL_LEVEL_COMMAND,
"obd_fuel_consumption_rate_liter_hour", OBDComputerWidgetFormatter("%.1f")),
"obd_fuel_consumption_rate_liter_hour", OBDComputerWidgetFormatter("%.1f"),
FUEL_CONSUMPTION_DEFAULT_AVERAGE_TIME),
FUEL_CONSUMPTION_RATE_SENSOR(
false,
OBD_FUEL_CONSUMPTION_RATE_COMMAND,
Expand Down Expand Up @@ -303,7 +312,12 @@ object OBDDataComputer {

FUEL_CONSUMPTION_RATE_LITER_HOUR -> {
if (locValues.size >= 2) {
getFuelTank() * calculateFuelConsumption(locValues) / 100
val result = getFuelTank() * calculateFuelConsumption(locValues) / 100
if (result > LITER_HOUR_CONSUMPTION_LIMIT) {
Float.NaN
} else {
result
}
} else if (locValues.size == 1) {
Float.NaN
} else {
Expand All @@ -322,7 +336,12 @@ object OBDDataComputer {
val distance = getDistanceForTimePeriod(first.timestamp, last.timestamp)
if (distance > 0) {
log.debug("l/100km. distance $distance; difLiter $difLiter; result ${100 * difLiter / (distance / 1000)}")
return 100 * difLiter / (distance / 1000)
val result = 100 * difLiter / (distance / 1000)
return if (result > LITER_KM_CONSUMPTION_LIMIT) {
Float.NaN
} else {
result
}
}
}
null
Expand Down
Loading

0 comments on commit 8e051f4

Please sign in to comment.