dawarich/app/models/point.rb
2024-05-25 13:26:56 +02:00

36 lines
929 B
Ruby

# frozen_string_literal: true
class Point < ApplicationRecord
# self.ignored_columns = %w[raw_data]
belongs_to :import, optional: true
belongs_to :user, optional: true
validates :latitude, :longitude, :timestamp, presence: true
enum battery_status: { unknown: 0, unplugged: 1, charging: 2, full: 3 }, _suffix: true
enum trigger: {
unknown: 0, background_event: 1, circular_region_event: 2, beacon_event: 3,
report_location_message_event: 4, manual_event: 5, timer_based_event: 6,
settings_monitoring_event: 7
}, _suffix: true
enum connection: { mobile: 0, wifi: 1, offline: 2 }, _suffix: true
after_create :async_reverse_geocode
def self.without_raw_data
select(column_names - ['raw_data'])
end
def recorded_at
Time.zone.at(timestamp)
end
private
def async_reverse_geocode
return unless REVERSE_GEOCODING_ENABLED
ReverseGeocodingJob.perform_later(id)
end
end