Unnamed imported tracks (FIT, ...) take the file's name, backfilled once for earlier imports; split and best-effort times with seconds
This commit is contained in:
1 parent
21c5c2f21b
commit
d87b8b8f80
5 files changed
+30
-11
No files matched your search
+15
-5
@@ -37,7 +37,7 @@ module Maptool
|
||||
EXTENSIONS = %w[.gpx .fit .tcx .geojson].freeze
|
||||
# Bumped when a parser starts reading more (power, temperature, ...):
|
||||
# tracks imported before get their profile re-read once (reparse).
|
||||
PARSER_VERSION = 2
|
||||
PARSER_VERSION = 3
|
||||
|
||||
def initialize(db_path, gpx_store:, sources_dir:)
|
||||
@path = db_path
|
||||
@@ -76,9 +76,9 @@ module Maptool
|
||||
def reparse
|
||||
return 0 if connect { |db| db.get_first_value("SELECT parser FROM meta") } >= PARSER_VERSION
|
||||
|
||||
rows = connect { |db| db.execute("SELECT id, type, geometry, properties, source_path FROM items WHERE deleted_at IS NULL AND source_path IS NOT NULL AND type IN ('track', 'route', 'layer')") }
|
||||
rows = connect { |db| db.execute("SELECT id, type, name, geometry, properties, source_path FROM items WHERE deleted_at IS NULL AND source_path IS NOT NULL AND type IN ('track', 'route', 'layer')") }
|
||||
updated = 0
|
||||
rows.each do |id, type, geometry, props, source|
|
||||
rows.each do |id, type, name, geometry, props, source|
|
||||
if type == "layer"
|
||||
@gpx_store.refresh(source)
|
||||
next
|
||||
@@ -90,9 +90,12 @@ module Maptool
|
||||
feature = parse(path).find { |f| item_type(f) == type && round(f["geometry"]) == geometry }
|
||||
next unless feature&.dig("properties", "profile")
|
||||
|
||||
name = default_name(source) if name.to_s.empty?
|
||||
props = JSON.parse(props).merge(feature["properties"].slice("profile", "laps"))
|
||||
props["name"] = name if props["name"].to_s.empty?
|
||||
write do |db, rev, now|
|
||||
db.execute("UPDATE items SET properties = ?, updated_at = ?, rev = ? WHERE id = ?",
|
||||
[JSON.generate(JSON.parse(props).merge(feature["properties"].slice("profile", "laps"))), now, rev, id])
|
||||
db.execute("UPDATE items SET name = ?, properties = ?, updated_at = ?, rev = ? WHERE id = ?",
|
||||
[name, JSON.generate(props), now, rev, id])
|
||||
end
|
||||
updated += 1
|
||||
rescue Gpx::ParseError, Fit::ParseError, Errno::ENOENT, JSON::ParserError, GpxStore::InvalidPath
|
||||
@@ -228,6 +231,12 @@ module Maptool
|
||||
add_features(features, folder, source: relative)
|
||||
end
|
||||
|
||||
# FIT (and many TCX/GPX) tracks carry no name of their own: those take
|
||||
# the file's, so the tree doesn't fill up with "Track".
|
||||
def default_name(source)
|
||||
File.basename(source, ".*")
|
||||
end
|
||||
|
||||
# One hand-drawn note (notes.js) into `folder`; returns its node key.
|
||||
def add_note(feature, folder)
|
||||
add_features([feature], folder).first
|
||||
@@ -567,6 +576,7 @@ module Maptool
|
||||
features.sort_by { |f| f.dig("geometry", "type") == "Point" ? 1 : 0 }.each do |f|
|
||||
type = item_type(f)
|
||||
props = (f["properties"] || {}).compact
|
||||
props["name"] = default_name(source) if source && props["name"].to_s.empty? && %w[track route].include?(type)
|
||||
fingerprint = Digest::SHA1.hexdigest(JSON.generate([type, props["name"], round(f["geometry"])]))
|
||||
existing = db.get_first_value("SELECT id FROM items WHERE folder_id IS ? AND fingerprint = ? AND deleted_at IS NULL", [target, fingerprint])
|
||||
id = existing
|
||||
|
||||
Reference in new issue
Block a user