Add aggregate field crackingTime to AgentAssignment#2329
Conversation
… existing code that did something similar and write tests for checking the correct calculation of total time value
|
A few things to add:
Tests
|
There was a problem hiding this comment.
Pull request overview
Adds a reusable “aggregate cracking time” computation and exposes it as an aggregate field on AgentAssignment (and refactors Agent’s existing aggregate to use the shared implementation), aligning with the enhancement request to aggregate time spent on a specific task by an agent.
Changes:
- Introduces
TaskUtils::getAggregateCrackingTime(agentId, taskId?)to compute summed cracking time from chunk timestamps. - Adds an
assignment.crackingTimeaggregate fieldset toAgentAssignmentAPI. - Adds/updates PHPUnit and API tests to validate the new aggregation behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/inc/utils/TaskUtils.php | Adds shared aggregate cracking-time helper (agent-wide or agent+task). |
| src/inc/apiv2/model/AgentAssignmentAPI.php | Exposes cracking-time aggregation on AgentAssignment via aggregate fieldsets. |
| src/inc/apiv2/model/AgentAPI.php | Refactors Agent crackingTime aggregation to call the shared TaskUtils helper. |
| ci/phpunit/inc/utils/TaskUtilsTest.php | Adds PHPUnit coverage for the new aggregate cracking-time helper. |
| ci/apiv2/test_agentassignment.py | Adds API-level test for AgentAssignment crackingTime aggregation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Calculate reference value via an interval merge algorithm | ||
| $totalEnd = $referenceSum = 0; | ||
| foreach ($timeSpans as [$currentStart, $currentEnd]) { // Expects list to be sorted by time | ||
| $referenceSum = $referenceSum + ($currentEnd - $currentStart) // Add current time span to running total | ||
| - max(0, $totalEnd - $currentStart) // Correct for potential overlapping when current start before previous end | ||
| + max(0, $totalEnd - $currentEnd); // Correct for potential overcorrection when current end before previous end | ||
| $totalEnd = max($totalEnd, $currentEnd); // Extend window if current end exceeds previous end | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
… with the current version
|
I agree with your consolidation, but I think it would be better to move it to AgentUtils and not TaskUtils, as it's agent dependent (and Task only in certain cases). Especially, as this way of do the diff of the sums only works when calculating for one agent, but not if for example we calculate the time which has been spent on task (wall clock time). |
…d-crackingtime-on-agentassignment
…ther code accordingly
|
@s3inlc I moved the code for the cracking time aggregation to the I also refactored the PHP unit test code accordingly to correspond with this change. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Fixes #2297