Data Report

The data generated through chat communication is not saved in variables, unlike most of the other information in SoPHIE. Therefore, the simplechat API is provided, to retrieve data from the database. The easiest way to get a structured result of the chat communications is shown in the code below, which is applied in a plain text report.

$simplechat = $api->get('sophielabs_simplechat');


For most use cases this result is not sufficient, as the data analysis is processed on structured data accessible in csv format or similar. To get to this result, simply use the code below in a csv report.

$chatApi = $api->get('sophielabs_simplechat');

$data = array();
$data[] = array(
    'Channel Identifier',
    'Abs. Time',

$messages = $chatApi->getMessages();

$channelIdentifier = null;
foreach ($messages as $msg)
    if ($msg['channelIdentifier'] === $channelIdentifier)
        $msg['channelIdentifier'] = '';
        $channelIdentifier = $msg['channelIdentifier'];
    $data[] = array(

foreach ($data as $row)
    $line = array();
    foreach ($row as $cell)
        // $cell = str_replace(array("'", '\\', '"', "\n", "\r", "\t"), '', $cell);
        $cell = preg_replace('/\s/', ' ', $cell);
        $cell = str_replace('"', '""', $cell);
        $line[] = '"' . $cell . '"';
    echo implode(';', $line) . PHP_EOL;

These functions are not limited to reports though. The simplechat API can be used to display communication results during the experiments as well.