Skip to content

Commit

Permalink
Merge pull request #186 from unepwcmc/release-1.1.0
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
WKocur authored Jun 8, 2021
2 parents a4ebde2 + 68d4e1c commit 8c78085
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/models/geo_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def occurrences

hash = {}

occurrences.uniq.map do |occurrence|
occurrences.map do |occurrence|
next if hash[occurrence['name']] == 'present'

hash[occurrence['name']] = occurrence['occurrence']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(country, habitats_presence_data)
end

def serialize
Habitat.where(id: [1, 2, 3, 4, 5]).map{ |h| get_habitat_change(h) }.compact
Habitat.all.map{ |h| get_habitat_change(h) }.compact
end

def get_habitat_change habitat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def serialize
private

def add_habitats_stats
Habitat.where(id: [1, 2, 3, 4, 5]).each_with_index do |habitat, idx|
Habitat.all.each_with_index do |habitat, idx|
habitat_stat = @geo_stat.find_by(habitat_id: habitat)
value = habitat_stat.coastal_coverage || 0

Expand Down
1 change: 1 addition & 0 deletions app/views/global/_downloads.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<% else %>
<%= link_to downloads[:statistics][:button], "downloads/global_statistics.zip",
class: 'downloads__button button--download',
download: 'global_statistics',
data: {
download_type: 'statistics',
download_label: 'global'
Expand Down
17 changes: 1 addition & 16 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
habitats_config = YAML.load(File.open("#{Rails.root}/config/habitats.yml", 'r'))

habitats_config['habitats'].each do |name, data|
Habitat.where(name: data['name']).first_or_create do |habitat|
habitat.update_attributes(data)
end
Rails.logger.info "#{name.capitalize} habitat created!"
end

# Commented as we are temporarily using static data
#Habitat.all.each do |habitat|
# habitat.calculate_global_coverage
# Rails.logger.info("Global coverage calculate for #{habitat.name}!")
#end

%w(countries regions prebakedstats new_redlist_data coastalstats global_change
%w(habitats countries regions prebakedstats new_redlist_data coastalstats global_change
sources country_citations habitat_sources_per_country bounding_boxes).each do |import_type|
Rake::Task["import:#{import_type}"].invoke
end
Expand Down
13 changes: 13 additions & 0 deletions lib/tasks/import_habitats.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace :import do
desc "import CSV data into database"
task :habitats, [:csv_file] => [:environment] do
habitats_config = YAML.load(File.open("#{Rails.root}/config/habitats.yml", 'r'))

habitats_config['habitats'].each do |name, data|
Habitat.where(name: data['name']).first_or_create do |habitat|
habitat.update_attributes(data)
end
Rails.logger.info "#{name.capitalize} habitat created!"
end
end
end
4 changes: 2 additions & 2 deletions lib/tasks/import_refresh.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ namespace :import do
models = %w(
GeoEntityStat ChangeStat GeoRelationship CoastalStat GeoEntity
GeoEntitiesSpecies Species GeoEntityStatsSources Source CountryCitation
GlobalChangeCitation
GlobalChangeCitation GlobalChangeStat Habitat
)

models.each do |m|
p "Deleting #{m}..."
m.constantize.send(:delete_all)
end

tasks = %w(countries regions prebakedstats new_redlist_data coastalstats
tasks = %w(habitats countries regions prebakedstats new_redlist_data coastalstats
global_change sources country_citations habitat_sources_per_country bounding_boxes
)

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/import_sources.rake
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace :import do

next unless geo_entity

Habitat.where(id: [1, 2, 3, 4, 5]).each do |habitat|
Habitat.all.each do |habitat|
# Fetch the source IDs from the relevant column
camelcased_habitat_title = habitat.title.gsub(/[\s-]/, '_')

Expand Down

0 comments on commit 8c78085

Please sign in to comment.