Improved data structure of cti caller log to get better statistics.
This commit is contained in:
parent
a93f81e20b
commit
72792fadd6
4 changed files with 103 additions and 13 deletions
|
@ -149,8 +149,8 @@ example data, can be used for demo
|
|||
call_id: '00005',
|
||||
comment: '',
|
||||
state: 'hangup',
|
||||
start: Time.zone.now - 15.seconds,
|
||||
'end': Time.zone.now,
|
||||
start_at: Time.zone.now - 15.seconds,
|
||||
end_at: Time.zone.now,
|
||||
preferences: {
|
||||
from: [
|
||||
{
|
||||
|
@ -174,8 +174,8 @@ example data, can be used for demo
|
|||
call_id: '00006',
|
||||
comment: '',
|
||||
state: 'hangup',
|
||||
start: Time.zone.now - 15.seconds,
|
||||
'end': Time.zone.now,
|
||||
start_at: Time.zone.now - 15.seconds,
|
||||
end_at: Time.zone.now,
|
||||
preferences: {
|
||||
from: [
|
||||
{
|
||||
|
@ -199,8 +199,8 @@ example data, can be used for demo
|
|||
call_id: '00007',
|
||||
comment: '',
|
||||
state: 'hangup',
|
||||
start: Time.zone.now - 15.seconds,
|
||||
'end': Time.zone.now,
|
||||
start_at: Time.zone.now - 15.seconds,
|
||||
end_at: Time.zone.now,
|
||||
preferences: {
|
||||
from: [
|
||||
{
|
||||
|
@ -222,8 +222,8 @@ example data, can be used for demo
|
|||
call_id: '00008',
|
||||
comment: '',
|
||||
state: 'hangup',
|
||||
start: Time.zone.now - 20.seconds,
|
||||
'end': Time.zone.now,
|
||||
start_at: Time.zone.now - 20.seconds,
|
||||
end_at: Time.zone.now,
|
||||
preferences: {}
|
||||
)
|
||||
|
||||
|
@ -306,13 +306,15 @@ Cti::Log.process(
|
|||
call_id: call_id,
|
||||
comment: comment,
|
||||
state: event,
|
||||
initialized_at: Time.zone.now,
|
||||
preferences: preferences,
|
||||
)
|
||||
when 'answer'
|
||||
log = find_by(call_id: call_id)
|
||||
raise "No such call_id #{call_id}" if !log
|
||||
log.state = 'answer'
|
||||
log.start = Time.zone.now
|
||||
log.start_at = Time.zone.now
|
||||
log.duration_waiting_time = log.start_at.to_i - log.initialized_at.to_i
|
||||
if user
|
||||
log.to_comment = user
|
||||
end
|
||||
|
@ -328,7 +330,12 @@ Cti::Log.process(
|
|||
log.done = false
|
||||
end
|
||||
log.state = 'hangup'
|
||||
log.end = Time.zone.now
|
||||
log.end_at = Time.zone.now
|
||||
if log.start_at
|
||||
log.duration_talking_time = log.start_at.to_i - log.end_at.to_i
|
||||
elsif !log.duration_waiting_time && log.initialized_at
|
||||
log.duration_waiting_time = log.end_at.to_i - log.initialized_at.to_i
|
||||
end
|
||||
log.comment = comment
|
||||
log.save
|
||||
else
|
||||
|
|
|
@ -642,10 +642,14 @@ class CreateBase < ActiveRecord::Migration[4.2]
|
|||
t.string :from_comment, limit: 250, null: true
|
||||
t.string :to, limit: 100, null: false
|
||||
t.string :to_comment, limit: 250, null: true
|
||||
t.string :queue, limit: 250, null: true
|
||||
t.string :call_id, limit: 250, null: false
|
||||
t.string :comment, limit: 500, null: true
|
||||
t.timestamp :start, limit: 3, null: true
|
||||
t.timestamp :end, limit: 3, null: true
|
||||
t.timestamp :initialized_at, limit: 3, null: true
|
||||
t.timestamp :start_at, limit: 3, null: true
|
||||
t.timestamp :end_at, limit: 3, null: true
|
||||
t.integer :duration_waiting_time, null: true
|
||||
t.integer :duration_talking_time, null: true
|
||||
t.boolean :done, null: false, default: true
|
||||
t.text :preferences, limit: 500.kilobytes + 1, null: true
|
||||
t.timestamps limit: 3, null: false
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class SettingCti < ActiveRecord::Migration[5.1]
|
||||
class CtiGenericApi < ActiveRecord::Migration[5.1]
|
||||
def up
|
||||
|
||||
# return if it's a new setup
|
||||
|
@ -66,5 +66,14 @@ class SettingCti < ActiveRecord::Migration[5.1]
|
|||
},
|
||||
frontend: false
|
||||
)
|
||||
|
||||
add_column :cti_logs, :queue, :string, limit: 250, null: true
|
||||
add_column :cti_logs, :initialized_at, :string, limit: 250, null: true
|
||||
add_column :cti_logs, :duration_waiting_time, :integer, null: true
|
||||
add_column :cti_logs, :duration_talking_time, :integer, null: true
|
||||
|
||||
rename_column :cti_logs, :start, :start_at
|
||||
rename_column :cti_logs, :end, :end_at
|
||||
|
||||
end
|
||||
end
|
|
@ -180,6 +180,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_nil(log.comment)
|
||||
assert_equal('newCall', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert_nil(log.start_at)
|
||||
assert_nil(log.end_at)
|
||||
assert_nil(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# outbound - I - hangup by agent
|
||||
params = 'event=hangup&direction=out&call_id=1234567890-1&cause=cancel'
|
||||
|
@ -195,6 +200,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_equal('cancel', log.comment)
|
||||
assert_equal('hangup', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert_nil(log.start_at)
|
||||
assert(log.end_at)
|
||||
assert(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# outbound - II - new call
|
||||
params = 'event=newCall&direction=out&from=4930600000000&to=4912347114711&call_id=1234567890-2&user%5B%5D=user+1'
|
||||
|
@ -210,6 +220,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_nil(log.comment)
|
||||
assert_equal('newCall', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert_nil(log.start_at)
|
||||
assert_nil(log.end_at)
|
||||
assert_nil(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# outbound - II - answer by customer
|
||||
params = 'event=answer&direction=out&call_id=1234567890-2&from=4930600000000&to=4912347114711'
|
||||
|
@ -225,6 +240,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_nil(log.comment)
|
||||
assert_equal('answer', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert(log.start_at)
|
||||
assert_nil(log.end_at)
|
||||
assert(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# outbound - II - hangup by customer
|
||||
params = 'event=hangup&direction=out&call_id=1234567890-2&cause=normalClearing&from=4930600000000&to=4912347114711'
|
||||
|
@ -240,6 +260,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_equal('normalClearing', log.comment)
|
||||
assert_equal('hangup', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert(log.start_at)
|
||||
assert(log.end_at)
|
||||
assert(log.duration_waiting_time)
|
||||
assert(log.duration_talking_time)
|
||||
|
||||
# inbound - I - new call
|
||||
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&call_id=1234567890-3&user%5B%5D=user+1'
|
||||
|
@ -255,6 +280,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_nil(log.comment)
|
||||
assert_equal('newCall', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert_nil(log.start_at)
|
||||
assert_nil(log.end_at)
|
||||
assert_nil(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# inbound - I - answer by customer
|
||||
params = 'event=answer&direction=in&call_id=1234567890-3&to=4930600000000&from=4912347114711'
|
||||
|
@ -270,6 +300,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_nil(log.comment)
|
||||
assert_equal('answer', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert(log.start_at)
|
||||
assert_nil(log.end_at)
|
||||
assert(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# inbound - I - hangup by customer
|
||||
params = 'event=hangup&direction=in&call_id=1234567890-3&cause=normalClearing&to=4930600000000&from=4912347114711'
|
||||
|
@ -285,6 +320,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_equal('normalClearing', log.comment)
|
||||
assert_equal('hangup', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert(log.start_at)
|
||||
assert(log.end_at)
|
||||
assert(log.duration_waiting_time)
|
||||
assert(log.duration_talking_time)
|
||||
|
||||
# inbound - II - new call
|
||||
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&call_id=1234567890-4&user%5B%5D=user+1,user+2'
|
||||
|
@ -300,6 +340,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_nil(log.comment)
|
||||
assert_equal('newCall', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert_nil(log.start_at)
|
||||
assert_nil(log.end_at)
|
||||
assert_nil(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# inbound - II - answer by voicemail
|
||||
params = 'event=answer&direction=in&call_id=1234567890-4&to=4930600000000&from=4912347114711&user=voicemail'
|
||||
|
@ -315,6 +360,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_nil(log.comment)
|
||||
assert_equal('answer', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert(log.start_at)
|
||||
assert_nil(log.end_at)
|
||||
assert(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# inbound - II - hangup by customer
|
||||
params = 'event=hangup&direction=in&call_id=1234567890-4&cause=normalClearing&to=4930600000000&from=4912347114711'
|
||||
|
@ -330,6 +380,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_equal('normalClearing', log.comment)
|
||||
assert_equal('hangup', log.state)
|
||||
assert_equal(false, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert(log.start_at)
|
||||
assert(log.end_at)
|
||||
assert(log.duration_waiting_time)
|
||||
assert(log.duration_talking_time)
|
||||
|
||||
# inbound - III - new call
|
||||
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&call_id=1234567890-5&user%5B%5D=user+1,user+2'
|
||||
|
@ -345,6 +400,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_nil(log.comment)
|
||||
assert_equal('newCall', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert_nil(log.start_at)
|
||||
assert_nil(log.end_at)
|
||||
assert_nil(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# inbound - III - hangup by customer
|
||||
params = 'event=hangup&direction=in&call_id=1234567890-5&cause=normalClearing&to=4930600000000&from=4912347114711'
|
||||
|
@ -360,6 +420,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_equal('normalClearing', log.comment)
|
||||
assert_equal('hangup', log.state)
|
||||
assert_equal(false, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert_nil(log.start_at)
|
||||
assert(log.end_at)
|
||||
assert(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# inbound - IV - new call
|
||||
params = 'event=newCall&direction=in&to=4930600000000&from=49999992222222&call_id=1234567890-6&user%5B%5D=user+1,user+2'
|
||||
|
@ -377,6 +442,11 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_nil(log.comment)
|
||||
assert_equal('newCall', log.state)
|
||||
assert_equal(true, log.done)
|
||||
assert(log.initialized_at)
|
||||
assert_nil(log.start_at)
|
||||
assert_nil(log.end_at)
|
||||
assert_nil(log.duration_waiting_time)
|
||||
assert_nil(log.duration_talking_time)
|
||||
|
||||
# get caller list
|
||||
get '/api/v1/cti/log'
|
||||
|
|
Loading…
Reference in a new issue