forked from inaturalist/inaturalist
/
load_dummy_observations.rb
44 lines (39 loc) · 1.26 KB
/
load_dummy_observations.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
# Loads a bunch of dummy observations, random users, taxa, and locations. Run
# with script/runner
if ENV['RAILS_ENV'] == 'production' || RAILS_ENV == 'production'
puts "Dude, you should NOT be running this in production"
exit
end
QUIET = false
EARLIEST_TIME = Time.parse('2007-01-01')
LATEST_TIME = Time.now
count = 0
taxon_count = Taxon.count
user_count = User.count
num_obs = (ARGV[0] || 100).to_i
num_obs.times do
taxon = Taxon.first(:offset => rand(taxon_count))
time = EARLIEST_TIME + rand(LATEST_TIME - EARLIEST_TIME)
user = User.first(:offset => rand(user_count))
next unless user.active?
obs = Observation.new(
:user => user,
:taxon => taxon,
:species_guess => taxon.name,
:observed_on_string => time.to_date.to_s,
# :time_observed_at => time,
# Create observations in the Bay Area
# :latitude => rand + 37,
# :longitude => (rand + 122)*-1)
# Create obs in the northern part of the western hemisphere
:latitude => rand * 80,
:longitude => rand * -170)
if obs.save
puts "Created #{obs}" unless QUIET
count += 1
else
puts "Invalid!, Skipping observation for user #{obs.user}: #{obs.errors.full_messages.to_sentence}"
end
end
puts "Created #{count} observations"
# Observation.all.each {|o| o.destroy}