From 26733a627d75180c09562a3ce645b6b452bef9f9 Mon Sep 17 00:00:00 2001 From: lencse Date: Tue, 18 May 2021 11:04:06 +0200 Subject: [PATCH] . --- src/hiking-trails/okt/index.ts | 120 ++++++++++++++++----------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/src/hiking-trails/okt/index.ts b/src/hiking-trails/okt/index.ts index afa90d2..020c7e8 100644 --- a/src/hiking-trails/okt/index.ts +++ b/src/hiking-trails/okt/index.ts @@ -47,67 +47,67 @@ const getLinkUrlsFromHtml = (html: string): { links: string[] } => { } async function load() { - // const init = 'https://www.kektura.hu/okt-es-gykt-szakaszok' - // let d: any = await httpGet(init) - // d = getLinkUrlsFromHtml(d) - // d = ((args: any): any => ({ - // pathGpxUrl: findByPattern(args.links, /okt_teljes_[0-9_]+\.gpx/), - // stampGpxUrl: findByPattern(args.links, /okt_bh_[0-9_]+\.gpx/) - // }))(d) - // d = await (async (args: any): Promise => ({ - // pathGpx: await httpGet(args.pathGpxUrl), - // stampGpx: await httpGet(args.stampGpxUrl), - // }))(d) - // d = await (async (args: any): Promise => ({ - // path: (await pointsFromGpx(args.pathGpx)), - // // path: (await pointsFromGpx(args.pathGpx)).filter((p, idx) => 0 === idx % 300), - // stampingLocations: (await stampsFromGpx(args.stampGpx)) - // }))(d) - // d = ((args: any): any => { - // return { - // ...args, - // stampingLocations: args.stampingLocations.map(stamp => { - // let minDistance = Infinity - // let nearestIdx = -1 - // args.path.forEach((point, idx) => { - // const distance = distanceInMeters(point, stamp.point) - // if (distance < minDistance) { - // minDistance = distance - // nearestIdx = idx - // } - // }) - // return { - // ...stamp, - // pointIdx: nearestIdx - // } - // }) - // } - // })(d) - // d = ((args: any): any => { - // const cp = new Map() - // args.stampingLocations.forEach((stamp) => { - // if (!cp.has(stamp.name)) { - // cp.set(stamp.name, { - // name: stamp.name, - // stampingLocations: [] - // }) - // } - // const c = cp.get(stamp.name) - // c.stampingLocations.push(stamp) - // }) - // const result = [] - // for (const i of cp.values()) { - // result.push(i) - // } - // // console.log(result[2]) - // // console.log(result.filter(c => c.name === 'Sirok')[0]) - // return { - // path: args.path, - // checkpoints: result - // } - // })(d) + const init = 'https://www.kektura.hu/okt-es-gykt-szakaszok' + let d: any = await httpGet(init) + d = getLinkUrlsFromHtml(d) + d = ((args: any): any => ({ + pathGpxUrl: findByPattern(args.links, /okt_teljes_[0-9_]+\.gpx/), + stampGpxUrl: findByPattern(args.links, /okt_bh_[0-9_]+\.gpx/) + }))(d) + d = await (async (args: any): Promise => ({ + pathGpx: await httpGet(args.pathGpxUrl), + stampGpx: await httpGet(args.stampGpxUrl), + }))(d) + d = await (async (args: any): Promise => ({ + path: (await pointsFromGpx(args.pathGpx)), + // path: (await pointsFromGpx(args.pathGpx)).filter((p, idx) => 0 === idx % 300), + stampingLocations: (await stampsFromGpx(args.stampGpx)) + }))(d) + d = ((args: any): any => { + return { + ...args, + stampingLocations: args.stampingLocations.map(stamp => { + let minDistance = Infinity + let nearestIdx = -1 + args.path.forEach((point, idx) => { + const distance = distanceInMeters(point, stamp.point) + if (distance < minDistance) { + minDistance = distance + nearestIdx = idx + } + }) + return { + ...stamp, + pointIdx: nearestIdx + } + }) + } + })(d) + d = ((args: any): any => { + const cp = new Map() + args.stampingLocations.forEach((stamp) => { + if (!cp.has(stamp.name)) { + cp.set(stamp.name, { + name: stamp.name, + stampingLocations: [] + }) + } + const c = cp.get(stamp.name) + c.stampingLocations.push(stamp) + }) + const result = [] + for (const i of cp.values()) { + result.push(i) + } + // console.log(result[2]) + // console.log(result.filter(c => c.name === 'Sirok')[0]) + return { + path: args.path, + checkpoints: result + } + })(d) // writeFileSync('/tmp/x.json', JSON.stringify(d)) - let d = JSON.parse(readFileSync('/tmp/x.json').toString()) + // let d = JSON.parse(readFileSync('/tmp/x.json').toString()) d = ((args: any): any => { return ({ ...args,