diff --git a/README.md b/README.md index a70c6d3..59763cb 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,6 @@ Szkielet komponentu Joomla 6 do gromadzenia pytań testowych. ## Instalacja -W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.9). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.10). Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**. diff --git a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini index 4107421..7c01b82 100644 --- a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini +++ b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini @@ -107,6 +107,7 @@ COM_TESTQUESTIONS_RESULT_PREVIEW="Podgląd zapisanego testu" COM_TESTQUESTIONS_RESULT_NOT_FOUND="Nie znaleziono zapisanego testu." COM_TESTQUESTIONS_RESULT_PARTICIPANT="Użytkownik" COM_TESTQUESTIONS_RESULT_AI_TOKENS="Tokeny AI" +COM_TESTQUESTIONS_RESULTS_AI_TOKENS_TOTAL="Łączne wykorzystanie tokenów w wynikach" COM_TESTQUESTIONS_RESULT_SCORE="Wynik" COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER="Punkty przed / po korekcie" COM_TESTQUESTIONS_RESULT_GRADE="Ocena" diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.43.10.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.43.10.sql new file mode 100644 index 0000000..3a6ae55 --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.43.10.sql @@ -0,0 +1 @@ +-- No database changes required for version 1.43.10. diff --git a/administrator/components/com_testquestions/src/Model/ResultsModel.php b/administrator/components/com_testquestions/src/Model/ResultsModel.php index 8616c8e..9d97583 100644 --- a/administrator/components/com_testquestions/src/Model/ResultsModel.php +++ b/administrator/components/com_testquestions/src/Model/ResultsModel.php @@ -51,6 +51,44 @@ class ResultsModel extends ListModel return $items; } + public function getAiUsageTotals(): array + { + $db = Factory::getContainer()->get('DatabaseDriver'); + $query = clone $this->getListQuery(); + $query->clear('select')->clear('order')->select($db->quoteName('r.answers')); + $answersRows = $db->setQuery($query)->loadColumn(); + $totals = ['input_tokens' => 0, 'output_tokens' => 0, 'total_tokens' => 0, 'cost_usd' => 0.0]; + + foreach ($answersRows as $answersJson) { + $answers = json_decode((string) $answersJson, true); + if (!is_array($answers)) { + continue; + } + foreach ($answers as $answer) { + if (!is_array($answer)) { + continue; + } + $usages = $answer['ai_usage_history'] ?? (isset($answer['ai_usage']) ? [$answer['ai_usage']] : []); + if (!is_array($usages)) { + continue; + } + foreach ($usages as $usage) { + if (!is_array($usage)) { + continue; + } + $totals['input_tokens'] += (int) ($usage['input_tokens'] ?? 0); + $totals['output_tokens'] += (int) ($usage['output_tokens'] ?? 0); + $totals['total_tokens'] += (int) ($usage['total_tokens'] ?? 0); + if (is_numeric($usage['cost_usd'] ?? null)) { + $totals['cost_usd'] += (float) $usage['cost_usd']; + } + } + } + } + + return $totals; + } + protected function populateState($ordering = 'r.created', $direction = 'desc') { parent::populateState($ordering, $direction); diff --git a/administrator/components/com_testquestions/src/View/Results/HtmlView.php b/administrator/components/com_testquestions/src/View/Results/HtmlView.php index 872bc3a..9f2d5a7 100644 --- a/administrator/components/com_testquestions/src/View/Results/HtmlView.php +++ b/administrator/components/com_testquestions/src/View/Results/HtmlView.php @@ -15,6 +15,7 @@ class HtmlView extends BaseHtmlView protected $pagination; protected $state; protected $sets; + protected $aiUsageTotals; public function display($tpl = null) { @@ -22,6 +23,7 @@ class HtmlView extends BaseHtmlView $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); $this->sets = $this->get('Sets'); + $this->aiUsageTotals = $this->get('AiUsageTotals'); ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_RESULTS')); ToolbarHelper::link('index.php?option=com_testquestions&view=sets', 'COM_TESTQUESTIONS_SETS', 'back'); diff --git a/administrator/components/com_testquestions/tmpl/results/default.php b/administrator/components/com_testquestions/tmpl/results/default.php index d5d4a60..7ee38d7 100644 --- a/administrator/components/com_testquestions/tmpl/results/default.php +++ b/administrator/components/com_testquestions/tmpl/results/default.php @@ -33,15 +33,24 @@ use Joomla\CMS\Router\Route;
+| - | + | points_before; ?> (%) / points_after; ?> (%) | +escape($grade); ?> | +execution_time / 60); ?>:execution_time % 60), 2, '0', STR_PAD_LEFT); ?> | +created, 'Y-m-d H:i'); ?> | ai_total_tokens > 0) : ?> ai_total_tokens, 0, ',', ' '); ?> escape(\Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_USAGE_TOTAL')); ?> @@ -68,9 +80,6 @@ use Joomla\CMS\Router\Route; — | -escape($grade); ?> | -execution_time / 60); ?>:execution_time % 60), 2, '0', STR_PAD_LEFT); ?> | -created, 'Y-m-d H:i'); ?> | diff --git a/com_testquestions.xml b/com_testquestions.xml index 8bbe7c9..1f89367 100644 --- a/com_testquestions.xml +++ b/com_testquestions.xml @@ -4,7 +4,7 @@
|---|