-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsegmentsSafeDistance.ts
More file actions
27 lines (24 loc) · 875 Bytes
/
Copy pathsegmentsSafeDistance.ts
File metadata and controls
27 lines (24 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import isSafePath from './isSafePath'
import lineStringDistance from './lineStringDistance'
export default function (segments, safeExtension) {
const { safe, unsafe } = segments.reduce(
(memo, next) => {
const coordinates = next.geometry.coordinates
const segmentDistance = lineStringDistance(coordinates)
const distance = segmentDistance * (next.properties.rides?.length || 0)
const safe =
isSafePath(next.properties.tags) ||
(safeExtension && safeExtension(next.properties.tags))
if (!safeExtension && safe !== next.properties.isSafePath)
return new Error(
"Le serveur et le client ne sont pas d'accord sur le caractère sécurisé du segment"
)
return {
safe: memo.safe + (safe ? distance : 0),
unsafe: memo.unsafe + (safe ? 0 : distance),
}
},
{ safe: 0, unsafe: 0 }
)
return (safe / (safe + unsafe)) * 100
}