From 377125608761ffe78b780b07ad3b3f4373721fa7 Mon Sep 17 00:00:00 2001 From: Nayor Date: Wed, 8 May 2024 11:21:59 +0200 Subject: [PATCH] feat:#3936 compute route public transportation rating --- src/js/constants/common.json | 9 +++-- src/js/constants/documentsProperties.json | 1 + src/js/constants/fieldsProperties.json | 3 +- src/js/vue-plugins/document-utils.js | 2 +- src/translations/de.json | 3 ++ src/translations/es.json | 6 +++ src/translations/eu.json | 6 +++ src/translations/fixed_strings_common_js.vue | 9 +++-- src/translations/fr.json | 3 ++ src/translations/hu.json | 6 +++ src/translations/it.json | 5 ++- src/translations/sl.json | 5 ++- src/translations/zh_CN.json | 3 ++ src/views/document/RouteView.vue | 1 + src/views/wiki/edition/RouteEditionView.vue | 40 ++++++++++++++++++++ 15 files changed, 90 insertions(+), 12 deletions(-) diff --git a/src/js/constants/common.json b/src/js/constants/common.json index 11016a4a5c..02b24ee56b 100644 --- a/src/js/constants/common.json +++ b/src/js/constants/common.json @@ -221,11 +221,12 @@ "previous_injuries": ["no", "previous_injuries_2"], "product_types": ["farm_sale", "restaurant", "grocery", "bar", "sport_shop"], "public_transportation_ratings": [ - "good service", - "seasonal service", - "poor service", + "no service", + "unknown service", "nearby service", - "no service" + "poor service", + "seasonal service", + "good service" ], "public_transportation_types": ["train", "bus", "service_on_demand", "boat"], "qualification": ["federal_supervisor", "federal_trainer", "professional_diploma"], diff --git a/src/js/constants/documentsProperties.json b/src/js/constants/documentsProperties.json index 0928c83f13..37f921f7ab 100644 --- a/src/js/constants/documentsProperties.json +++ b/src/js/constants/documentsProperties.json @@ -469,6 +469,7 @@ { "id": "mtb_length_trail", "properties": { "url": "mbtrack", "activities": ["mountain_biking"] } }, { "id": "mtb_up_rating", "properties": { "url": "mbur", "activities": ["mountain_biking"] } }, { "id": "orientations", "properties": { "url": "fac" } }, + { "id": "public_transportation_rating" }, { "id": "quality", "properties": { "url": "qa" } }, { "id": "risk_rating", diff --git a/src/js/constants/fieldsProperties.json b/src/js/constants/fieldsProperties.json index c872bc8f84..3844d27b0c 100644 --- a/src/js/constants/fieldsProperties.json +++ b/src/js/constants/fieldsProperties.json @@ -697,7 +697,8 @@ "default": false }, "public_transportation_rating": { - "values": "public_transportation_ratings" + "values": "public_transportation_ratings", + "default": "unknown service" }, "public_transportation_types": { "values": "public_transportation_types", diff --git a/src/js/vue-plugins/document-utils.js b/src/js/vue-plugins/document-utils.js index dcaca418ed..55a212d89b 100644 --- a/src/js/vue-plugins/document-utils.js +++ b/src/js/vue-plugins/document-utils.js @@ -379,7 +379,7 @@ export default function install(Vue) { hasSoftMobility(document) { return ( document.public_transportation_rating && - common.attributes.public_transportation_ratings.indexOf(document.public_transportation_rating) < 4 + common.attributes.public_transportation_ratings.indexOf(document.public_transportation_rating) > 1 ); }, diff --git a/src/translations/de.json b/src/translations/de.json index ff192435e7..1499d9c4bd 100644 --- a/src/translations/de.json +++ b/src/translations/de.json @@ -1966,6 +1966,9 @@ "unknown": { "tracking": "Unbekannt" }, + "unknown service": { + "public_transportation_ratings": "Unbekannt Verkehr" + }, "unsufficient-scopes": { "tracking": "Unzureichende Berechtigungen" }, diff --git a/src/translations/es.json b/src/translations/es.json index 51e5337a7f..197d98ec9c 100644 --- a/src/translations/es.json +++ b/src/translations/es.json @@ -1493,6 +1493,12 @@ "traverse": { "route_types": "cruce" }, + "unknown": { + "tracking": "desconocido" + }, + "unknown service": { + "public_transportation_ratings": "servicio desconocido" + }, "users": "usuarios", "very_dangerous": { "children_proof_types": "peligroso" diff --git a/src/translations/eu.json b/src/translations/eu.json index b5aeaf5d25..f8941f5f15 100644 --- a/src/translations/eu.json +++ b/src/translations/eu.json @@ -916,6 +916,12 @@ "traverse": { "route_types": "trabesia" }, + "unknown": { + "tracking": "ezezaguna" + }, + "unknown service": { + "public_transportation_ratings": "zerbitzu ezezaguna" + }, "url": "URL", "vertical": { "climbing_styles": "bertikala" diff --git a/src/translations/fixed_strings_common_js.vue b/src/translations/fixed_strings_common_js.vue index cd57492c2a..b3c5db43c9 100644 --- a/src/translations/fixed_strings_common_js.vue +++ b/src/translations/fixed_strings_common_js.vue @@ -419,11 +419,12 @@ bar sport_shop - good service - seasonal service - poor service - nearby service no service + unknown + nearby service + poor service + seasonal service + good service train bus diff --git a/src/translations/fr.json b/src/translations/fr.json index 319a1d1f25..06c720084a 100644 --- a/src/translations/fr.json +++ b/src/translations/fr.json @@ -1771,6 +1771,9 @@ "unknown": { "tracking": "Inconnu" }, + "unknown service": { + "public_transportation_ratings": "service inconnu" + }, "unsufficient-scopes": { "tracking": "Autorisations insuffisantes" }, diff --git a/src/translations/hu.json b/src/translations/hu.json index 1434fdcf30..5fceddc0ee 100644 --- a/src/translations/hu.json +++ b/src/translations/hu.json @@ -1634,6 +1634,12 @@ "traverse": { "route_types": "áthalad" }, + "unknown": { + "tracking": "ismeretlen" + }, + "unknown service": { + "public_transportation_ratings": "ismeretlen szolgáltatás" + }, "users": "felhasználók", "vertical": { "climbing_styles": "függőleges" diff --git a/src/translations/it.json b/src/translations/it.json index 1fa090e2b2..6f988a97b4 100644 --- a/src/translations/it.json +++ b/src/translations/it.json @@ -1832,7 +1832,10 @@ "route_types": "traversata" }, "unknown": { - "tracking": "Sconosciuto" + "tracking": "sconosciuto" + }, + "unknown service": { + "public_transportation_ratings": "servizio sconosciuto" }, "unsufficient-scopes": { "tracking": "Autorizzazioni insufficienti" diff --git a/src/translations/sl.json b/src/translations/sl.json index 62400da68d..f28a6e861e 100644 --- a/src/translations/sl.json +++ b/src/translations/sl.json @@ -1883,7 +1883,10 @@ "route_types": "prečenje" }, "unknown": { - "tracking": "Neznano" + "tracking": "neznano" + }, + "unknown service": { + "public_transportation_ratings": "neznana storitev" }, "unsufficient-scopes": { "tracking": "Nezadostna dovoljenja" diff --git a/src/translations/zh_CN.json b/src/translations/zh_CN.json index bc0ff7a5fc..13087993c4 100644 --- a/src/translations/zh_CN.json +++ b/src/translations/zh_CN.json @@ -1892,6 +1892,9 @@ "unknown": { "tracking": "未知" }, + "unknown service": { + "public_transportation_ratings": "未知服务" + }, "unsufficient-scopes": { "tracking": "范围不足" }, diff --git a/src/views/document/RouteView.vue b/src/views/document/RouteView.vue index 692c885382..58bb09b5e6 100644 --- a/src/views/document/RouteView.vue +++ b/src/views/document/RouteView.vue @@ -27,6 +27,7 @@ +
diff --git a/src/views/wiki/edition/RouteEditionView.vue b/src/views/wiki/edition/RouteEditionView.vue index 389fa5f88c..3705341e85 100644 --- a/src/views/wiki/edition/RouteEditionView.vue +++ b/src/views/wiki/edition/RouteEditionView.vue @@ -63,6 +63,15 @@ :options-filter="filterAccessWaypoints" :cards-filter="filterEndingWaypoints" /> +
+ + +
import documentEditionViewMixin from './utils/document-edition-view-mixin'; +import common from '@/js/constants/common.json'; +const public_transportation_ratings = common.attributes.public_transportation_ratings; + export default { mixins: [documentEditionViewMixin], @@ -242,6 +254,7 @@ export default { this.document.starting_waypoints = waypoints.filter((waypoint) => waypoint.waypoint_type === 'access'); } } + this.updatePublicTransportationRating(); }, beforeSave() { @@ -287,6 +300,33 @@ export default { this.document.ending_waypoints = this.document.ending_waypoints.filter((waypoint) => this.$documentUtils.isInArray(waypoints, waypoint) ); + + this.updatePublicTransportationRating(); + }, + + // for each category (starts and ends) take best rating, and keep the worst of the two values + // if no waypoint is provided, assume default service (unknown) + updatePublicTransportationRating() { + const default_rating = this.fields.public_transportation_rating.default; + const starts_rating = this.document.starting_waypoints + .map((w) => w.public_transportation_rating) + .reduce(this.bestPTRatings, default_rating); + const ends_rating = this.document.ending_waypoints + .map((w) => w.public_transportation_rating) + .reduce(this.bestPTRatings, default_rating); + + let estimated_rating; + if (this.fields.ending_waypoints.isVisibleFor(this.document)) { + estimated_rating = [starts_rating, ends_rating].reduceRight(bestPTRatings); + } else { + estimated_rating = starts_rating; + } + + this.document.public_transportation_rating = estimated_rating; + }, + + bestPTRatings(ptr1, ptr2) { + return public_transportation_ratings.indexOf(ptr1) > public_transportation_ratings.indexOf(ptr2) ? ptr1 : ptr2; }, handleRockFreeRating(climbingType) {