Compare commits
No commits in common. "a7809d13e88468e2c044d8e74f85ce9277fdf042" and "3ef7da331765f71d52ae37ad82b08804f1d8d2d1" have entirely different histories.
a7809d13e8
...
3ef7da3317
2 changed files with 2 additions and 23 deletions
|
@ -21,7 +21,7 @@ class ReadingsController < ActionController::API
|
|||
params[:arduinos]&.reject do |a|
|
||||
a[:id].blank? || a[:sensores].empty?
|
||||
end&.each do |a|
|
||||
arduino = reading.arduinos.find_or_initialize_by(local_id: a[:id], raspberry: raspberry)
|
||||
arduino = reading.arduinos.build local_id: a[:id], raspberry: raspberry
|
||||
|
||||
a[:sensores].each do |s|
|
||||
arduino.sensors.build(sensor_params s)
|
||||
|
@ -73,7 +73,7 @@ class ReadingsController < ActionController::API
|
|||
:sample,
|
||||
:signature,
|
||||
coordinates: %i[lat lng]).tap do |p|
|
||||
p[:timestamp] = Time.at p[:timestamp].to_i
|
||||
p[:timestamp] = Time.at p[:timestamp]
|
||||
rescue TypeError
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Elimina arduinos multiplicados
|
||||
class DeduplicateArduinos < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
Raspberry.find_each do |raspberry|
|
||||
unique_local_ids = raspberry.arduinos.distinct(:local_id).pluck(:local_id)
|
||||
|
||||
unique_local_ids.each do |unique_local_id|
|
||||
arduinos = raspberry.arduinos.where(local_id: unique_local_id)
|
||||
unique_arduino = arduinos.first
|
||||
duplicated_arduinos = arduinos.where.not(id: unique_arduino.id)
|
||||
|
||||
result = Sensor.where(arduino_id: duplicated_arduinos.pluck(:id)).update_all(arduino_id: unique_arduino.id)
|
||||
duplicated_arduinos.destroy_all if result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
Loading…
Reference in a new issue