orb_def 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.circleci/config.yml +79 -0
- data/.gitignore +14 -0
- data/.rakeTasks +7 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +207 -0
- data/MIT-LICENSE +20 -0
- data/README.md +30 -0
- data/Rakefile +23 -0
- data/app/assets/config/orb_def_manifest.js +2 -0
- data/app/assets/javascripts/orb_def/application.js +15 -0
- data/app/assets/stylesheets/orb_def/application.css +15 -0
- data/app/controllers/orb_def/api/v1/fires_controller.rb +64 -0
- data/app/controllers/orb_def/api/v1/weather_readings_controller.rb +16 -0
- data/app/controllers/orb_def/application_controller.rb +5 -0
- data/app/helpers/orb_def/application_helper.rb +4 -0
- data/app/jobs/orb_def/application_job.rb +4 -0
- data/app/mailers/orb_def/application_mailer.rb +6 -0
- data/app/models/orb_def/application_record.rb +5 -0
- data/app/models/orb_def/detection_type.rb +7 -0
- data/app/models/orb_def/fire.rb +60 -0
- data/app/models/orb_def/weather_reading.rb +41 -0
- data/app/models/orb_def/weather_station.rb +33 -0
- data/app/serializers/orb_def/api/v1/fire_serializer.rb +17 -0
- data/app/services/orb_def/fire_weather_data.rb +36 -0
- data/app/services/orb_def/nasa/firms_client.rb +38 -0
- data/app/services/orb_def/nasa/firms_import.rb +44 -0
- data/app/services/orb_def/open_weather_api/weather_by_coordinates.rb +31 -0
- data/app/views/layouts/orb_def/application.html.erb +16 -0
- data/bin/rails +25 -0
- data/config/routes.rb +13 -0
- data/db/migrate/20200422073925_create_orb_def_weather_stations.rb +12 -0
- data/db/migrate/20200422073938_create_orb_def_weather_readings.rb +20 -0
- data/db/migrate/20200423064313_create_orb_def_detection_types.rb +9 -0
- data/db/migrate/20200428063630_create_orb_def_fires.rb +28 -0
- data/db/seeds.rb +8 -0
- data/lib/orb_def/engine.rb +16 -0
- data/lib/orb_def/version.rb +3 -0
- data/lib/orb_def.rb +16 -0
- data/lib/tasks/orb_def_tasks.rake +4 -0
- data/orb_def.gemspec +38 -0
- data/spec/controllers/orb_def/api/v1/fires_controller_spec.rb +16 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +4 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +36 -0
- data/spec/dummy/bin/update +31 -0
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config/application.rb +30 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +21 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +61 -0
- data/spec/dummy/config/environments/production.rb +94 -0
- data/spec/dummy/config/environments/test.rb +46 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +14 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/orb_def.rb +4 -0
- data/spec/dummy/config/initializers/pagy.rb +170 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/orb_def/spring.rb +1 -0
- data/spec/dummy/config/puma.rb +37 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/schema.rb +87 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/detection_type.rb +5 -0
- data/spec/fixtures/files/modis_c6.txt +3 -0
- data/spec/fixtures/nasa/firms/viirs.txt +3 -0
- data/spec/rails_helper.rb +72 -0
- data/spec/services/orbital_defence_engine/nasa/firms_import_spec.rb +27 -0
- data/spec/services/orbital_defence_engine/open_weather_api/weather_by_coordinates_spec.rb +16 -0
- data/spec/spec/vcr/cassettes/OrbitalDefenceEngine_Nasa_FirmsImport/_all/when_request_successful/creates_fires.yml +77 -0
- data/spec/spec/vcr/cassettes/OrbitalDefenceEngine_OpenWeatherApi_WeatherByCoordinates/_fetch_weather_by_coordinates/returns_json_data_as_a_hash.yml +41 -0
- data/spec/spec_helper.rb +96 -0
- data/spec/support/factory_bot.rb +3 -0
- data/spec/support/vcr.rb +9 -0
- data/spec/vcr/cassettes/OpenWeatherApi_WeatherByCoordinates/_fetch_weather_by_coordinates/returns_json_data_as_a_hash.yml +41 -0
- data/spec/vcr/cassettes/OrbDef_Nasa_FirmsImport/_all/when_request_successful/creates_fires.yml +4766 -0
- data/spec/vcr/cassettes/OrbDef_OpenWeatherApi_WeatherByCoordinates/_fetch_weather_by_coordinates/returns_json_data_as_a_hash.yml +41 -0
- metadata +438 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module OrbDef
|
|
2
|
+
class WeatherStation < ApplicationRecord
|
|
3
|
+
acts_as_mappable :default_units => :kms,
|
|
4
|
+
:default_formula => :sphere,
|
|
5
|
+
:lat_column_name => :latitude,
|
|
6
|
+
:lng_column_name => :longitude
|
|
7
|
+
|
|
8
|
+
has_many :weather_readings, dependent: :destroy
|
|
9
|
+
has_many :fires
|
|
10
|
+
|
|
11
|
+
validates :identifier, uniqueness: true
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
def find_or_create(reading_json)
|
|
15
|
+
identifier = "#{reading_json['name']}:AUS"
|
|
16
|
+
weather_station = WeatherStation.find_by(identifier: identifier)
|
|
17
|
+
|
|
18
|
+
return weather_station if weather_station.present?
|
|
19
|
+
|
|
20
|
+
WeatherStation.create(
|
|
21
|
+
identifier: identifier,
|
|
22
|
+
name: reading_json['name'],
|
|
23
|
+
latitude: reading_json['coord']['lat'],
|
|
24
|
+
longitude: reading_json['coord']['lon']
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def latest_weather_reading
|
|
30
|
+
self.weather_readings.last
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module OrbDef
|
|
2
|
+
class Api::V1::FireSerializer < ActiveModel::Serializer
|
|
3
|
+
attributes :id, :scan_type, :detected_at, :confidence, :latitude, :longitude, :weather_reading_id, :weather_station_id
|
|
4
|
+
|
|
5
|
+
def id
|
|
6
|
+
object.id.to_s
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def weather_reading_id
|
|
10
|
+
object.weather_reading_id.to_s
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def weather_station_id
|
|
14
|
+
object.weather_station_id.to_s
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OrbDef
|
|
4
|
+
class FireWeatherData
|
|
5
|
+
attr_reader :fire
|
|
6
|
+
|
|
7
|
+
def initialize(fire)
|
|
8
|
+
@fire = fire
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def find_or_create_weather
|
|
12
|
+
weather_station = WeatherStation.within(10, origin: [fire.latitude, fire.longitude]).first
|
|
13
|
+
|
|
14
|
+
if weather_station.present? && weather_reading_within_limits?(weather_station)
|
|
15
|
+
return weather_station, weather_station.weather_readings.last
|
|
16
|
+
else
|
|
17
|
+
create_station_and_reading
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def create_station_and_reading
|
|
22
|
+
reading_json = OpenWeatherApi::WeatherByCoordinates.fetch(latitude: fire.latitude, longitude: fire.longitude)
|
|
23
|
+
|
|
24
|
+
return unless reading_json
|
|
25
|
+
|
|
26
|
+
weather_station = WeatherStation.find_or_create(reading_json)
|
|
27
|
+
weather_reading = WeatherReading.find_or_create_by_reading(reading_json, weather_station.id)
|
|
28
|
+
|
|
29
|
+
return weather_station, weather_reading
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def weather_reading_within_limits?(weather_station)
|
|
33
|
+
weather_station.weather_readings&.last.reading_at.between?(fire.detected_at - 30.minutes, fire.detected_at + 30.minutes)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module OrbDef
|
|
3
|
+
module Nasa
|
|
4
|
+
class RemoteServerError < StandardError; end
|
|
5
|
+
|
|
6
|
+
class FirmsClient
|
|
7
|
+
class << self
|
|
8
|
+
def fetch(url, date: julian_date)
|
|
9
|
+
Rails.logger.info('Nasa::FirmsClient#fetch - Started')
|
|
10
|
+
|
|
11
|
+
response = client.get do |req|
|
|
12
|
+
req.url "#{url}#{date}.txt"
|
|
13
|
+
req.headers['Authorization'] = "Bearer #{OrbDef.nasa_api_key}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
if response.success?
|
|
17
|
+
Rails.logger.info('Nasa::FirmsClient#fetch - Completed')
|
|
18
|
+
response.body
|
|
19
|
+
else
|
|
20
|
+
Rails.logger.error("Nasa::FirmsClient#fetch - Failed: #{response.status} #{response.body} - #{url}#{julian_date}")
|
|
21
|
+
raise RemoteServerError
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def julian_date
|
|
28
|
+
@julian_date ||= "#{Date.today.year}#{"%.3d" % Date.today.yday}".to_i
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def client
|
|
32
|
+
@client ||= Faraday.new(url: 'https://nrt4.modaps.eosdis.nasa.gov')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module OrbDef
|
|
3
|
+
module Nasa
|
|
4
|
+
class FirmsImport
|
|
5
|
+
require 'csv'
|
|
6
|
+
|
|
7
|
+
FIRMS_DATA_URLS = {
|
|
8
|
+
# modis: '/api/v2/content/archives/FIRMS/c6/Australia_NewZealand/MODIS_C6_Australia_NewZealand_MCD14DL_NRT_',
|
|
9
|
+
# virrs: '/api/v2/content/archives/FIRMS/viirs/Australia_NewZealand/VIIRS_I_Australia_NewZealand_VNP14IMGTDL_NRT_'
|
|
10
|
+
modis: '/api/v2/content/archives/FIRMS/c6/Global/MODIS_C6_Global_MCD14DL_NRT_',
|
|
11
|
+
virrs: '/api/v2/content/archives/FIRMS/viirs/Global/VIIRS_I_Global_VNP14IMGTDL_NRT_'
|
|
12
|
+
#modis: '/api/v2/content/archives/FIRMS/c6/Southern_Africa/MODIS_C6_Southern_Africa_MCD14DL_NRT_',
|
|
13
|
+
#viirs: '/api/v2/content/archives/FIRMS/viirs/Southern_Africa/VIIRS_I_Southern_Africa_VNP14IMGTDL_NRT_'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
def all
|
|
18
|
+
FIRMS_DATA_URLS.each do |key, url|
|
|
19
|
+
csv_text = Nasa::FirmsClient.fetch(url)
|
|
20
|
+
parse_and_create_fire(csv_text: csv_text, scan_type: key)
|
|
21
|
+
|
|
22
|
+
rescue Nasa::RemoteServerError
|
|
23
|
+
Rails.logger.error("Nasa::FirmsImport#all - Failed to fetch #{key}")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def file(file:, scan_type:)
|
|
28
|
+
parse_and_create(
|
|
29
|
+
csv_text: File.read(Rails.root.join('external_data', file)),
|
|
30
|
+
scan_type: scan_type
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def parse_and_create_fire(csv_text:, scan_type:)
|
|
37
|
+
CSV.parse(csv_text, :headers => true, :encoding => 'ISO-8859-1').each do |row|
|
|
38
|
+
Fire.create_from_csv_row(row, scan_type)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module OrbDef
|
|
3
|
+
module OpenWeatherApi
|
|
4
|
+
class WeatherByCoordinates
|
|
5
|
+
API_THROTTLE_TIME = (ENV['API_THROTTLE_TIME'] || 0.02).freeze
|
|
6
|
+
|
|
7
|
+
class << self
|
|
8
|
+
def fetch(latitude:, longitude:)
|
|
9
|
+
response = open_weather_client.get do |req|
|
|
10
|
+
req.url "/data/2.5/weather?lat=#{latitude}&lon=#{longitude}&appid=#{open_weather_key}"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
sleep API_THROTTLE_TIME
|
|
14
|
+
|
|
15
|
+
JSON.parse(response.body) if response.success?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def open_weather_client
|
|
21
|
+
@open_weather_client ||= Faraday.new(url: 'http://api.openweathermap.org')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def open_weather_key
|
|
25
|
+
@open_weather_key ||= OrbDef.open_weather_api_key
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Orbital defence engine</title>
|
|
5
|
+
<%= csrf_meta_tags %>
|
|
6
|
+
<%= csp_meta_tag %>
|
|
7
|
+
|
|
8
|
+
<%= stylesheet_link_tag "orb_def/application", media: "all" %>
|
|
9
|
+
<%= javascript_include_tag "orb_def/application" %>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
|
|
13
|
+
<%= yield %>
|
|
14
|
+
|
|
15
|
+
</body>
|
|
16
|
+
</html>
|
data/bin/rails
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
|
3
|
+
# installed from the root of your application.
|
|
4
|
+
|
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/orb_def/engine', __dir__)
|
|
7
|
+
APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
|
|
8
|
+
|
|
9
|
+
# Set up gems listed in the Gemfile.
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
|
12
|
+
|
|
13
|
+
require "rails"
|
|
14
|
+
# Pick the frameworks you want:
|
|
15
|
+
require "active_model/railtie"
|
|
16
|
+
require "active_job/railtie"
|
|
17
|
+
require "active_record/railtie"
|
|
18
|
+
require "active_storage/engine"
|
|
19
|
+
require "action_controller/railtie"
|
|
20
|
+
require "action_mailer/railtie"
|
|
21
|
+
require "action_view/railtie"
|
|
22
|
+
require "action_cable/engine"
|
|
23
|
+
require "sprockets/railtie"
|
|
24
|
+
# require "rails/test_unit/railtie"
|
|
25
|
+
require 'rails/engine/commands'
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
OrbDef::Engine.routes.draw do
|
|
2
|
+
namespace :api do
|
|
3
|
+
namespace :v1 do
|
|
4
|
+
resources :fires, only: :index do
|
|
5
|
+
collection do
|
|
6
|
+
get '/windIndicators', to: 'fires#fires_current_wind_direction_indicator'
|
|
7
|
+
get '/search', to: 'fires#search'
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
resources :weather_readings, only: :show
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class CreateOrbDefWeatherStations < ActiveRecord::Migration[5.2]
|
|
2
|
+
def change
|
|
3
|
+
create_table :orb_def_weather_stations do |t|
|
|
4
|
+
t.string :name
|
|
5
|
+
t.float :latitude
|
|
6
|
+
t.float :longitude
|
|
7
|
+
t.string :identifier, index: true, uniqueness: true
|
|
8
|
+
|
|
9
|
+
t.timestamps
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class CreateOrbDefWeatherReadings < ActiveRecord::Migration[5.2]
|
|
2
|
+
def change
|
|
3
|
+
create_table :orb_def_weather_readings do |t|
|
|
4
|
+
t.belongs_to :weather_station, index: true
|
|
5
|
+
t.string :identifier, index: true, uniqueness: true
|
|
6
|
+
t.float :temperature
|
|
7
|
+
t.float :pressure
|
|
8
|
+
t.float :ground_level
|
|
9
|
+
t.integer :humidity
|
|
10
|
+
t.float :wind_speed
|
|
11
|
+
t.float :wind_direction
|
|
12
|
+
t.float :rain
|
|
13
|
+
t.integer :cloud
|
|
14
|
+
t.string :description
|
|
15
|
+
t.datetime :reading_at
|
|
16
|
+
|
|
17
|
+
t.timestamps
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class CreateOrbDefFires < ActiveRecord::Migration[5.2]
|
|
2
|
+
def change
|
|
3
|
+
create_table :orb_def_fires do |t|
|
|
4
|
+
t.belongs_to :weather_station, index: true
|
|
5
|
+
t.belongs_to :detected_at_weather_reading, limit: 8, index: true
|
|
6
|
+
t.belongs_to :detection_type
|
|
7
|
+
t.float :latitude, precision: 10, scale: 6, index: true
|
|
8
|
+
t.float :longitude, precision: 10, scale: 6, index: true
|
|
9
|
+
t.float :brightness
|
|
10
|
+
t.float :bright_t31
|
|
11
|
+
t.float :bright_ti5
|
|
12
|
+
t.float :bright_ti4
|
|
13
|
+
t.float :scan
|
|
14
|
+
t.float :track
|
|
15
|
+
t.float :frp
|
|
16
|
+
t.integer :distance
|
|
17
|
+
t.string :scan_type
|
|
18
|
+
t.string :identifier, index: true, uniqueness: true
|
|
19
|
+
t.string :lat_long, index: true, uniqueness: false
|
|
20
|
+
t.string :satellite
|
|
21
|
+
t.string :confidence
|
|
22
|
+
t.string :version
|
|
23
|
+
t.string :day_night
|
|
24
|
+
t.timestamp :detected_at, index: true, uniqueness: false
|
|
25
|
+
t.timestamps
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/db/seeds.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module OrbDef
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace OrbDef
|
|
4
|
+
|
|
5
|
+
require 'pagy'
|
|
6
|
+
require 'active_model_serializers'
|
|
7
|
+
require 'geokit-rails'
|
|
8
|
+
require 'faraday'
|
|
9
|
+
|
|
10
|
+
config.generators do |g|
|
|
11
|
+
g.test_framework :rspec
|
|
12
|
+
g.fixture_replacement :factory_bot #newly added code
|
|
13
|
+
g.factory_bot dir: 'spec/factories' #newly added code
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/orb_def.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require "orb_def/engine"
|
|
2
|
+
|
|
3
|
+
module OrbDef
|
|
4
|
+
class << self
|
|
5
|
+
mattr_accessor :nasa_api_key, :open_weather_api_key
|
|
6
|
+
self.nasa_api_key = "NASA API KEY"
|
|
7
|
+
self.open_weather_api_key = "OPEN WEATHER API API KEY"
|
|
8
|
+
|
|
9
|
+
# add default values of more config vars here
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# this function maps the vars from your app into your engine
|
|
13
|
+
def self.setup(&block)
|
|
14
|
+
yield self
|
|
15
|
+
end
|
|
16
|
+
end
|
data/orb_def.gemspec
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
$:.push File.expand_path("lib", __dir__)
|
|
2
|
+
|
|
3
|
+
# Maintain your gem's version:
|
|
4
|
+
require "orb_def/version"
|
|
5
|
+
|
|
6
|
+
# Describe your gem and declare its dependencies:
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = "orb_def"
|
|
9
|
+
spec.version = OrbDef::VERSION
|
|
10
|
+
spec.authors = ["James Gascoigne-Taylor"]
|
|
11
|
+
spec.email = ["james@flippakitten.com"]
|
|
12
|
+
spec.homepage = "https://github.com/flippakitten/orbital_defence_engine"
|
|
13
|
+
spec.summary = "Fire and weather data you can query by geolocation"
|
|
14
|
+
spec.description = "Uses Nasa FIRMS data and OpenWeatherApi data"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.bindir = "exe"
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
spec.test_files = Dir["spec/**/*"]
|
|
22
|
+
|
|
23
|
+
spec.add_dependency 'rails', '~> 5.2.4', '>= 5.2.4.2'
|
|
24
|
+
spec.add_dependency 'pagy', '~> 3.7', '>= 3.7.5'
|
|
25
|
+
spec.add_dependency 'geokit-rails', '~> 2.3', '>= 2.3.1'
|
|
26
|
+
spec.add_dependency 'faraday', '~> 0.15.3'
|
|
27
|
+
spec.add_dependency 'active_model_serializers'
|
|
28
|
+
|
|
29
|
+
spec.add_development_dependency 'pg'
|
|
30
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.9.0'
|
|
31
|
+
spec.add_development_dependency 'rspec_junit_formatter'
|
|
32
|
+
spec.add_development_dependency 'factory_bot_rails', '>= 5.1.1'
|
|
33
|
+
spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
|
|
34
|
+
spec.add_development_dependency 'vcr'
|
|
35
|
+
spec.add_development_dependency 'webmock'
|
|
36
|
+
spec.add_development_dependency 'rspec-sidekiq'
|
|
37
|
+
spec.add_development_dependency 'timecop', '~> 0.9.1'
|
|
38
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe OrbDef::Api::V1::FiresController, type: :controller do
|
|
6
|
+
#before(:all) do
|
|
7
|
+
#end
|
|
8
|
+
|
|
9
|
+
describe 'GET index' do
|
|
10
|
+
# let(:csv_text) {File.read(Rails.root.join('spec/fixtures/nasa/firms', 'virrs.txt')) }
|
|
11
|
+
|
|
12
|
+
it 'does something' do
|
|
13
|
+
expect(true).to be_truthy
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/spec/dummy/Rakefile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require rails-ujs
|
|
14
|
+
//= require activestorage
|
|
15
|
+
//= require_tree .
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Action Cable provides the framework to deal with WebSockets in Rails.
|
|
2
|
+
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
|
|
3
|
+
//
|
|
4
|
+
//= require action_cable
|
|
5
|
+
//= require_self
|
|
6
|
+
//= require_tree ./channels
|
|
7
|
+
|
|
8
|
+
(function() {
|
|
9
|
+
this.App || (this.App = {});
|
|
10
|
+
|
|
11
|
+
App.cable = ActionCable.createConsumer();
|
|
12
|
+
|
|
13
|
+
}).call(this);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
|
11
|
+
* It is generally better to create a new file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Dummy</title>
|
|
5
|
+
<%= csrf_meta_tags %>
|
|
6
|
+
<%= csp_meta_tag %>
|
|
7
|
+
|
|
8
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
|
9
|
+
<%= javascript_include_tag 'application' %>
|
|
10
|
+
</head>
|
|
11
|
+
|
|
12
|
+
<body>
|
|
13
|
+
<%= yield %>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= yield %>
|
data/spec/dummy/bin/rake
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
include FileUtils
|
|
4
|
+
|
|
5
|
+
# path to your application root.
|
|
6
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
|
7
|
+
|
|
8
|
+
def system!(*args)
|
|
9
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
chdir APP_ROOT do
|
|
13
|
+
# This script is a starting point to setup your application.
|
|
14
|
+
# Add necessary setup steps to this file.
|
|
15
|
+
|
|
16
|
+
puts '== Installing dependencies =='
|
|
17
|
+
system! 'gem install bundler --conservative'
|
|
18
|
+
system('bundle check') || system!('bundle install')
|
|
19
|
+
|
|
20
|
+
# Install JavaScript dependencies if using Yarn
|
|
21
|
+
# system('bin/yarn')
|
|
22
|
+
|
|
23
|
+
# puts "\n== Copying sample files =="
|
|
24
|
+
# unless File.exist?('config/database.yml')
|
|
25
|
+
# cp 'config/database.yml.sample', 'config/database.yml'
|
|
26
|
+
# end
|
|
27
|
+
|
|
28
|
+
puts "\n== Preparing database =="
|
|
29
|
+
system! 'bin/rails db:setup'
|
|
30
|
+
|
|
31
|
+
puts "\n== Removing old logs and tempfiles =="
|
|
32
|
+
system! 'bin/rails log:clear tmp:clear'
|
|
33
|
+
|
|
34
|
+
puts "\n== Restarting application server =="
|
|
35
|
+
system! 'bin/rails restart'
|
|
36
|
+
end
|