aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2019-12-04 01:36:41 +0800
committertypebrook <typebrook@gmail.com>2019-12-04 01:36:41 +0800
commit73d18a578b14f367b8087cd38b7ca813923d5143 (patch)
tree64362ca46e19b5019e1f65f1d847c2e7bc1e6e34 /scripts
parentf2fa7f6237f69bdafcc082dedadfbd52d5c54af1 (diff)
update
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/match.sh21
1 files changed, 11 insertions, 10 deletions
diff --git a/scripts/match.sh b/scripts/match.sh
index 876b78d..e76ddec 100755
--- a/scripts/match.sh
+++ b/scripts/match.sh
@@ -14,8 +14,7 @@ paste -d' ' \
14 <(sed -nr 's/.*lon=\"([^\"]+)\".*/\1/p' $1) \ 14 <(sed -nr 's/.*lon=\"([^\"]+)\".*/\1/p' $1) \
15 <(sed -nr 's/.*lat=\"([^\"]+)\".*/\1/p' $1) |\ 15 <(sed -nr 's/.*lat=\"([^\"]+)\".*/\1/p' $1) |\
16sed -r 's/ ([^ ]+) ([^ ]+)/ [\1,\2]/' |\ 16sed -r 's/ ([^ ]+) ([^ ]+)/ [\1,\2]/' |\
17awk '!_[$1]++' |\ 17awk '!_[$1]++' > origin
18awk '!_[$2]++' > origin
19 18
20while [ -s origin ] 19while [ -s origin ]
21do 20do
@@ -24,19 +23,22 @@ do
24 <(head -$LIMIT origin | cut -d' ' -f1 | jq -nR '[inputs]') |\ 23 <(head -$LIMIT origin | cut -d' ' -f1 | jq -nR '[inputs]') |\
25 curl -X POST -s --header "Content-Type:application/json" --data @- https://api.mapbox.com/matching/v4/mapbox.driving.json?access_token=$ACCESS_TOKEN > response 24 curl -X POST -s --header "Content-Type:application/json" --data @- https://api.mapbox.com/matching/v4/mapbox.driving.json?access_token=$ACCESS_TOKEN > response
26 25
26 TIMESTAMP=0
27 paste -d' ' \
28 <(jq -c '.features[0].properties.matchedPoints[]' response) \
29 <(jq -c '.features[0].properties.indices[]' response | xargs -I{} echo {}+1 | bc | xargs -I{} sed -n {}p origin | cut -d' ' -f1 | date -f - +%s) \
30 > matched
27 jq -c '.features[0].geometry.coordinates[]' response |\ 31 jq -c '.features[0].geometry.coordinates[]' response |\
28 while read line 32 while read line
29 do 33 do
30 paste -d' ' \ 34 TIMESTAMP=$(head -1 matched | cut -d' ' -f2)
31 <(jq -c '.features[0].properties.matchedPoints[]' response) \ 35 (head -1 matched | grep -F $line && sed -i 1d matched) || echo $line $TIMESTAMP jojo
32 <(jq -c '.features[0].properties.indices[]' response | xargs -I{} echo {}+1 | bc | xargs -I{} sed -n {}p origin | cut -d' ' -f1 | date -f - +%s) |\
33 grep -F $line | head -1 || echo $line
34 done |\ 36 done |\
35 tee /dev/tty 37 tee /dev/tty && rm matched
36 38
37 sed -i "1,$LIMIT d" origin 39 sed -i "1,$LIMIT d" origin
38done |\ 40done |\
39sed -r 's/\[([^,]+),([^,]+)\] (.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\ 41sed -r 's/\[([^,]+),([^,]+)\] ?(.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\
40sed "1i \ 42sed "1i \
41<gpx version=\"1.1\" creator=\"Garmin Connect\"\n\ 43<gpx version=\"1.1\" creator=\"Garmin Connect\"\n\
42 xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd\"\n\ 44 xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd\"\n\
@@ -50,5 +52,4 @@ sed "1i \
50\ \ \ \ <\/trkseg>\n\ 52\ \ \ \ <\/trkseg>\n\
51 <\/trk>\n\ 53 <\/trk>\n\
52<\/gpx>\n\ 54<\/gpx>\n\
53 " |\ 55 " | tee output.gpx
54tee output.gpx