Commit cef90ed70f96cd27209290cec882ef1dedce0a29
1 parent
adfa080c
Exists in
master
and in
29 other branches
ActionItem1210: give random positions to sample enterprises
Showing
1 changed file
with
17 additions
and
1 deletions
Show diff stats
script/sample-enterprises
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
2 | require File.dirname(__FILE__) + '/../config/environment' | 2 | require File.dirname(__FILE__) + '/../config/environment' |
3 | 3 | ||
4 | +def rand_position(type) | ||
5 | + range = { | ||
6 | + :lat => [-33.52, 4.6], | ||
7 | + :lng => [-72.9, -32.41], | ||
8 | + }[type] | ||
9 | + amplitude = (range.last - range.first) | ||
10 | + range.first + rand() * amplitude | ||
11 | +end | ||
12 | + | ||
4 | groups = ['Associação', 'Empresa Solidária', 'Cooperativa'] | 13 | groups = ['Associação', 'Empresa Solidária', 'Cooperativa'] |
5 | what = ['de Produção de Alimentos', 'de Serviços', 'de Artesanato', 'de Comercialização'] | 14 | what = ['de Produção de Alimentos', 'de Serviços', 'de Artesanato', 'de Comercialização'] |
6 | places = ['de Caximbinha do Sul', 'de Bonito', 'de Reviravolta do Serrado'] | 15 | places = ['de Caximbinha do Sul', 'de Bonito', 'de Reviravolta do Serrado'] |
@@ -11,7 +20,14 @@ groups.each do |group| | @@ -11,7 +20,14 @@ groups.each do |group| | ||
11 | what.each do |production| | 20 | what.each do |production| |
12 | places.each do |place| | 21 | places.each do |place| |
13 | name = [group, production, place].join(' ') | 22 | name = [group, production, place].join(' ') |
14 | - Enterprise.create!(:name => name, :identifier => name.to_slug, :enabled => false, :foundation_year => (1990..2008).to_a[rand(18)]) | 23 | + Enterprise.create!( |
24 | + :name => name, | ||
25 | + :identifier => name.to_slug, | ||
26 | + :enabled => false, | ||
27 | + :foundation_year => (1990..2008).to_a[rand(18)], | ||
28 | + :lat => rand_position(:lat), | ||
29 | + :lng => rand_position(:lng) | ||
30 | + ) | ||
15 | print "."; $stdout.flush | 31 | print "."; $stdout.flush |
16 | end | 32 | end |
17 | end | 33 | end |