Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tracepoint ordering logic into tracepoint model, and add tests #2068

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/models/tracepoint.rb
Expand Up @@ -32,17 +32,17 @@ class Tracepoint < ActiveRecord::Base

belongs_to :trace, :foreign_key => "gpx_id"

# Return points of trackable traces in original order
scope :trackable_ordered, -> { joins(:trace).where(:gpx_files => { :visibility => %w[trackable identifiable] }).order("gpx_id DESC, trackid ASC, timestamp ASC") }

# Hide the order of points of non-trackable traces for privacy
scope :non_trackable_unordered, -> { joins(:trace).where(:gpx_files => { :visibility => %w[public private] }).order("gps_points.latitude", "gps_points.longitude") }

def to_xml_node(print_timestamp = false)
el1 = XML::Node.new "trkpt"
el1["lat"] = lat.to_s
el1["lon"] = lon.to_s
el1 << (XML::Node.new("time") << timestamp.xmlschema) if print_timestamp
el1
end

# Return points of trackable traces in original order
scope :trackable_ordered, -> { joins(:trace).where(:gpx_files => { :visibility => %w[trackable identifiable] }).order("gpx_id DESC, trackid ASC, timestamp ASC") }

# Hide the order of points of non-trackable traces for privacy
scope :non_trackable_unordered, -> { joins(:trace).where(:gpx_files => { :visibility => %w[public private] }).order("gps_points.latitude", "gps_points.longitude") }
end