mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Update owntracks points data
This commit is contained in:
parent
2b4a16d6cb
commit
a0aa684985
1 changed files with 46 additions and 17 deletions
|
|
@ -2,10 +2,45 @@
|
|||
|
||||
class AddOwntracksPointsData < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
Rails.logger.info("Updating #{Import.owntracks.count} owntracks imports points")
|
||||
|
||||
import_points = 0
|
||||
Import.owntracks.each do |import|
|
||||
import.points.each do |point|
|
||||
params = OwnTracks::Params.new(point.raw_data).call
|
||||
|
||||
update_point(point, params)
|
||||
|
||||
import_points += 1
|
||||
end
|
||||
end
|
||||
|
||||
Rails.logger.info("#{import_points} points updated from owntracks imports")
|
||||
|
||||
# Getting points by owntracks-specific data
|
||||
points = Point.where("raw_data -> 'm' is not null and raw_data -> 'acc' is not null")
|
||||
|
||||
Rails.logger.info("Updating #{points.count} points")
|
||||
|
||||
points_updated = 0
|
||||
points.each do |point|
|
||||
params = OwnTracks::Params.new(point.raw_data).call
|
||||
|
||||
update_point(point, params)
|
||||
|
||||
points_updated += 1
|
||||
end
|
||||
|
||||
Rails.logger.info("#{points_updated} points updated")
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_point(point, params)
|
||||
point.update!(
|
||||
battery: params[:battery],
|
||||
ping: params[:ping],
|
||||
|
|
@ -25,9 +60,3 @@ class AddOwntracksPointsData < ActiveRecord::Migration[7.1]
|
|||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue