-
Notifications
You must be signed in to change notification settings - Fork 3
/
reset_run_data.rb
59 lines (47 loc) · 1.67 KB
/
reset_run_data.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'rubygems'
require 'mongo'
require 'json'
$: << "agents/sail.rb/lib"
RUNS = ['a','b','c','d'].collect{|alph| "michelle-feb-2012-#{alph}"}
require 'sail/rollcall/user'
require 'sail/rollcall/group'
json = File.read("config.json")
config = JSON.parse(json, :symbolize_names => true)
RUNS.each do |run|
puts ">> Resetting #{run.inspect}..."
mongo = Mongo::Connection.new.db(run)
puts " >> Wiping data in mongo database #{run.inspect}..."
mongo.collection(:location_tracking).remove()
mongo.collection(:observations).remove()
mongo.collection(:notes).remove()
mongo.collection(:meetups).remove()
keep_metadata_keys = ["assigned_organisms", "specialty", "assigned_backup", "day", "key"]
Rollcall::Base.user = "rollcall"
Rollcall::Base.password = "rollcall!"
Rollcall::Base.site = config[:rollcall][:url]
users_url = "/runs/#{run}/users.xml"
full_url = Rollcall::Base.site.to_s + users_url
puts " >> Pulling users from #{full_url.inspect}..."
Rollcall::User.format = :xml
Rollcall::User.find(:all, :from => users_url).each do |u|
puts " >> Wiping metadata for #{u.account.login.inspect}..."
(u.metadata.attributes.keys).each do |key|
unless keep_metadata_keys.include?(key)
puts " - #{key}"
u.metadata.send("#{key}=", nil)
end
# begin
# g = Rollcall::Group.find(u.groups.first.id)
# if g
# puts "Clearing metadata for group #{g.name}"
# g.metadata.assigned_location_for_guess = nil
# g.save
# end
# rescue NoMethodError
# puts "Not clearing group metadata for #{u.account.login.inspect}..."
# end
end
u.save
end
puts
end