sample-enterprises
1.54 KB
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
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env ruby
# encoding: utf-8
require File.dirname(__FILE__) + '/../config/environment'
include Noosfero::SampleDataHelper
categories = $environment.categories
def rand_position(type)
range = {
:lat => [-33.52, 4.6],
:lng => [-72.9, -32.41],
}[type]
amplitude = (range.last - range.first)
range.first + rand() * amplitude
end
groups = ['Associação', 'Empresa Solidária', 'Cooperativa']
what = ['de Produção de Alimentos', 'de Serviços', 'de Artesanato', 'de Comercialização']
places = ['de Caximbinha do Sul', 'de Bonito', 'de Reviravolta do Serrado']
start_time = Time.now
print "Creating enterprises: "
groups.each do |group|
what.each do |production|
places.each do |place|
name = [group, production, place].join(' ') + " - #{$environment.name}"
enterprise = Enterprise.new(
:name => name,
:identifier => name.to_slug,
:foundation_year => (1990..2008).to_a[rand(18)],
:lat => rand_position(:lat),
:lng => rand_position(:lng)
)
next if Profile[enterprise.identifier]
save enterprise do
2.times do
category = categories.sample
enterprise.add_category category
end
end
end
end
end
done
EnterpriseActivation.where('created_at > ?', start_time).each do |activation|
enterprise = activation.enterprise
end
ze = Person['ze']
# give admin rights for 'ze' in some enterprises
$environment.enterprises.sample.add_admin(ze)
$environment.enterprises.sample.add_admin(ze)
$environment.enterprises.sample.add_admin(ze)