fiedsch/quancept-log-parser

a library with helpers for managing quancept cati log files

0.4.1 2018-02-17 07:39 UTC

This package is auto-updated.

Last update: 2024-12-18 16:53:57 UTC


README

Quancept generates log files. Among these are accounts.sms and <projectname>.qca.

This library provides classes that help to make parsing these files easier.

This is Work in Progress. If you find something missing or wrong, please consider opening an issue or even better make a pull request.

Usage

Installation

composer require "fiedsch/quancept-log-parser <version>"

where <version> is a versionstring like 0.2.0.

Example one parse accounts.sms

require __DIR__ . "/vendor/autoload.php";

use Fiedsch\Data\File\FixedWidthReader;
use Fiedsch\Data\File\Helper;
use Fiedsch\Quancept\Logs\Accounts;

$input = "/path/to/your/accounts.sms";

// the columns to be read from $input into our data array

$columns = [
    'interviewer' => ['from' => Accounts::INTERVIEWER_FROM, 'to' => Accounts::INTERVIEWER_TO],
    'kex'         => ['from' => Accounts::RECORD_KEY_FROM,  'to' => Accounts::RECORD_KEY_TO],
    'timestried'  => ['from' => Accounts::TIMESTRIED_FROM,  'to' => Accounts::TIMESTRIED_TO],
    'start_day'   => ['from' => Accounts::START_DATE_FROM,  'to' => Accounts::START_DATE_TO],
    'start_time'  => ['from' => Accounts::START_TIME_FROM,  'to' => Accounts::START_TIME_TO],
    'duration'    => ['from' => Accounts::DURATION_FROM,    'to' => Accounts::DURATION_TO],
    'tipcode'     => ['from' => Accounts::TIPCODE_FROM,     'to' => Accounts::TIPCODE_TO],
    'exitcode'    => ['from' => Accounts::EXITCODE_FROM,    'to' => Accounts::EXITCODE_TO],
    'queuename'   => ['from' => Accounts::QUEUENAME_FROM,   'to' => Accounts::QUEUENAME_TO],
];

// read file line by line

$reader = new FixedWidthReader($input, $columns);

$aggregated = [];

while (($line = $reader->getLine(FixedWidthReader::SKIP_EMPTY_LINES)) !== null) {
    // trim all data as they might contain surrounding spaces
    $data = array_map(function($el) { return trim($el); }, $line);
    // ignore lines generated by the QTS dialer with no interviewer interaction
    if ($data[0] === Accounts::AGENT_QTS) { continue; }
    // reorganize our data array such that the array keys are the names in $columns
    $data = Helper::setArrayKeys($data, array_keys($columns));
    // change numeric value to label
    if (isset(Accounts::EXITCODES[$data['exitcode']])) {
        $data['exitcode'] = Accounts::EXITCODES[$data['exitcode']];
    }
    // do something with $data here (e.g. aggregate values in $aggregated) 
    // Fit to your needs!
}

Helpers

QcaResults

$results = new QcaResults();
// read lines of the `*.qca` file into $data
// for every line do:
    $results->addInterviewerRecord($data[Qca::USERNAME], $data);
    $results->addDayRecord(date("ymd", $data[Qca::INTERVIEWSTARTTIMESTAMP]), $data);

AccountsResults

$results = new AccountsResults();
// read lines of the `accounts.sms` file into $data
// for every line do:
    $results->addInterviewerRecord($data[AccountsResults::INTERVIEWER], $data);
    $results->addDayRecord($data[AccountsResults::START_DAY], $data);

Aggregation of QcaResults and AccountsResults

  • TODO