-
Notifications
You must be signed in to change notification settings - Fork 246
Helper edit tasks #1541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Helper edit tasks #1541
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| <?php | ||
|
|
||
| use DBA\Aggregation; | ||
| use DBA\Chunk; | ||
| use DBA\Factory; | ||
| use DBA\QueryFilter; | ||
| use JetBrains\PhpStorm\NoReturn; | ||
| use Middlewares\Utils\HttpErrorException; | ||
| use Psr\Container\ContainerExceptionInterface; | ||
| use Psr\Container\NotFoundExceptionInterface; | ||
| use Psr\Http\Message\ResponseInterface as Response; | ||
| use Psr\Http\Message\ServerRequestInterface as Request; | ||
|
|
||
| require_once(dirname(__FILE__) . "/../common/AbstractHelperAPI.class.php"); | ||
|
|
||
| class TaskExtraDetailsHelper extends AbstractHelperAPI { | ||
| public static function getBaseUri(): string { | ||
| return "/api/v2/helper/taskExtraDetails"; | ||
| } | ||
|
|
||
| public static function getAvailableMethods(): array { | ||
| return ['GET']; | ||
| } | ||
|
|
||
| public function getRequiredPermissions(string $method): array { | ||
| return []; | ||
| } | ||
|
|
||
| public function getFormFields(): array { | ||
| return []; | ||
| } | ||
|
|
||
| /** | ||
| * @throws HttpErrorException | ||
| */ | ||
| public function handleGet(Request $request, Response $response): Response { | ||
| $this->preCommon($request); | ||
|
|
||
| $taskId = $request->getQueryParams()['task']; | ||
| if ($taskId === null) { | ||
| throw new HttpErrorException("No task query param has been provided"); | ||
| } | ||
| $taskId = intval($taskId); | ||
| if ($taskId === 0) { | ||
| throw new HttpErrorException("No valid integer provided as task"); | ||
| } | ||
| $task = Factory::getTaskFactory()->get($taskId); | ||
| if ($task === null) { | ||
| throw new HttpErrorException("No task found for provided task ID"); | ||
| } | ||
|
|
||
| $qF = new QueryFilter(Chunk::TASK_ID, $taskId, "="); | ||
| $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); | ||
| $currentSpeed = 0; | ||
| $cProgress = 0; | ||
| foreach ($chunks as $chunk) { | ||
| $cProgress += $chunk->getCheckpoint() - $chunk->getSkip(); | ||
| if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) { | ||
| $currentSpeed += $chunk->getSpeed(); | ||
| } | ||
| } | ||
|
|
||
| $timeChunks = $chunks; | ||
| usort($timeChunks, "Util::compareChunksTime"); | ||
| $timeSpent = 0; | ||
| $current = 0; | ||
| foreach ($timeChunks as $c) { | ||
| if ($c->getDispatchTime() > $current) { | ||
| $timeSpent += $c->getSolveTime() - $c->getDispatchTime(); | ||
| $current = $c->getSolveTime(); | ||
| } | ||
| else if ($c->getSolveTime() > $current) { | ||
| $timeSpent += $c->getSolveTime() - $current; | ||
| $current = $c->getSolveTime(); | ||
| } | ||
| } | ||
| $keyspace = $task->getKeyspace(); | ||
| $estimatedTime = ($keyspace > 0 && $cProgress > 0) ? round($timeSpent / ($cProgress / $keyspace) - $timeSpent) : 0; | ||
| $responseObject = [ | ||
| "estimatedTime" => $estimatedTime, | ||
| "timeSpent" => $timeSpent, | ||
| "currentSpeed" => $currentSpeed, | ||
| ]; | ||
|
|
||
| return self::getMetaResponse($responseObject, $request, $response); | ||
| } | ||
|
|
||
| #[NoReturn] public function actionPost($data): object|array|null { | ||
| assert(false, "TaskExtraDetails has no POST"); | ||
| } | ||
|
|
||
| static public function register($app): void { | ||
| $baseUri = TaskExtraDetailsHelper::getBaseUri(); | ||
|
|
||
| /* Allow CORS preflight requests */ | ||
| $app->options($baseUri, function (Request $request, Response $response): Response { | ||
| return $response; | ||
| }); | ||
| $app->get($baseUri, "TaskExtraDetailsHelper:handleGet"); | ||
| } | ||
|
|
||
| /** | ||
| * getAccessGroups is different because it returns via another function | ||
| */ | ||
| public static function getResponse(): array|string|null { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| TaskExtraDetailsHelper::register($app); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.