<commit_before>#!/usr/bin/env ruby

require 'rubygems'
require 'bundler/setup'
require 'mormon'
require 'ruby_kml'
require 'pry'

osm_file = 'map.osm'
node_start = '3167844735'
node_end = '2999413127'

loader = Mormon::OSM::Loader.new(osm_file)
router = Mormon::OSM::Router.new(loader)
res = router.find_route(node_start, node_end, :foot)

# Reverse coords since KML uses <lon,lat> instead of <lat,lon>
placemark = KML::Placemark.new(
  geometry: KML::LineString.new(
    tessellate: true,
    coordinates: res[1].map(&:reverse)
  )
)

kml = KMLFile.new
doc = KML::Document.new(
  name: 'ElevationProfiler path',
  features: [placemark]
)
kml.objects << doc
File.open('result.kml', 'w') { |f| f.puts(kml.render) }<commit_msg>Raise on no route found<commit_after>#!/usr/bin/env ruby

require 'rubygems'
require 'bundler/setup'
require 'mormon'
require 'ruby_kml'
require 'pry'

osm_file = 'map.osm'
node_start = '3167844735'
node_end = '2999412925'

loader = Mormon::OSM::Loader.new(osm_file)
router = Mormon::OSM::Router.new(loader)
res = router.find_route(node_start, node_end, :foot)

raise 'No route found' if res[1].empty?

# Reverse coords since KML uses <lon,lat> instead of <lat,lon>
placemark = KML::Placemark.new(
  geometry: KML::LineString.new(
    tessellate: true,
    coordinates: res[1].map(&:reverse)
  )
)

kml = KMLFile.new
doc = KML::Document.new(
  name: 'ElevationProfiler path',
  features: [placemark]
)
kml.objects << doc
File.open('result.kml', 'w') { |f| f.puts(kml.render) }
{'fraction_non_alphanumeric': 0.15856095936042638, 'fraction_numerical': 0.028647568287808126, 'mean_word_length': 5.337552742616034, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '24583', 'n_tokens_mistral': 643, 'n_tokens_neox': 608, 'n_words': 126}