我想比較發送的郵件之間的時間,以便我知道某人會有多快回應。比較時間差
message_sent是消息發送時的unix時間戳。 ID:0000000005是開始,ID:0000000006是關於ID的消息的響應:0000000005.
有了這些數據:0000000006發送的消息上1483021773.原始問題針對0000000005上1483021687.所以反應時間是1483021773 - 1483021687.我應該如何處理這個問題,以便獲得平均響應時間?
我想比較發送的郵件之間的時間,以便我知道某人會有多快回應。比較時間差
message_sent是消息發送時的unix時間戳。 ID:0000000005是開始,ID:0000000006是關於ID的消息的響應:0000000005.
有了這些數據:0000000006發送的消息上1483021773.原始問題針對0000000005上1483021687.所以反應時間是1483021773 - 1483021687.我應該如何處理這個問題,以便獲得平均響應時間?
假設的響應時間是由它需要用於用戶到另一個用戶的最後一個消息響應時間定義爲:
$response_times = array(); // array of response times
// let's define a variable to keep track of the person
// to which another person will respond. initially, variable will hold
// the first message
$initiator = array_shift($messages);
// now iterator through messages
foreach ($messages as $message) {
// if this message belongs to the initiator, just update the timestamp
if ($message['from_user_id'] == $initiator['from_user_id']) {
$initiator['message_sent'] = $message['message_sent'];
continue; // and go to the next message
}
// otherwise, calculate the time difference and put it in response times
array_push($response_times, $message['message_sent'] - $initiator['message_sent']);
// and update the initiator
$initiator = $message;
}
// finally, calculate average of response time
$avg_response_time = array_sum($response_times)/count($response_times);
因爲我不知道這裏的確切代碼是一些sudo代碼,例如:
$total_items = count($array_of_items);
$starting_time_total = "0";
// Some code here to do your message_sent - message_sent = $some_value;
// Do the following for every single item for the $total_items in array
$starting_time_total = $starting_time_total + $some_value;
//Now to get the average we do this
$average = $starting_time_total/$total_items;
所以如果你有4個項目在數組中,響應時間42 3,395,283,583,那麼您的平均響應時間爲421,然後您可以將其轉換爲分鐘或其他任何時間的秒數。
您是否希望整個消息的平均響應時間? – Pejman
不清楚你的問題是什麼。它看起來像你有你需要的所有數據,並知道如何找到差異。你在問如何平均數字? – alanlittle
請同時澄清一下,如果我們確信消息數組只包含用戶ID 6和用戶ID 1之間的對話。 – Pejman