aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/match.sh
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2019-12-04 08:47:39 +0800
committertypebrook <typebrook@gmail.com>2019-12-04 08:47:39 +0800
commite8d03c43ddeabfbff4934a69722cf7f125b5c55e (patch)
treed198e07a925ca5d679b785a238066ce940bfdd70 /scripts/match.sh
parent73d18a578b14f367b8087cd38b7ca813923d5143 (diff)
update
Diffstat (limited to 'scripts/match.sh')
-rwxr-xr-xscripts/match.sh28
1 files changed, 15 insertions, 13 deletions
diff --git a/scripts/match.sh b/scripts/match.sh
index e76ddec..a1c7e62 100755
--- a/scripts/match.sh
+++ b/scripts/match.sh
@@ -4,31 +4,33 @@
4set -e 4set -e
5 5
6ACCESS_TOKEN=$(cat ~/settings/tokens/mapbox) 6ACCESS_TOKEN=$(cat ~/settings/tokens/mapbox)
7#export MAPBOX_ACCESS_TOKEN=$ACCESS_TOKEN
8LIMIT=10 7LIMIT=10
9TRK_NAME=$(sed -nr 's/.*<name>(.*)<\/name>.*/\1/p; /<name>/q' $1) 8ORIGIN_DATA=/tmp/origin
9RESPONSE=/tmp/response
10 10
11# Need to add pre-process for duplicated gpx trkpts 11# store data of time and location into tmp file with 2 columns, format is like:
12# 1970-01-01T08:00:46 [121.0179739,14.5515336]
12paste -d' ' \ 13paste -d' ' \
13 <(sed -nr '/<trk>/,/<\/trk>/ { s/.*<time>(.*)<\/time>/\1/p }' $1 | cut -d'.' -f1) \ 14 <(sed -nr '/<trk>/,/<\/trk>/ { s/.*<time>(.*)<\/time>/\1/p }' $1 | cut -d'.' -f1) \
14 <(sed -nr 's/.*lon=\"([^\"]+)\".*/\1/p' $1) \ 15 <(sed -nr 's/.*lon=\"([^\"]+)\".*/\1/p' $1) \
15 <(sed -nr 's/.*lat=\"([^\"]+)\".*/\1/p' $1) |\ 16 <(sed -nr 's/.*lat=\"([^\"]+)\".*/\1/p' $1) |\
16sed -r 's/ ([^ ]+) ([^ ]+)/ [\1,\2]/' |\ 17sed -r 's/ ([^ ]+) ([^ ]+)/ [\1,\2]/' |\
17awk '!_[$1]++' > origin 18awk '!_[$1]++' > $ORIGIN_DATA
19exit 0
18 20
19while [ -s origin ] 21while [ -s $ORIGIN_DATA ]
20do 22do
21 jq --slurp '{type: "Feature", properties: {coordTimes: .[1]}, geometry: {type: "LineString", coordinates: .[0]}}' \ 23 jq --slurp '{type: "Feature", properties: {coordTimes: .[1]}, geometry: {type: "LineString", coordinates: .[0]}}' \
22 <(head -$LIMIT origin | cut -d' ' -f2 | jq -n '[inputs]') \ 24 <(head -$LIMIT $ORIGIN_DATA | cut -d' ' -f2 | jq -n '[inputs]') \
23 <(head -$LIMIT origin | cut -d' ' -f1 | jq -nR '[inputs]') |\ 25 <(head -$LIMIT $ORIGIN_DATA | cut -d' ' -f1 | jq -nR '[inputs]') |\
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 curl -X POST -s --header "Content-Type:application/json" --data @- https://api.mapbox.com/matching/v4/mapbox.driving.json?access_token=$ACCESS_TOKEN > $RESPONSE
25 27
26 TIMESTAMP=0 28 TIMESTAMP=0
27 paste -d' ' \ 29 paste -d' ' \
28 <(jq -c '.features[0].properties.matchedPoints[]' response) \ 30 <(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) \ 31 <(jq -c '.features[0].properties.indices[]' $RESPONSE | xargs -I{} echo {}+1 | bc | xargs -I{} sed -n {}p $ORIGIN_DATA | cut -d' ' -f1 | date -f - +%s) \
30 > matched 32 > matched
31 jq -c '.features[0].geometry.coordinates[]' response |\ 33 jq -c '.features[0].geometry.coordinates[]' $RESPONSE |\
32 while read line 34 while read line
33 do 35 do
34 TIMESTAMP=$(head -1 matched | cut -d' ' -f2) 36 TIMESTAMP=$(head -1 matched | cut -d' ' -f2)
@@ -36,7 +38,7 @@ do
36 done |\ 38 done |\
37 tee /dev/tty && rm matched 39 tee /dev/tty && rm matched
38 40
39 sed -i "1,$LIMIT d" origin 41 sed -i "1,$LIMIT d" $ORIGIN_DATA
40done |\ 42done |\
41sed -r 's/\[([^,]+),([^,]+)\] ?(.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\ 43sed -r 's/\[([^,]+),([^,]+)\] ?(.*)/ <trkpt lon="\1" lat="\2"><time>\3<\/time><\/trkpt>/' |\
42sed "1i \ 44sed "1i \
@@ -46,7 +48,7 @@ sed "1i \
46 xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v1\"\n\ 48 xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v1\"\n\
47 xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n\ 49 xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n\
48 <trk>\n\ 50 <trk>\n\
49 <name>$TRK_NAME<\/name>\n\ 51 <name>$(sed -nr 's/.*<name>(.*)<\/name>.*/\1/p; /<name>/q' $1)<\/name>\n\
50 <trkseg> 52 <trkseg>
51\$a \ 53\$a \
52\ \ \ \ <\/trkseg>\n\ 54\ \ \ \ <\/trkseg>\n\