Skip to content

Commit

Permalink
feat:c2corg#3936 compute route public transportation rating
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayor committed May 8, 2024
1 parent efa812c commit 79f0b8c
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/js/constants/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
1 change: 1 addition & 0 deletions src/js/constants/documentsProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/js/constants/fieldsProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/js/vue-plugins/document-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
},

Expand Down
3 changes: 3 additions & 0 deletions src/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,9 @@
"unknown": {
"tracking": "Unbekannt"
},
"unknown service": {
"public_transportation_ratings": "Unbekannt Verkehr"
},
"unsufficient-scopes": {
"tracking": "Unzureichende Berechtigungen"
},
Expand Down
6 changes: 6 additions & 0 deletions src/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions src/translations/eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,12 @@
"traverse": {
"route_types": "trabesia"
},
"unknown": {
"tracking": "ezezaguna"
},
"unknown service": {
"public_transportation_ratings": "zerbitzu ezezaguna"
},
"url": "URL",
"vertical": {
"climbing_styles": "bertikala"
Expand Down
9 changes: 5 additions & 4 deletions src/translations/fixed_strings_common_js.vue
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,12 @@
<span v-translate translate-context="product_types">bar</span>
<span v-translate translate-context="product_types">sport_shop</span>
<!-- public_transportation_ratings -->
<span v-translate translate-context="public_transportation_ratings">good service</span>
<span v-translate translate-context="public_transportation_ratings">seasonal service</span>
<span v-translate translate-context="public_transportation_ratings">poor service</span>
<span v-translate translate-context="public_transportation_ratings">nearby service</span>
<span v-translate translate-context="public_transportation_ratings">no service</span>
<span v-translate translate-context="public_transportation_ratings">unknown</span>
<span v-translate translate-context="public_transportation_ratings">nearby service</span>
<span v-translate translate-context="public_transportation_ratings">poor service</span>
<span v-translate translate-context="public_transportation_ratings">seasonal service</span>
<span v-translate translate-context="public_transportation_ratings">good service</span>
<!-- public_transportation_types -->
<span v-translate translate-context="public_transportation_types">train</span>
<span v-translate translate-context="public_transportation_types">bus</span>
Expand Down
3 changes: 3 additions & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,9 @@
"unknown": {
"tracking": "Inconnu"
},
"unknown service": {
"public_transportation_ratings": "service inconnu"
},
"unsufficient-scopes": {
"tracking": "Autorisations insuffisantes"
},
Expand Down
6 changes: 6 additions & 0 deletions src/translations/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion src/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,10 @@
"route_types": "traversata"
},
"unknown": {
"tracking": "Sconosciuto"
"tracking": "sconosciuto"
},
"unknown service": {
"public_transportation_ratings": "servizio sconosciuto"
},
"unsufficient-scopes": {
"tracking": "Autorizzazioni insufficienti"
Expand Down
5 changes: 4 additions & 1 deletion src/translations/sl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/translations/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,9 @@
"unknown": {
"tracking": "未知"
},
"unknown service": {
"public_transportation_ratings": "未知服务"
},
"unsufficient-scopes": {
"tracking": "范围不足"
},
Expand Down
1 change: 1 addition & 0 deletions src/views/document/RouteView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<field-view :document="document" :field="fields.climbing_outdoor_type" />
<field-view :document="document" :field="fields.configuration" />
<field-view :document="document" :field="fields.slackline_type" />
<field-view :document="document" :field="fields.public_transportation_rating" />
</div>

<div class="column is-4">
Expand Down
40 changes: 40 additions & 0 deletions src/views/wiki/edition/RouteEditionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
:options-filter="filterAccessWaypoints"
:cards-filter="filterEndingWaypoints"
/>
<div>
<label class="label">{{ $gettext('public_transportation_rating') }}</label>
<template v-if="document && document.public_transportation_rating">
{{
$gettext(document.public_transportation_rating, fields.public_transportation_rating.i18nContext)
| uppercaseFirstLetter
}}
</template>
</div>
</form-section>

<form-section
Expand Down Expand Up @@ -194,6 +203,9 @@
<script>
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],
Expand Down Expand Up @@ -241,6 +253,7 @@ export default {
this.document.starting_waypoints = waypoints.filter((waypoint) => waypoint.waypoint_type === 'access');
}
}
this.updatePublicTransportationRating();
},
beforeSave() {
Expand Down Expand Up @@ -285,6 +298,33 @@ export default {
this.document.ending_waypoints = this.document.ending_waypoints.filter((waypoint) =>
waypoints.some((doc) => doc.document_id === waypoint.document_id)
);
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(public_transportation_ratings.indexOf);
} 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) {
Expand Down

0 comments on commit 79f0b8c

Please sign in to comment.