diff --git a/README.md b/README.md index 59763cb..d082be6 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.10). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.11). Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**. diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.43.11.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.43.11.sql new file mode 100644 index 0000000..a282b6c --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.43.11.sql @@ -0,0 +1 @@ +-- No database changes required for version 1.43.11. diff --git a/administrator/components/com_testquestions/src/Model/ResultsModel.php b/administrator/components/com_testquestions/src/Model/ResultsModel.php index 9d97583..819ca43 100644 --- a/administrator/components/com_testquestions/src/Model/ResultsModel.php +++ b/administrator/components/com_testquestions/src/Model/ResultsModel.php @@ -18,6 +18,7 @@ class ResultsModel extends ListModel $item->ai_output_tokens = 0; $item->ai_total_tokens = 0; $item->ai_cost_usd = 0.0; + $item->ai_tokens_by_provider = ['openai' => 0, 'grok' => 0]; $answers = json_decode((string) ($item->answers ?? ''), true); if (!is_array($answers)) { @@ -41,6 +42,10 @@ class ResultsModel extends ListModel $item->ai_input_tokens += (int) ($usage['input_tokens'] ?? 0); $item->ai_output_tokens += (int) ($usage['output_tokens'] ?? 0); $item->ai_total_tokens += (int) ($usage['total_tokens'] ?? 0); + $provider = (string) ($usage['provider'] ?? ''); + if (isset($item->ai_tokens_by_provider[$provider])) { + $item->ai_tokens_by_provider[$provider] += (int) ($usage['total_tokens'] ?? 0); + } if (is_numeric($usage['cost_usd'] ?? null)) { $item->ai_cost_usd += (float) $usage['cost_usd']; } @@ -57,7 +62,14 @@ class ResultsModel extends ListModel $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]; + $emptyProviderTotals = ['input_tokens' => 0, 'output_tokens' => 0, 'total_tokens' => 0, 'cost_usd' => 0.0]; + $totals = [ + 'input_tokens' => 0, + 'output_tokens' => 0, + 'total_tokens' => 0, + 'cost_usd' => 0.0, + 'providers' => ['openai' => $emptyProviderTotals, 'grok' => $emptyProviderTotals], + ]; foreach ($answersRows as $answersJson) { $answers = json_decode((string) $answersJson, true); @@ -82,6 +94,15 @@ class ResultsModel extends ListModel if (is_numeric($usage['cost_usd'] ?? null)) { $totals['cost_usd'] += (float) $usage['cost_usd']; } + $provider = (string) ($usage['provider'] ?? ''); + if (isset($totals['providers'][$provider])) { + $totals['providers'][$provider]['input_tokens'] += (int) ($usage['input_tokens'] ?? 0); + $totals['providers'][$provider]['output_tokens'] += (int) ($usage['output_tokens'] ?? 0); + $totals['providers'][$provider]['total_tokens'] += (int) ($usage['total_tokens'] ?? 0); + if (is_numeric($usage['cost_usd'] ?? null)) { + $totals['providers'][$provider]['cost_usd'] += (float) $usage['cost_usd']; + } + } } } } diff --git a/administrator/components/com_testquestions/tmpl/results/default.php b/administrator/components/com_testquestions/tmpl/results/default.php index 7ee38d7..881dc3e 100644 --- a/administrator/components/com_testquestions/tmpl/results/default.php +++ b/administrator/components/com_testquestions/tmpl/results/default.php @@ -34,13 +34,22 @@ use Joomla\CMS\Router\Route;
| created, 'Y-m-d H:i'); ?> |
ai_total_tokens > 0) : ?>
- ai_total_tokens, 0, ',', ' '); ?> escape(\Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_USAGE_TOTAL')); ?>
- ai_input_tokens, 0, ',', ' '); ?> in /
- ai_output_tokens, 0, ',', ' '); ?> out
+ OpenAI: ai_tokens_by_provider['openai'], 0, ',', ' '); ?> ·
+ Grok: ai_tokens_by_provider['grok'], 0, ',', ' '); ?>
+
+
+ ai_total_tokens, 0, ',', ' '); ?> łącznie
ai_cost_usd > 0) : ?> · ai_cost_usd, 8, ',', ' '); ?> USD
diff --git a/com_testquestions.xml b/com_testquestions.xml
index 1f89367..c4db9a4 100644
--- a/com_testquestions.xml
+++ b/com_testquestions.xml
@@ -4,7 +4,7 @@
|