Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/inc/apiv2/common/AbstractBaseAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ protected function getFeatures(): array
return $features;
}

/**
* Overidable function to aggregate data in the object. Currently only used for Tasks
* returns the aggregated data in key value pairs
*/
public static function aggregateData(object $object): array {
return [];
}

/**
* Take all the dba features and converts them to a list.
* It uses the data from the generator and replaces the keys with the aliasses.
Expand Down Expand Up @@ -517,6 +525,9 @@ protected function obj2Resource(object $obj, array $expandResult = [])
$attributes[$feature['alias']] = $apiClass::db2json($feature, $kv[$name]);
}

//TODO: only aggregate data when it has been included
$aggregatedData = $apiClass::aggregateData($obj);
$attributes = array_merge($attributes, $aggregatedData);

/* Build JSON::API relationship resource */
$toManyRelationships = $apiClass::getToManyRelationships();
Expand Down Expand Up @@ -890,6 +901,7 @@ protected function getPrimaryKey(): string
return $key;
}
}
throw new HTException("Internal error: no primary key found");
}

function getFilters(Request $request) {
Expand All @@ -899,7 +911,6 @@ function getFilters(Request $request) {
/**
* Check for valid filter parameters and build QueryFilter
*/
// protected function makeFilter(Request $request, array $features): array
protected function makeFilter(array $filters, object $apiClass): array
{
$qFs = [];
Expand Down
1 change: 1 addition & 0 deletions src/inc/apiv2/common/AbstractModelAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ protected function getPrimaryKeyOther(string $dbaClass): string
return $key;
}
}
throw new HTException("Internal error: no primary key found");
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/inc/apiv2/model/tasks.routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use DBA\Speed;
use DBA\Task;
use DBA\TaskWrapper;
use Util;

require_once(dirname(__FILE__) . "/../common/AbstractModelAPI.class.php");

Expand Down Expand Up @@ -125,6 +126,13 @@ protected function createObject(array $data): int {
return $object->getId();
}

static function aggregateData(object $object): array {
$aggregatedData["Dispatched"] = Util::showperc($object->getKeyspaceProgress(), $object->getKeyspace());
$aggregatedData["Searched"] = Util::showperc(TaskUtils::getTaskProgress($object), $object->getKeyspace());

return $aggregatedData;
}

protected function deleteObject(object $object): void {
TaskUtils::deleteTask($object);
}
Expand Down
11 changes: 11 additions & 0 deletions src/inc/utils/TaskUtils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use DBA\TaskDebugOutput;
use DBA\Factory;
use DBA\Speed;
use DBA\Aggregation;

class TaskUtils {
/**
Expand Down Expand Up @@ -1393,4 +1394,14 @@ public static function isSaturatedByOtherAgents($task, $agent) {
return ($task->getIsSmall() == 1 && $numAssignments > 0) || // at least one agent is already assigned here
($task->getMaxAgents() > 0 && $numAssignments >= $task->getMaxAgents()); // at least maxAgents agents are already assigned
}

public static function getTaskProgress($task) {
$qF1 = new QueryFilter(Chunk::TASK_ID, $task->getId(), "=");

$agg1 = new Aggregation(Chunk::CHECKPOINT, Aggregation::SUM);
$agg2 = new Aggregation(Chunk::SKIP, Aggregation::SUM);
$results = Factory::getChunkFactory()->multicolAggregationFilter([Factory::FILTER => $qF1], [$agg1, $agg2]);
$progress = $results[$agg1->getName()] - $results[$agg2->getName()];
return $progress;
}
}