Created
July 17, 2012 10:04
-
-
Save mimosz/3128524 to your computer and use it in GitHub Desktop.
通过聊天记录统计客服数据
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=User.all[5] | |
reply_nicks=[] | |
non_reply_nicks=[] | |
date='2012-07-10'.to_date | |
user.subusers.all[1].chatpeers.where(date: date).each do |chatpeer| | |
# 定义基础变量 | |
questions = 0 # 提问数 | |
answers = 0 # 答复数 | |
qna_rate = 0 # 问答率 | |
avg_waiting_times = 0 # 平均等待时间 | |
asked_at = 0 # 发起询问,时间 | |
chatpeer.msgs.each do |msg| | |
talked_at = msg.time.to_i | |
case msg.direction | |
when 0 | |
questions += 1 # 累加,提问数 | |
case | |
when asked_at == 0 | |
asked_at = talked_at | |
when asked_at > talked_at | |
asked_at = talked_at | |
end | |
when 1 | |
if asked_at > 0 | |
waiting_times = talked_at - asked_at | |
avg_waiting_times = if avg_waiting_times > 0 | |
(avg_waiting_times + waiting_times) / 2 | |
else | |
waiting_times | |
end | |
asked_at = 0 # 清除询问,时间 | |
end | |
answers += 1 # 累加,答复数 | |
end | |
end | |
if answers > 0 # 答复提问 | |
qna_rate = (answers.to_f/questions.to_f * 100).round(1) if questions > 0 # 未捕捉到,客人提问 | |
reply_nicks << chatpeer.uid | |
else | |
non_reply_nicks << chatpeer.uid | |
end | |
puts "接待:#{chatpeer.uid},提问:#{questions},回答:#{answers},问答率:#{qna_rate},平均响应时间:#{avg_waiting_times}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment