Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

QMAPS-2129 add startAt / arriveBy options in public transports (draft / poc) #1383

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
41cba17
QMAPS-2129 add startAt / arriveBy options in public transports (draft…
xem Jul 27, 2022
0922728
Rework Actions init
pascaloliv Jul 29, 2022
9ecc6cd
Replace mapbox-gl typescript patch as @types/mapbox-gl PR was merged
pascaloliv Aug 3, 2022
6686f0d
Merge pull request #1385 from Qwant/replace-mapboxgl-types
pascaloliv Aug 3, 2022
679e1c1
add category airport
sdrll Aug 3, 2022
b4d4686
Merge pull request #1386 from Qwant/add_airport_category_label
sdrll Aug 4, 2022
5248585
Add distance on walking public transport instructions
sdrll Aug 8, 2022
10b37e1
fix translation for walking instructions
sdrll Aug 9, 2022
bbdc944
Merge pull request #1387 from Qwant/add_distance_on_empty_walk_instru…
sdrll Aug 9, 2022
2c8ae9f
QMAPS-2843 design (#1388)
xem Aug 23, 2022
4f559fd
QMAPS fix bold rating (#1390)
xem Aug 23, 2022
b39050e
fix intention renaming revert
sdrll Aug 23, 2022
2bf40a0
Merge pull request #1392 from Qwant/fix_intentions_filed_renaming_revert
sdrll Aug 23, 2022
9cdb456
Merge pull request #1384 from Qwant/rework-actions
pascaloliv Aug 24, 2022
f8eb905
make front compatible with intention api field
sdrll Aug 24, 2022
eeedc51
Deploy Storybook command execption
pascaloliv Aug 24, 2022
95edf41
Merge pull request #1395 from Qwant/fix-deploy-storybook
pascaloliv Aug 24, 2022
661cc73
Missing closing double quote in Github action
pascaloliv Aug 24, 2022
75e5bcd
Merge pull request #1396 from Qwant/fix-deploy-storybook
pascaloliv Aug 24, 2022
1a89687
QMAPS-2909 fix PT dezoom (#1397)
xem Aug 31, 2022
3d716ab
fix transparent topbar borders for mobile (#1398)
remi-dupre Aug 31, 2022
2e7d96c
QMAPS-2129 wip
xem Aug 31, 2022
cfcea39
Merge pull request #1394 from Qwant/compatible_endpoint_intention_field
sdrll Aug 31, 2022
31ba1c9
QMAPS-2850 scroll to selected route
xem Aug 31, 2022
ac8541e
Merge pull request #1399 from Qwant/QMAPS-2850-scroll
sdrll Sep 5, 2022
ee031d6
disable nlu switch and use intention field
sdrll Sep 6, 2022
27da256
remove unused test in production
sdrll Sep 7, 2022
1a959cc
remove unused test in production
sdrll Sep 7, 2022
de706fa
Merge pull request #1400 from Qwant/fix_intention
sdrll Sep 7, 2022
81335a4
QMAPS-2129 add startAt / arriveBy options in public transports (draft…
xem Jul 27, 2022
259d5ba
QMAPS-2129 wip
xem Aug 31, 2022
0e17d45
Merge branch 'QMAPS-2129-startAt-arriveBy' of https://github.com/Qwan…
xem Sep 12, 2022
c7560fc
QMAPS-2129 clean PoC
xem Sep 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
}
},
{
"files": ["bin/**/*.js", "build/**/*.js"],
"files": ["bin/**/*.js", "build/**/*.js", "tests/**/*.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
Expand Down
59 changes: 45 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
name: Erdapfel CI
name: Qwant Maps - CI

on: [push, pull_request]
on: [push]

jobs:
build:
Build:
runs-on: ubuntu-18.04

steps:
- name: Init summary markown
run: echo '# 🗺 Qwant Maps - Build summary' >> $GITHUB_STEP_SUMMARY

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -yq libstdc++6 gettext
sudo apt-get install -yq libstdc++6 gettext jq

- uses: actions/checkout@v2

Expand All @@ -24,25 +27,53 @@ jobs:
npm install -g [email protected]
npm ci

- name: Build
run: TEST=true npm run build -- --mode=production
- name: Run build
run: |
TEST=true npm run build -- --mode=production
echo "- ## 🤖 Project build" >> $GITHUB_STEP_SUMMARY
echo "✅ Success" >> $GITHUB_STEP_SUMMARY

- name: Run coverage
run: npm run ts:coverage
- name: Run ESLint
run: |
npm run lint
echo "- ## 🤖 ESLint" >> $GITHUB_STEP_SUMMARY
echo "✅ Success" >> $GITHUB_STEP_SUMMARY

- name: Run ts/js files count
run: npm run ts:count
- name: Run TypeScript migration files count
run: |
echo "- ## 🤖 TypeScript migration" >> $GITHUB_STEP_SUMMARY
npm run ts:count >> $GITHUB_STEP_SUMMARY

- name: Run linter
run: npm run lint
- name: Run TypeScript coverage
id: tscov
run: |
echo "- ## 🤖 TypeScript coverage" >> $GITHUB_STEP_SUMMARY
npm run ts:coverage
echo "📊 Total coverage: $(cat coverage-ts/typescript-coverage.json | jq '.percentage')% - Details: $(cat coverage-ts/typescript-coverage.json | jq '.covered')/$(cat coverage-ts/typescript-coverage.json | jq '.total') lines covered" >> $GITHUB_STEP_SUMMARY

- name: Run tests
run: npm run test
- name: Run unit tests
run: |
npm run unit-test
echo "- ## 🤖 Unit tests" >> $GITHUB_STEP_SUMMARY
echo "✅ Success" >> $GITHUB_STEP_SUMMARY
echo "📊 Lines coverage: $(cat coverage/coverage-summary.json | jq '.total.lines.pct')% - Details: $(cat coverage/coverage-summary.json | jq '.total.lines.covered')/$(cat coverage/coverage-summary.json | jq '.total.lines.total') lines covered" >> $GITHUB_STEP_SUMMARY
echo "📊 Statements coverage: $(cat coverage/coverage-summary.json | jq '.total.statements.pct')% - Details: $(cat coverage/coverage-summary.json | jq '.total.statements.covered')/$(cat coverage/coverage-summary.json | jq '.total.statements.total') statements covered" >> $GITHUB_STEP_SUMMARY
echo "📊 Functions coverage: $(cat coverage/coverage-summary.json | jq '.total.functions.pct')% - Details: $(cat coverage/coverage-summary.json | jq '.total.functions.covered')/$(cat coverage/coverage-summary.json | jq '.total.functions.total') functions covered" >> $GITHUB_STEP_SUMMARY
echo "📊 Branches coverage: $(cat coverage/coverage-summary.json | jq '.total.branches.pct')% - Details: $(cat coverage/coverage-summary.json | jq '.total.branches.covered')/$(cat coverage/coverage-summary.json | jq '.total.branches.total') branches covered" >> $GITHUB_STEP_SUMMARY

- name: Run integration tests
run: |
npm run integration-test
echo "- ## 🤖 Integration tests" >> $GITHUB_STEP_SUMMARY
echo "✅ Success" >> $GITHUB_STEP_SUMMARY

- name: Deploy Storybook
if: "contains(github.ref_name, 'master')"
run: |
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
npm run deploy-storybook -- -u "github-actions-bot <[email protected]>"
echo "- ## 🎨 Storybook"
echo "- ✅ Successfully deployed to [https://qwant.github.io/erdapfel/](https://qwant.github.io/erdapfel/) 🚀" >> $GITHUB_STEP_SUMMARY

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 4 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Qwant Maps - Docker image

on:
push:
branches:
Expand All @@ -9,7 +11,7 @@ env:
DOCKER_IMAGE_BASENAME: qwantresearch/erdapfel

jobs:
build_docker:
BuildDockerImage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -32,5 +34,5 @@ jobs:

- run: docker build --label "org.label-schema.vcs-ref=$GITHUB_SHA" -t $DOCKER_IMAGE .

- if: github.event_name == 'push'
- if: github.event_name == 'push'
run: docker push $DOCKER_IMAGE
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public/message

# Code coverage
coverage-ts/
coverage/

# Static Storybook Build
storybook-static/
Expand Down
1 change: 1 addition & 0 deletions config/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,6 @@ window.categories = [
_('stadium'),
_('viewpoint'),
_('charging station'),
_('airport'),
_('osteopathy'),
];
2 changes: 2 additions & 0 deletions config/categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,5 +336,7 @@
name: viewpoint
- label: _('charging station')
name: charging_station
- label: _('airport')
name: airport
- label: _('osteopathy')
name: health_osteopathy
6 changes: 6 additions & 0 deletions language/message/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,12 @@ msgstr "Zurück gehen"
msgid "{modifier} on {name}"
msgstr "{modifier} auf {name}"

msgid "{modifier} in {length} m"
msgstr "{modifier} in {length} m"

msgid "{modifier} during {length} m"
msgstr "{modifier} während {length} m"

msgid "Walk on {walkDistance}"
msgstr "Lauf über {walkDistance}"

Expand Down
6 changes: 6 additions & 0 deletions language/message/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,12 @@ msgstr "Volver"
msgid "{modifier} on {name}"
msgstr "{modifier} en la {name}"

msgid "{modifier} in {length} m"
msgstr "{modifier} en {length} m"

msgid "{modifier} during {length} m"
msgstr "{modifier} durante {length} m"

msgid "Walk on {walkDistance}"
msgstr "Camina {walkDistance}"

Expand Down
6 changes: 6 additions & 0 deletions language/message/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,12 @@ msgstr "Faites demi tour"
msgid "{modifier} on {name}"
msgstr "{modifier} sur {name}"

msgid "{modifier} in {length} m"
msgstr "{modifier} dans {length} m"

msgid "{modifier} during {length} m"
msgstr "{modifier} pendant {length} m"

msgid "Walk on {walkDistance}"
msgstr "Marchez sur {walkDistance}"

Expand Down
6 changes: 6 additions & 0 deletions language/message/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,12 @@ msgstr "Torna indietro"
msgid "{modifier} on {name}"
msgstr "{modifier} su {name}"

msgid "{modifier} in {length} m"
msgstr "{modifier} in {length} m"

msgid "{modifier} during {length} m"
msgstr "{modifier} durante {length} m"

msgid "Walk on {walkDistance}"
msgstr "Cammina per {walkDistance}"

Expand Down
120 changes: 120 additions & 0 deletions local_modules/alt-route-labeller/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Alt-route-labeller
// Original author: Benjamin Becquet
// Forked from: https://www.npmjs.com/package/alt-route-labeller
// Altered distinctSegment() to ensure the filtered array passed to lineString() has at least 2 items

import { coordAll } from '@turf/meta';
import { lineString } from '@turf/helpers';
import { getCoord } from '@turf/invariant';
import along from '@turf/along';
import lineLength from '@turf/length';
import bearing from '@turf/bearing';

const TOLERANCE = 0.000001;
const floatEquals = (f1, f2) => Math.abs(f1 - f2) < TOLERANCE;
const coordEquals = (c1 = [], c2 = []) => floatEquals(c1[0], c2[0]) && floatEquals(c1[1], c2[1]);
const asKey = coord => `${coord[0].toFixed(6)},${coord[1].toFixed(6)}`;
const last = (array = []) => array[array.length - 1];

// find the point at the given distance ratio on the linestring
const project = ratio => ls => {
const length = lineLength(ls);
const lngLat = getCoord(along(ls, length * ratio));
// keep the local bearing of the line to later choose an anchor minimizing the portion of line covered.
const localLineBearing = bearing(
along(ls, length * (ratio - 0.1)),
along(ls, length * (ratio + 0.1))
);

return { lngLat, localLineBearing };
};

function distinctSegment(coordinates, coordCounts) {
const adjacentCoordsUsedOnce = [[]];
coordinates.forEach(coord => {
if (coordCounts.get(asKey(coord)) > 1) {
adjacentCoordsUsedOnce.push([]);
} else {
last(adjacentCoordsUsedOnce).push(coord);
}
});
const longestDistinctSegment = adjacentCoordsUsedOnce
.filter(a => a.length > 0)
.reduce((longest, current) => (current.length > longest.length ? current : longest), []);

const tmp = longestDistinctSegment.length === 0 ? coordinates : longestDistinctSegment;

if (tmp.length === 1) tmp[1] = tmp[0];

return lineString(tmp);
}

// extract the longest segment of each linestring
// whose coordinates don't overlap with another feature
export function findDistinctSegments(linestrings) {
if (linestrings.length < 2) {
return linestrings;
}
// extract raw coordinates
const featuresCoords = linestrings.map(coordAll);
// count occurences of each coordinate accross all features
const coordCounts = new Map();
[].concat(...featuresCoords).forEach(coord => {
coordCounts.set(asKey(coord), (coordCounts.get(asKey(coord)) || 0) + 1);
});
return featuresCoords.map(coordinates => distinctSegment(coordinates, coordCounts));
}

function toSimpleLinestring(feature) {
const allCoordsWithNoDups = coordAll(feature).reduce((noDups, coord) => {
const prevCoord = last(noDups);
if (!prevCoord || !coordEquals(prevCoord, coord)) {
noDups.push(coord);
}
return noDups;
}, []);
return lineString(allCoordsWithNoDups);
}

// Reduce possibilities of collision by chosing anchors so that labels repulse each other
function optimizeAnchors(positions) {
return positions.map((position, index) => {
const others = positions.slice();
others.splice(index, 1);
const othersBearing = getBearingFromOtherPoints(position, others);
return {
lngLat: position.lngLat,
anchor: getAnchor(position, othersBearing),
};
});
}

function getBearingFromOtherPoints(position, others) {
return (
others
.map(other => bearing(other.lngLat, position.lngLat))
.reduce((avg, value, _index, { length }) => avg + value / length, 0) || // mean
0
);
}

function getAnchor(position, otherBearing) {
const axis =
Math.abs(position.localLineBearing) < 45 || Math.abs(position.localLineBearing) > 135
? 'vertical'
: 'horizontal';

if (axis === 'vertical') {
return otherBearing > 0 ? 'left' : 'right';
}
return Math.abs(otherBearing) < 90 ? 'bottom' : 'top';
}

// routes can be a FeatureCollection or an array of Feature or Geometry
export function getLabelPositions(routes = []) {
const featuresOrGeoms = Array.isArray(routes) ? routes : routes.features;
const lineStrings = featuresOrGeoms.map(toSimpleLinestring);
const segments = findDistinctSegments(lineStrings);
const positions = segments.map(project(0.5));
return optimizeAnchors(positions);
}
43 changes: 43 additions & 0 deletions local_modules/alt-route-labeller/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "alt-route-labeller",
"version": "0.3.1",
"description": "A library to compute the best position to put labels on multiple routes between two points",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c"
},
"keywords": [
"map",
"routes",
"directions",
"itineraries",
"ux",
"labels"
],
"author": "Benjamin Becquet ([email protected])",
"license": "ISC",
"dependencies": {
"@turf/along": "^6.0.1",
"@turf/bearing": "^6.0.1",
"@turf/distance": "^6.0.1",
"@turf/helpers": "^6.1.4",
"@turf/invariant": "^6.1.2",
"@turf/length": "^6.0.2",
"@turf/meta": "^6.0.2"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@rollup/plugin-babel": "^5.2.2",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"rollup": "^2.35.1",
"rollup-plugin-terser": "^7.0.2"
},
"repository": {
"type": "git",
"url": "https://github.com/bbecquet/alt-route-labeller"
}
}
Loading