/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/components/XbenchParserComponent.php
132 строки
3 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\components; use common\components\base\BaseGenerator; use common\helpers\ArrayHelper; use PhpOffice\PhpSpreadsheet\IOFactory; use Yii; /** * Компонент для работа файла отчёта Xbench * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2024 */ class XbenchParserComponent extends BaseGenerator { /** * Текст ошибок * @var array */ private $result = []; /** * Текст ошибок * @var array */ private $input = []; /** * @inheritdoc */ protected function generate() { $filename = ArrayHelper::getValue($this->params, 'filename'); $spreadsheet = IOFactory::load($filename); $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); $output = array_slice($sheetData, 10); $errors_list = []; $map = [ // Basic 'Untranslated Segments', 'Inconsistency in Source', 'Inconsistency in Target', 'Target same as Source', // Content 'Tag Mismatch', 'Numeric Mismatch', 'URL Mismatch', 'Alphanumeric Mismatch', 'Unpaired Symbol', 'Unpaired Quotes', 'Double Blank', 'Repeated Word', 'Key Term Mismatch', 'CamelCase Mismatch', 'ALLUPPERCASE Mismatch', 'Leading/Trailing Mismatch', // Checklists 'Project Checklist', 'Hungarian' ]; $error_type = null; $result = []; $id = 1; foreach ($output as $index => $row) { $test_error_type = ArrayHelper::getValue($row, 'A'); $source = ArrayHelper::getValue($row, 'C'); $target = ArrayHelper::getValue($row, 'D'); if ($test_error_type && empty($source)) { foreach ($map as $item) { if (str_starts_with($test_error_type, $item)) { $error_type = $item; break; } } } if ($error_type && $source && $target) { $errors_list[$error_type][] = [ 'Line_id' => $index, 'Source' => $source, 'Target' => $target ]; $result[$index] = [ $id, $error_type, $source, $target ]; $id++; } } $this->result = $result; $this->input = []; foreach ($errors_list as $type => $errors) { $this->input[] = [ 'Possible_Error_type' => $type, 'Entries' => $errors ]; } return true; } /** * Получить информацию из файла * @return array */ public function getResult() { return $this->result; } /** * Получить информацию из файла для GPT * @return array */ public function getInput() { return $this->input; } }