Commit d97a67f0c7b16280c07ef08c8d41a7c63f46f62c
1 parent
91579eca
Exists in
master
and in
1 other branch
add unambiguator and use it
Showing
1 changed file
with
50 additions
and
4 deletions
Show diff stats
lib/tasks/prune_db.rake
| ... | ... | @@ -28,7 +28,7 @@ namespace :prune_db do |
| 28 | 28 | |
| 29 | 29 | desc "Converts all dates from PT to UTC" |
| 30 | 30 | task :convert_dates_to_utc, [:workerid, :workers] => [:environment] do|t,args| |
| 31 | - args.with_defaults(:workerid => 0, :workers => 1) | |
| 31 | + args.with_defaults(:workerid => "0", :workers => "1") | |
| 32 | 32 | raise "workerid can not be greater than workers" if args[:workerid] > args[:workers] |
| 33 | 33 | time_spans = [ |
| 34 | 34 | { :gt => "2009-11-01 01:59:59", :lt => "2010-03-14 02:00:00", :h => 8}, |
| ... | ... | @@ -40,6 +40,46 @@ namespace :prune_db do |
| 40 | 40 | { :gt => "2011-11-06 01:59:59", :lt => "2012-03-11 02:00:00", :h => 8}, |
| 41 | 41 | { :gt => "2012-03-11 01:59:59", :lt => "2012-11-04 01:00:00", :h => 7} |
| 42 | 42 | ] |
| 43 | + unambiguator = { | |
| 44 | + :appearances => [ | |
| 45 | + { :range => 454229..454229, :h => 7}, | |
| 46 | + { :range => 454426..454501, :h => 7}, # 454501 updated_at needs additional hour | |
| 47 | + { :range => 454502..454745, :h => 8}, | |
| 48 | + { :range => 4005307..4005522, :h => 7 }, | |
| 49 | + { :range => 4005523..4005556, :h => 8 } | |
| 50 | + ], | |
| 51 | + :choices => [ | |
| 52 | + { :range => 181957..181957, :h => 7} # based on appearance id 8392753 | |
| 53 | + ], | |
| 54 | + :prompts => [ | |
| 55 | + { :range => 5191157..5191225, :h => 7}, | |
| 56 | + { :range => 5191226..5191876, :h => 8}, | |
| 57 | + { :range => 8392753..8392758, :h => 7}, # based on appearance id 4005361 | |
| 58 | + ], | |
| 59 | + :question_versions => [ | |
| 60 | + { :range => 7126..7128, :h => 7} # based on choice 181957 | |
| 61 | + ], | |
| 62 | + :questions => [ | |
| 63 | + { :range => 1855..1855, :h => 7} # based on question_versions 7128 | |
| 64 | + ], | |
| 65 | + :skips => [ | |
| 66 | + { :range => 30948..30952, :h => 8}, # based on vote 326681 | |
| 67 | + { :range => 365240..365276, :h => 7}, | |
| 68 | + { :range => 365277..365281, :h => 8}, | |
| 69 | + ], | |
| 70 | + :visitors => [ | |
| 71 | + { :range => 594751..594777, :h => 7}, | |
| 72 | + { :range => 594778..594795, :h => 8}, | |
| 73 | + { :range => 91350..91358, :h => 7}, | |
| 74 | + { :range => 91359..91366, :h => 8} | |
| 75 | + ], | |
| 76 | + :votes => [ | |
| 77 | + { :range => 3145774..3145926, :h => 7}, | |
| 78 | + { :range => 3145927..3145935, :h => 8}, | |
| 79 | + { :range => 326504..326571, :h => 7}, | |
| 80 | + { :range => 326572..326803, :h => 8}, | |
| 81 | + ], | |
| 82 | + } | |
| 43 | 83 | # UTC because Rails will be thinking DB is in UTC when we run this |
| 44 | 84 | #time_spans.map! do |t| |
| 45 | 85 | # { :gt => Time.parse("#{t[:gt]} UTC"), |
| ... | ... | @@ -50,10 +90,10 @@ namespace :prune_db do |
| 50 | 90 | #:appearances => ['created_at', 'updated_at'], |
| 51 | 91 | #:choices => ['created_at', 'updated_at'], |
| 52 | 92 | #:clicks => ['created_at', 'updated_at'], |
| 53 | - :densities => ['created_at', 'updated_at'], | |
| 93 | + #:densities => ['created_at', 'updated_at'], | |
| 54 | 94 | #:flags => ['created_at', 'updated_at'], |
| 55 | 95 | #:prompts => ['created_at', 'updated_at'], |
| 56 | - #:skips => ['created_at', 'updated_at'], | |
| 96 | + :skips => ['created_at', 'updated_at'], | |
| 57 | 97 | #:votes => ['created_at', 'updated_at'], |
| 58 | 98 | #:visitors => ['created_at', 'updated_at'], |
| 59 | 99 | #:users => ['created_at', 'updated_at'], |
| ... | ... | @@ -88,8 +128,14 @@ namespace :prune_db do |
| 88 | 128 | if value < span[:lt] && value > span[:gt] |
| 89 | 129 | # if blank then ambiguous and we don't know how to translate |
| 90 | 130 | if span[:h].blank? |
| 91 | - logger.info "AMBIGUOUS: #{table} #{row["id"]} #{column}: #{value}" | |
| 92 | 131 | updated_values[column] = nil |
| 132 | + if unambiguator[table] && unambiguator[table].length > 0 | |
| 133 | + unambiguator[table].each do |ids| | |
| 134 | + updated_values[column] = ids[:h] if ids[:range].include? row["id"].to_i | |
| 135 | + end | |
| 136 | + end | |
| 137 | + | |
| 138 | + logger.info "AMBIGUOUS: #{table} #{row["id"]} #{column}: #{value}" if updated_values[column].blank? | |
| 93 | 139 | else |
| 94 | 140 | updated_values[column] = span[:h] |
| 95 | 141 | end | ... | ... |