Class: QueueCallLog
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- QueueCallLog
- Defined in:
- app/models/queue_call_log.rb
Overview
== Schema Information
Table name: queue_call_logs
Database name: primary
id :integer not null, primary key
abandon_position :integer
caller_id_name :string
caller_id_number :string
enter_position :integer
exit_position :integer
member_extension :integer
member_misses :integer
member_name :string
origination :string
outcome :string
queue_extension :integer
queue_name :string
result_member_extension :integer
result_member_name :string
result_type :string
ring_time :integer
start_date_cst :date
start_time :datetime
talk_time :integer
wait_time :integer
caller_party_id :integer
member_account_id :integer
member_party_id :integer
queue_account_id :integer
result_member_account_id :integer
unique_id :string
Indexes
idx_outcome_st_rt (outcome,start_time,ring_time)
idx_queue_call_logs (unique_id, start_time, outcome, COALESCE(member_extension, 0), queue_extension) UNIQUE
index_queue_call_logs_caller_party_id (caller_party_id)
index_queue_call_logs_on_member_extension (member_extension)
index_queue_call_logs_on_queue_extension (queue_extension)
index_queue_call_logs_on_start_date_cst (start_date_cst) USING brin
index_queue_call_logs_on_start_time (start_time)
member_party_id_st_rt (member_party_id,start_time,ring_time)
Constant Summary
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Belongs to collapse
Class Method Summary collapse
- .create_from_log_entries(les) ⇒ Object
- .create_from_log_entry(le) ⇒ Object
- .import_member_queue_call_logs(start_time, end_time) ⇒ Object
- .import_new_queue_call_logs(start_time_override: nil, end_time_override: nil) ⇒ Object
- .import_queue_call_logs(start_time, end_time) ⇒ Object
- .queue_name_select_options ⇒ Object
Instance Method Summary collapse
- #find_party_using_account_id(account_id) ⇒ Object
- #find_party_using_number(number) ⇒ Object
- #match_caller_party ⇒ Object
- #match_member_party ⇒ Object
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Class Method Details
.create_from_log_entries(les) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/queue_call_log.rb', line 87 def self.create_from_log_entries(les) # `.compact` produced heterogeneous key sets across rows (nil patterns # differ per log entry — caller_party_id/member_party_id only set when a # match is found, abandon_position/talk_time/etc. only set on certain # outcomes), which Rails 7.2 native `insert_all` rejects with "All # objects being inserted must have the same keys" (AppSignal #4952). # `activerecord-import` (replaced in the 7.2 PR) silently filled missing # keys with column defaults; we have to do that ourselves now. Drop only # the auto-incremented `id` so all rows expose the same union of columns. # All non-PK columns on queue_call_logs are nullable. rows = les.map { |le| create_from_log_entry(le).attributes.except('id') } Rails.logger.info "New Queue Call Log to Import #{rows.size}" # Bulk import. Note: before_create :match_caller_party / :match_member_party # callbacks were skipped under activerecord-import too (the gem skips # callbacks by default), so this is semantically equivalent. res = QueueCallLog.insert_all(rows) if rows.any? Rails.logger.info "New Queue Call Log actually imported: #{res&.rows&.size || 0}" end |
.create_from_log_entry(le) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/models/queue_call_log.rb', line 106 def self.create_from_log_entry(le) qcl = new( caller_id_name: le.caller_id_name, queue_extension: le.queue_extension, enter_position: le.enter_position, abandon_position: le.abandon_position, origination: le.origination, member_account_id: le.member_account_id, wait_time: le.wait_time, queue_name: le.queue_name, caller_id_number: le.caller_id_number, start_time: le.start_time, unique_id: le.uniqueid, member_extension: le.member_extension, member_name: le.member_name, talk_time: le.talk_time, outcome: le.type, # type member_misses: le.member_misses, queue_account_id: le.queue_account_id, exit_position: le.exit_position, result_type: le.result_type, ring_time: le.ring_time, result_member_account_id: le.result_member_account_id, result_member_name: le.result_member_name, result_member_extension: le.result_member_extension ) qcl.match_caller_party qcl.match_member_party qcl end |
.import_member_queue_call_logs(start_time, end_time) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/queue_call_log.rb', line 75 def self.import_member_queue_call_logs(start_time, end_time) pbx = Phone::Pbx.instance params = { start_date: start_time, end_date: end_time } # Retrieve member account ids once pbx.member_queue_log_search(params) do |results| create_from_log_entries(results) end end |
.import_new_queue_call_logs(start_time_override: nil, end_time_override: nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/queue_call_log.rb', line 52 def self.import_new_queue_call_logs(start_time_override: nil, end_time_override: nil) # Find last import date start_time = start_time_override || (QueueCallLog.maximum(:start_time) - 1.hour) end_time = [end_time_override || Date.current.end_of_day, start_time].max Rails.logger.info "Queue Call Log import will start from #{start_time} until #{end_time}" import_queue_call_logs(start_time, end_time) # insert queue member log search import_member_queue_call_logs(start_time, end_time) end |
.import_queue_call_logs(start_time, end_time) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/queue_call_log.rb', line 63 def self.import_queue_call_logs(start_time, end_time) pbx = Phone::Pbx.instance params = { start_date: start_time, end_date: end_time } Rails.logger.info "Starting import_queue_call_logs" pbx.queue_log_search(params) do |results| create_from_log_entries(results) end end |
.queue_name_select_options ⇒ Object
159 160 161 |
# File 'app/models/queue_call_log.rb', line 159 def self. where.not(queue_name: 'test').order(:queue_name).distinct.pluck(:queue_name) end |
Instance Method Details
#caller_party ⇒ Party
47 |
# File 'app/models/queue_call_log.rb', line 47 belongs_to :caller_party, class_name: 'Party', inverse_of: :queue_call_logs, optional: true |
#find_party_using_account_id(account_id) ⇒ Object
145 146 147 148 149 |
# File 'app/models/queue_call_log.rb', line 145 def find_party_using_account_id(account_id) return unless account_id EmployeePhoneStatus.find_by(switchvox_account_id: account_id).try(:employee) end |
#find_party_using_number(number) ⇒ Object
151 152 153 154 155 156 157 |
# File 'app/models/queue_call_log.rb', line 151 def find_party_using_number(number) return if number.blank? Party.joins(:contact_points) .merge(ContactPoint.voice_callable) .where(contact_points: { detail: number }).first end |
#match_caller_party ⇒ Object
137 138 139 |
# File 'app/models/queue_call_log.rb', line 137 def match_caller_party self.caller_party = find_party_using_number(caller_id_number) if caller_id_number && caller_party.nil? end |
#match_member_party ⇒ Object
141 142 143 |
# File 'app/models/queue_call_log.rb', line 141 def match_member_party self.member_party = find_party_using_account_id(member_account_id) if member_account_id && member_party.nil? end |
#member_party ⇒ Party
48 |
# File 'app/models/queue_call_log.rb', line 48 belongs_to :member_party, class_name: "Party", optional: true |