fiedsch/quancept-log-parser

一个用于管理quancept cati日志文件的库

0.4.1 2018-02-17 07:39 UTC

This package is auto-updated.

Last update: 2024-09-18 16:21:51 UTC


README

Quancept生成日志文件。其中包含accounts.sms<projectname>.qca

此库提供了帮助解析这些文件的类。

此项目仍在进行中。如果您发现遗漏或错误,请考虑提交问题或更好的是提交一个pull request。

用法

安装

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

其中<version>是一个版本字符串,如0.2.0

示例:解析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!
}

辅助工具

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

QcaResults和AccountsResults的聚合

  • 待办事项