Commit 5c044e0712752dd36f309879fc944640db1ae36c

Authored by Hugo Melo
1 parent bea83c23

Save the ids of people already checked and skip it on next load

Showing 1 changed file with 12 additions and 3 deletions   Show diff stats
script/check_merit_actions_vs_points.rb
@@ -89,10 +89,16 @@ Environment.all.each do |environment| @@ -89,10 +89,16 @@ Environment.all.each do |environment|
89 89
90 group_control = YAML.load(File.read(File.join(Rails.root,'tmp','control_group.yml'))) if File.exist?(File.join(Rails.root,'tmp','control_group.yml')) 90 group_control = YAML.load(File.read(File.join(Rails.root,'tmp','control_group.yml'))) if File.exist?(File.join(Rails.root,'tmp','control_group.yml'))
91 conditions = group_control.nil? ? {} : {:identifier => group_control.map{|k,v| v['profiles']}.flatten} 91 conditions = group_control.nil? ? {} : {:identifier => group_control.map{|k,v| v['profiles']}.flatten}
92 - people_count = environment.people.where(conditions).count 92 + conditions = {}
  93 +
  94 + clean_profiles_file = File.join(Rails.root,'tmp','gamification_clean_profiles.yml')
  95 + clean_profiles = YAML.load(File.read(clean_profiles_file)) if File.exist?(File.join(clean_profiles_file))
  96 + clean_profiles = [0] if clean_profiles.nil?
  97 +
  98 + people_count = environment.people.where(conditions).where("id not in (?)",clean_profiles).count
93 person_index = 0 99 person_index = 0
94 puts "Analising environment people" 100 puts "Analising environment people"
95 - environment.people.find_each(:conditions => conditions) do |person| 101 + environment.people.where("id not in (?)",clean_profiles).find_each(:conditions => conditions) do |person|
96 person_index += 1 102 person_index += 1
97 profile_ids = GamificationPlugin::PointsCategorization.uniq.pluck(:profile_id) 103 profile_ids = GamificationPlugin::PointsCategorization.uniq.pluck(:profile_id)
98 profile_ids.keep_if { |item| group_control.keys.include?(item) } unless group_control.nil? 104 profile_ids.keep_if { |item| group_control.keys.include?(item) } unless group_control.nil?
@@ -145,7 +151,7 @@ Environment.all.each do |environment| @@ -145,7 +151,7 @@ Environment.all.each do |environment|
145 end 151 end
146 end 152 end
147 if should_and_doesnt_have.size > 0 || should_not_have.size > 0 153 if should_and_doesnt_have.size > 0 || should_not_have.size > 0
148 - CSV.open( "gamification_points_out_expectation.csv", 'a' ) do |csv| 154 + CSV.open( "gamification_wrong_badges.csv", 'a' ) do |csv|
149 [person.identifier, should_and_doesnt_have.join(' | '), should_not_have.join(' | ')] 155 [person.identifier, should_and_doesnt_have.join(' | '), should_not_have.join(' | ')]
150 end 156 end
151 end 157 end
@@ -156,6 +162,7 @@ Environment.all.each do |environment| @@ -156,6 +162,7 @@ Environment.all.each do |environment|
156 } 162 }
157 163
158 puts "Points:" 164 puts "Points:"
  165 + is_profile_clean = true
159 scope_by_type.each do |type, scope| 166 scope_by_type.each do |type, scope|
160 c = GamificationPlugin::PointsCategorization.for_type(type).where(profile_id: profile_id).joins(:point_type).first 167 c = GamificationPlugin::PointsCategorization.for_type(type).where(profile_id: profile_id).joins(:point_type).first
161 points = calc_points c, scope 168 points = calc_points c, scope
@@ -169,11 +176,13 @@ Environment.all.each do |environment| @@ -169,11 +176,13 @@ Environment.all.each do |environment|
169 CSV.open( "gamification_points_out_expectation.csv", 'a' ) do |csv| 176 CSV.open( "gamification_points_out_expectation.csv", 'a' ) do |csv|
170 [person.identifier, person.name, scope.first.class.base_class.name, profile_name, c.id, c.point_type.name, scope.count*c.weight, person.points(category: c.id.to_s)] 177 [person.identifier, person.name, scope.first.class.base_class.name, profile_name, c.id, c.point_type.name, scope.count*c.weight, person.points(category: c.id.to_s)]
171 end 178 end
  179 + is_profile_clean = false
172 else 180 else
173 puts "points fixed for #{c.point_type.name}!" 181 puts "points fixed for #{c.point_type.name}!"
174 end 182 end
175 end 183 end
176 end 184 end
  185 + File.open(clean_profiles_file, 'w') {|f| f.write(clean_profiles.push(person.id).to_yaml)} if is_profile_clean
177 puts 186 puts
178 end 187 end
179 end 188 end