Skip to content

Commit

Permalink
Merge branch 'release-13.7.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Nov 27, 2023
2 parents 2613200 + f18a583 commit 91cacce
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 22 deletions.
6 changes: 3 additions & 3 deletions models/Events/DeliveryExecutionResultsRecalculated.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class DeliveryExecutionResultsRecalculated implements Event
private ?float $totalScore;
private ?float $totalMaxScore;
private bool $isFullyGraded;
private int $timestamp;
private ?string $timestamp;

public function __construct(
DeliveryExecutionInterface $deliveryExecution,
?float $totalScore,
?float $totalMaxScore,
bool $isFullyGraded,
int $timestamp
?string $timestamp
) {
$this->deliveryExecution = $deliveryExecution;
$this->totalScore = $totalScore;
Expand Down Expand Up @@ -73,7 +73,7 @@ public function isFullyGraded(): bool
return $this->isFullyGraded;
}

public function getTimestamp(): int
public function getTimestamp(): ?string
{
return $this->timestamp;
}
Expand Down
3 changes: 3 additions & 0 deletions models/Import/Service/ResultImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ private function updateTestVariables(
string $testUri,
float $updatedScoreTotal
): void {
if ($scoreTotalVariable->getValue() != $updatedScoreTotal) {
$scoreTotalVariable->setEpoch(microtime());
}
$scoreTotalVariable->setValue($updatedScoreTotal);

$resultStorage->replaceTestVariables(
Expand Down
50 changes: 35 additions & 15 deletions models/Import/Service/SendCalculatedResultService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
use oat\taoResultServer\models\classes\implementation\ResultServerService;
use oat\taoResultServer\models\Events\DeliveryExecutionResultsRecalculated;
use stdClass;
use taoResultServer_models_classes_OutcomeVariable;
use taoResultServer_models_classes_ReadableResultStorage as ReadableResultStorage;
use taoResultServer_models_classes_Variable as ResultVariable;
use taoResultServer_models_classes_OutcomeVariable as OutcomeVariable;
use tao_helpers_Date as DateHelper;

class SendCalculatedResultService
{
Expand Down Expand Up @@ -66,10 +67,10 @@ public function sendByDeliveryExecutionId(string $deliveryExecutionId): array

$isFullyGraded = $this->checkIsFullyGraded($deliveryExecutionId, $outcomeVariables);

$timestamp = $this->secondsFromMicrotime($deliveryExecution->getFinishTime());
$timestamp = DateHelper::formatMicrotime($deliveryExecution->getFinishTime());

if ($isFullyGraded) {
$outcomeTimestamp = $this->getLatestOutcomesTimestamp($outcomeVariables);
$timestamp = max($outcomeTimestamp, $timestamp);
$timestamp = DateHelper::formatMicrotime($this->getLatestOutcomesTimestamp($outcomeVariables));
}

$this->eventManager->trigger(
Expand Down Expand Up @@ -194,25 +195,44 @@ private function isSubjectOutcomeVariableGraded(
return false;
}

private function secondsFromMicrotime(string $microtime): int
{
list(, $seconds) = explode(' ', $microtime);

return (int) $seconds;
}

private function getLatestOutcomesTimestamp(array $outcomeVariables): ?int
private function getLatestOutcomesTimestamp(array $outcomeVariables): ?string
{
$microtimeList = array_map(function ($outcome) {
$outcome = end($outcome);
if ($outcome->variable instanceof taoResultServer_models_classes_OutcomeVariable) {
if ($outcome->variable instanceof OutcomeVariable) {
return $outcome->variable->getEpoch();
}
return 0;
}, $outcomeVariables);
$sortedMicrotime = $this->sortMicrotimeList(array_filter($microtimeList));
return array_pop($sortedMicrotime);
}

private function sortMicrotimeList(array $microtimeList): array
{
usort($microtimeList, function ($a, $b) {
// Extract the values from each string
$microtimeA = explode(' ', $a);
$microtimeB = explode(' ', $b);

// Compare the timestamp values
$compareTimestamp = (float)$microtimeA[1] - (float)$microtimeB[1];

// If the timestamp values are equal, compare the microseconds
if ($compareTimestamp == 0) {
$d = (float)$microtimeA[0] - (float)$microtimeB[0];
if ($d == 0) {
return 0;
} elseif ($d > 0) {
return 1;
} else {
return -1;
}
}

$timestampList = array_map('self::secondsFromMicrotime', array_filter($microtimeList));
return $compareTimestamp;
});

return max($timestampList);
return $microtimeList;
}
}
3 changes: 2 additions & 1 deletion models/Import/Task/ImportResultTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ public function __invoke($params = [])
return Report::createSuccess($message);
} catch (Throwable $exception) {
$message = sprintf(
'[DeliveryExecutionResults] Error [%s] importing results [%s]',
'[DeliveryExecutionResults] Error [%s] Stacktrace [%s] importing results [%s]',
$exception->getMessage(),
$exception->getTraceAsString(),
isset($importResult) ? var_export($importResult->jsonSerialize(), true) : ''
);

Expand Down
11 changes: 8 additions & 3 deletions test/Unit/models/Import/Service/ResultImporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ public function testCreateByImportResult(): void
'executionId',
'testUri',
'executionId',
[
777 => $this->createTestVariable(4, 'SCORE_TOTAL'),
]
$this->callback(function ($array) {
$variable = array_pop($array);
return $variable->getIdentifier() === 'SCORE_TOTAL'
&& $variable->getCardinality() === 'single'
&& $variable->getBaseType() === 'float'
&& $variable->getExternallyGraded() === false;
})
);

$this->resultStorage
Expand Down Expand Up @@ -515,6 +519,7 @@ private function createTestVariable(
$variable->setIdentifier($identifier);
$variable->setCardinality('single');
$variable->setBaseType('float');
$variable->setEpoch(microtime());

return $variable;
}
Expand Down

0 comments on commit 91cacce

Please sign in to comment.