Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve track grade parsing #1774

Open
aoles opened this issue Apr 5, 2024 · 0 comments
Open

Improve track grade parsing #1774

aoles opened this issue Apr 5, 2024 · 0 comments
Assignees
Labels
easy-fix 👶 very easy fix that should not take much time enhancement | feature ⚡ routing network ⛔

Comments

@aoles
Copy link
Member

aoles commented Apr 5, 2024

Problem description

When parsing combined OSM tag values of tracktype currently only values listed with ; are taken into account but not ranges listed with -. However, according to taginfo there is an order of magnitude more occurrences of the latter ones than the former ones.

# query data from taginfo
url <- "https://taginfo.openstreetmap.org/api/4/key/values?key=tracktype&filter=ways&sortname=count&sortorder=desc&qtype=value"
res <- jsonlite::fromJSON(url)$data

# number of combined range-type values
with(res, count[grepl("-", value) & grepl("grade", value)] |> sum())
#> [1] 3493

# number of combined semicolon-separated values
with(res, count[grepl(";", value) & grepl("grade", value)] |> sum())
#> [1] 296

Created on 2024-04-05 with reprex v2.0.2

Other common easy to address tagging mistakes

# query data from taginfo
url <- "https://taginfo.openstreetmap.org/api/4/key/values?key=tracktype&filter=ways&sortname=count&sortorder=desc&qtype=value"
res <- jsonlite::fromJSON(url)$data

# single-number values such as `tracktype=5`
with(res, count[grepl("^[1-5]$", value)]  |> sum())
#> [1] 125

# higher grades 
res[with(res, which(grepl("^grade[6-9]+$", value))),1:2]
#>     value count
#> 8  grade6   200
#> 10 grade7    71
#> 38 grade8     4

Created on 2024-04-05 with reprex v2.0.2

Current code for parsing tracktype values

protected int getTrackGradeLevel(String grade) {
if (grade == null)
return 0;
if (grade.contains(";")) {
int maxGrade = 0;
try {
String[] values = grade.split(";");
for (String v : values) {
int iv = Integer.parseInt(v.replace("grade", "").trim());
if (iv > maxGrade)
maxGrade = iv;
}
return maxGrade;
} catch (Exception ex) {
// do nothing
}
}
switch (grade) {
case "grade":
case "grade1":
return 1;
case "grade2":
return 2;
case "grade3":
return 3;
case "grade4":
return 4;
case "grade5":
return 5;
case "grade6":
return 6;
default:
}
return 10;
}

Proposed solution

Include parsing of grade range values provided with -.

    protected int getTrackGradeLevel(String grade) {
        if (grade == null) 
            return 0; 
        switch (grade) {
            // official values
            case "grade1":
                return 1;
            case "grade2":
                return 2;
            case "grade3":
                return 3;
            case "grade4":
                return 4;
            case "grade5":
                return 5;
            // attempt to extract meaningful values from common tagging mistakes
            case "grade6":
            case "grade7":
            case "grade8":
                return 6;
            default:
                // call specialized parsing function:
                //    split on ";" or "-"
                //    remove "grade" and trim whitespaces
                //    parse as integer and take maximum over these values and 6
                //
                //    bonus: parse single-number values such as `tracktype=5`
        }
        return 0;
    }
@aoles aoles added enhancement | feature ⚡ routing network ⛔ easy-fix 👶 very easy fix that should not take much time labels Apr 5, 2024
@aoles aoles self-assigned this Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy-fix 👶 very easy fix that should not take much time enhancement | feature ⚡ routing network ⛔
Projects
No open projects
Status: To do
Development

No branches or pull requests

1 participant