Class: OrbDef::Fire

Inherits:
ApplicationRecord show all
Defined in:
app/models/orb_def/fire.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_from_csv_row(row, scan_type) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/orb_def/fire.rb', line 20

def create_from_csv_row(row, scan_type)
  acq_time = row['acq_time'].include?(':') ? row['acq_time'] : "#{row['acq_time'][0..1]}:#{row['acq_time'][2..3]}"
  detected_at = "#{row['acq_date']} #{acq_time}"
  lat_long = "#{row['latitude']},#{row['longitude']}"
  fire_identifier = Digest::SHA2.hexdigest "#{lat_long}#{detected_at}"

  return if Fire.find_by(identifier: fire_identifier).present?

  fire = Fire.create(
    identifier: fire_identifier,
    lat_long:   lat_long,
    scan_type:  scan_type.downcase,
    latitude:   row['latitude'].to_f,
    longitude:  row['longitude'].to_f,
    brightness: row['brightness'],
    bright_t31: row['bright_t31'],
    bright_ti5: row['bright_ti5'],
    bright_ti4: row['bright_ti4'],
    scan:       row['scan'],
    track:      row['track'],
    frp:        row['frp'],
    satellite:  row['satellite'],
    confidence: row['confidence'],
    version:    row['version'],
    day_night:  row['day_night'],
    detected_at: detected_at.to_datetime,
    detection_type_id: OrbDef::DetectionType.find_by_name('Satellite').id
    )

  station, reading = OrbDef::FireWeatherData.new(fire).find_or_create_weather

  fire.update_attributes(detected_at_weather_reading_id: reading.id, weather_station_id: station.id)
  fire.save!
end

Instance Method Details

#detected_at_weatherObject



56
57
58
# File 'app/models/orb_def/fire.rb', line 56

def detected_at_weather
  OrbDef::WeatherReading.find_by(id: weather_reading_id)
end