mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
76 lines
1.8 KiB
Ruby
76 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ExportSerializer
|
|
attr_reader :points, :user_email
|
|
|
|
def initialize(points, user_email)
|
|
@points = points
|
|
@user_email = user_email
|
|
end
|
|
|
|
def call
|
|
Oj.dump({ user_email => { 'dawarich-export' => export_points } })
|
|
end
|
|
|
|
private
|
|
|
|
def export_points
|
|
points.in_groups_of(1000, false).flat_map do |group|
|
|
group.map { |point| export_point(point) }
|
|
end
|
|
end
|
|
|
|
def export_point(point)
|
|
{
|
|
lat: point.latitude,
|
|
lon: point.longitude,
|
|
bs: battery_status(point),
|
|
batt: point.battery,
|
|
p: point.ping,
|
|
alt: point.altitude,
|
|
acc: point.accuracy,
|
|
vac: point.vertical_accuracy,
|
|
vel: point.velocity,
|
|
conn: connection(point),
|
|
SSID: point.ssid,
|
|
BSSID: point.bssid,
|
|
m: trigger(point),
|
|
tid: point.tracker_id,
|
|
tst: point.timestamp.to_i,
|
|
inrids: point.inrids,
|
|
inregions: point.in_regions,
|
|
topic: point.topic
|
|
}
|
|
end
|
|
|
|
def battery_status(point)
|
|
case point.battery_status
|
|
when 'unplugged' then 'u'
|
|
when 'charging' then 'c'
|
|
when 'full' then 'f'
|
|
else 'unknown'
|
|
end
|
|
end
|
|
|
|
def trigger(point)
|
|
case point.trigger
|
|
when 'background_event' then 'p'
|
|
when 'circular_region_event' then 'c'
|
|
when 'beacon_event' then 'b'
|
|
when 'report_location_message_event' then 'r'
|
|
when 'manual_event' then 'u'
|
|
when 'timer_based_event' then 't'
|
|
when 'settings_monitoring_event' then 'v'
|
|
else 'unknown'
|
|
end
|
|
end
|
|
|
|
def connection(point)
|
|
case point.connection
|
|
when 'mobile' then 'm'
|
|
when 'wifi' then 'w'
|
|
when 'offline' then 'o'
|
|
else 'unknown'
|
|
end
|
|
end
|
|
end
|