Guest User

Untitled

a guest
Mar 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. ct = CallType.find_by(name: "Retention ")
  2. if ct
  3. ct.name = "Retention"
  4. ct.save
  5. end
  6.  
  7. Outcome.all.each do |o|
  8. next if !o.name
  9. o.name = o.name.strip
  10. o.save
  11. end
  12.  
  13. replace_cs = [[704, 700],
  14. [801, 800]]
  15. replace_cs.each do |original, replacement|
  16. CallStatus.where(status: original) do |cs|
  17. cs.status = replacement
  18. cs.save
  19. end
  20. Call.where(status: original).each do |c|
  21. c.status = replacement
  22. c.save
  23. end
  24. end
  25.  
  26. move = [
  27. ['Greg Hutchison', 'Inbound', 'Brute Force'],
  28. ['Chase Kellas', 'Inbound', 'High Rollers'],
  29. ['Vartan Ouzounian', 'Inbound', 'High Rollers'],
  30. ['James Coats', 'Inbound', 'Brute Force'],
  31. ['Marilyn Perez', 'Inbound', 'Brute Force'],
  32. ['David Mares', 'Inbound', 'Brute Force'],
  33. ['Ryan Stone', 'Outbound', 'CAPTCHA Amerika'],
  34. ['David Schad', 'Outbound', 'CAPTCHA Amerika'],
  35. ['James Giles', 'Outbound', 'Retention'],
  36. ['Scott Mershon', 'Outbound', 'LXG'],
  37. ['Rachel Hammond', 'Outbound', 'CAPTCHA Amerika']
  38. ]
  39.  
  40. cts = Company.find(47).call_types
  41.  
  42. def to_map(skill_ids)
  43. skill_ids.map{ |id| [id, []] }.to_h
  44. end
  45.  
  46. def replace(arr, old, n)
  47. arr.map{ |x| x == old ? n : x }
  48. end
  49.  
  50. move.each do |row|
  51.  
  52. first, last = row[0].split(' ')
  53. u = User.where(first_name: first, last_name: last).first!
  54. puts "#{row[0]} (#{u.id}): #{row[1]} --> #{row[2]}"
  55. ct_old = cts.select {|ct| ct.name == row[1]}.first
  56. ct_new = cts.select {|ct| ct.name == row[2]}.first
  57.  
  58. replace_arr = [[45, 13],
  59. [53, 306]]
  60.  
  61. calls = u.calls
  62. calls.each do |call|
  63. # outcome
  64. o_ids = []
  65. call.outcome_ids.each do |o_id|
  66. o_old = Outcome.find(o_id)
  67. o_ids << Outcome.where(call_type: ct_new, name: o_old.name).first!.id
  68. end
  69. call.outcome_ids = o_ids
  70.  
  71. # tag
  72. tag_old = Tag.where(id: call.tag_id).first
  73. call.tag_id = tag_old.nil? ? nil : Tag.where(call_type: ct_new, name: tag_old.name).first!
  74. call.call_type = ct_new
  75.  
  76.  
  77. # skill
  78. call.events.each do |event|
  79. # call.skill_ids, event, eventskill, eventupdate
  80. skill_ids = event.skill_ids
  81.  
  82. replaced = false
  83. replace_arr.each do |original, replacement|
  84. if skill_ids.include?(original)
  85. replaced = true
  86. skill_ids = replace(skill_ids, original, replacement)
  87. end
  88. end
  89. if replaced
  90. event.update_skills(to_map(skill_ids), 1157, "team_migration")
  91. end
  92.  
  93. # qar
  94. QaRecord.where(event_id: event.id).each do |qar|
  95. qar.call_type_id = ct_new.id
  96. replace_arr.each do |original, replacement|
  97. if qar.skill_id == original
  98. qar.skill_id = replacement
  99. break
  100. end
  101. end
  102. qar.save
  103. end
  104. end
  105.  
  106. # calltype
  107. call.call_type_id = ct_new.id
  108. call.save
  109. end
  110. puts "Moved #{calls.length} calls."
  111.  
  112. # call type user
  113. ctu = CallTypeUserMembership.find_by(user_id: u.id, call_type_id: ct_old.id)
  114. if ctu
  115. ctu.active = true
  116. ctu.call_type_id = ct_new.id
  117. ctu.save
  118. puts "Moved to #{row[2]}"
  119. end
  120.  
  121. # permitted ctskill
  122. replace_arr.each do |original, replacement|
  123. pcts = PermittedCallTypeSkill.find_by(call_type_id: ct_new.id, skill_id: original)
  124. if pcts
  125. pcts.skill_id = replacement
  126. pcts.save
  127. puts "Replaced CallTypeSkill ct_id: #{ct_new.id} #{original} --> #{replacement}"
  128. end
  129. end
  130. end
  131.  
  132. # 45 -> 13
  133. # 53 -> 306
  134.  
  135. # outcome
  136. # tag
  137. # event_skill
  138. # event.skill_ids
  139. # call.skill_ids
  140. # qa_records
  141. # event_updates
  142. # permitted_call_type_skills
  143.  
  144. # TODO qa quizzes -- not that important
  145. #
Add Comment
Please, Sign In to add comment