2017-02-16 6 views
1

私は送信されたメッセージ間の時間を比較したいので、誰かがどのくらい迅速に応答するかを知りたいと思います。時差の比較

message_sentは、メッセージが送信されたときのunixタイムスタンプです。 ID:0000000005はID、スタートです:0000000006は、IDのメッセージに応答である。このデータでは0000000005.

:0000000006だから、元の質問が1483021687.に0000000005に頼まれた1483021773.に反応し、メッセージを送信時間は1483021773 - 1483021687です。私は平均応答時間を得るためにこれにどのようにアプローチすべきですか?

応答時間は、それが他のユーザの最後のメッセージに応答するユーザーのために要する時間によって定義されると仮定すると、データ enter image description here

+0

メッセージ全体の平均応答時間を希望しますか? – Pejman

+0

あなたの質問が何であるか不明です。あなたが必要とするすべてのデータを持っていて、違いを見つける方法を知っているようです。数字を平均する方法を尋ねていますか? – alanlittle

+0

メッセージの配列にユーザーID 6とユーザーID 1の間の会話しか含まれていないことも確認してください。 – Pejman

答えて

1

:私は知らないので

$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); 
+0

私はスクリーンショットで私のオリジナルのポストを編集しました、それは今明らかですか? – poNgz0r

+0

です!上記のコードを確認してください。あなたのデータがあれば、それは私にとって正しい平均応答時間を与えます。 – Pejman

+0

$ initiator ['from_user_id']が存在しないため、わかりません。どちらもありません:$ initiator = $ messages [0];存在する – poNgz0r

0

あなたは42の応答時間を持つ配列の4つの項目を、持っているので、もし

$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; 

:ここでの正確なコードは一例で、いくつかのsudoのコードです3、395、283、583の場合、421の平均応答時間が残っており、数分の秒に変換できます。