Backup #1372
| ID | 1372 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Domain/Entity/TaskResult.php |
| Version | 2 |
| Typ |
modified |
| Größe | 9.4 KB |
| Hash | 361c5c224cf6a02a883164f6d24e6a1b9ca1a334d70933d3cffd4d284b709e31 |
| Datum | 2025-12-25 16:56:36 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace Domain\Entity;
// @responsibility: Task-Ergebnis-Entität mit Token-Tracking
use Domain\ValueObject\AssigneeType;
class TaskResult
{
private ?int $id = null;
private int $taskId;
private ?int $assignmentId = null;
private string $executor;
private AssigneeType $executorType;
private ?string $modelName = null;
private ?string $request = null;
private ?string $response = null;
private \DateTimeImmutable $requestTimestamp;
private ?\DateTimeImmutable $responseTimestamp = null;
private ?int $durationMs = null;
private ?int $tokensInput = null;
private ?int $tokensOutput = null;
private ?int $tokensTotal = null;
private ?float $costUsd = null;
private string $status = 'success';
private ?string $errorMessage = null;
private \DateTimeImmutable $createdAt;
public function __construct()
{
$this->requestTimestamp = new \DateTimeImmutable();
$this->createdAt = new \DateTimeImmutable();
}
// Getters
public function getId(): ?int
{
return $this->id;
}
public function getTaskId(): int
{
return $this->taskId;
}
public function getAssignmentId(): ?int
{
return $this->assignmentId;
}
public function getExecutor(): string
{
return $this->executor;
}
public function getExecutorType(): AssigneeType
{
return $this->executorType;
}
public function getModelName(): ?string
{
return $this->modelName;
}
public function getRequest(): ?string
{
return $this->request;
}
public function getResponse(): ?string
{
return $this->response;
}
public function getRequestTimestamp(): \DateTimeImmutable
{
return $this->requestTimestamp;
}
public function getResponseTimestamp(): ?\DateTimeImmutable
{
return $this->responseTimestamp;
}
public function getDurationMs(): ?int
{
return $this->durationMs;
}
public function getTokensInput(): ?int
{
return $this->tokensInput;
}
public function getTokensOutput(): ?int
{
return $this->tokensOutput;
}
public function getTokensTotal(): ?int
{
return $this->tokensTotal;
}
public function getCostUsd(): ?float
{
return $this->costUsd;
}
public function getStatus(): string
{
return $this->status;
}
public function getErrorMessage(): ?string
{
return $this->errorMessage;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
// Setters
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function setTaskId(int $taskId): self
{
$this->taskId = $taskId;
return $this;
}
public function setAssignmentId(?int $assignmentId): self
{
$this->assignmentId = $assignmentId;
return $this;
}
public function setExecutor(string $executor): self
{
$this->executor = $executor;
return $this;
}
public function setExecutorType(AssigneeType $executorType): self
{
$this->executorType = $executorType;
return $this;
}
public function setModelName(?string $modelName): self
{
$this->modelName = $modelName;
return $this;
}
public function setRequest(?string $request): self
{
$this->request = $request;
return $this;
}
public function setResponse(?string $response): self
{
$this->response = $response;
$this->responseTimestamp = new \DateTimeImmutable();
$this->calculateDuration();
return $this;
}
public function setRequestTimestamp(\DateTimeImmutable $requestTimestamp): self
{
$this->requestTimestamp = $requestTimestamp;
return $this;
}
public function setResponseTimestamp(?\DateTimeImmutable $responseTimestamp): self
{
$this->responseTimestamp = $responseTimestamp;
$this->calculateDuration();
return $this;
}
public function setDurationMs(?int $durationMs): self
{
$this->durationMs = $durationMs;
return $this;
}
public function setTokensInput(?int $tokensInput): self
{
$this->tokensInput = $tokensInput;
$this->calculateTotalTokens();
return $this;
}
public function setTokensOutput(?int $tokensOutput): self
{
$this->tokensOutput = $tokensOutput;
$this->calculateTotalTokens();
return $this;
}
public function setTokensTotal(?int $tokensTotal): self
{
$this->tokensTotal = $tokensTotal;
return $this;
}
public function setCostUsd(?float $costUsd): self
{
$this->costUsd = $costUsd;
return $this;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function setErrorMessage(?string $errorMessage): self
{
$this->errorMessage = $errorMessage;
if ($errorMessage !== null) {
$this->status = 'error';
}
return $this;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
private function calculateDuration(): void
{
if ($this->responseTimestamp !== null) {
$diff = $this->responseTimestamp->getTimestamp() - $this->requestTimestamp->getTimestamp();
$this->durationMs = $diff * 1000;
}
}
private function calculateTotalTokens(): void
{
if ($this->tokensInput !== null && $this->tokensOutput !== null) {
$this->tokensTotal = $this->tokensInput + $this->tokensOutput;
}
}
public function estimateTokens(): void
{
if ($this->request !== null) {
$this->tokensInput = max(1, (int) (strlen($this->request) / 4));
}
if ($this->response !== null) {
$this->tokensOutput = max(1, (int) (strlen($this->response) / 4));
}
$this->calculateTotalTokens();
}
public function toArray(): array
{
return [
'id' => $this->id,
'task_id' => $this->taskId,
'assignment_id' => $this->assignmentId,
'executor' => $this->executor,
'executor_type' => $this->executorType->value,
'model_name' => $this->modelName,
'request' => $this->request,
'response' => $this->response,
'request_timestamp' => $this->requestTimestamp->format('Y-m-d H:i:s.u'),
'response_timestamp' => $this->responseTimestamp?->format('Y-m-d H:i:s.u'),
'duration_ms' => $this->durationMs,
'tokens_input' => $this->tokensInput,
'tokens_output' => $this->tokensOutput,
'tokens_total' => $this->tokensTotal,
'cost_usd' => $this->costUsd,
'status' => $this->status,
'error_message' => $this->errorMessage,
'created_at' => $this->createdAt->format('Y-m-d H:i:s.u'),
];
}
public static function fromArray(array $data): self
{
$result = new self();
if (isset($data['id'])) {
$result->setId((int) $data['id']);
}
if (isset($data['task_id'])) {
$result->setTaskId((int) $data['task_id']);
}
if (isset($data['assignment_id'])) {
$result->setAssignmentId((int) $data['assignment_id']);
}
if (isset($data['executor'])) {
$result->setExecutor($data['executor']);
}
if (isset($data['executor_type'])) {
$result->executorType = AssigneeType::from($data['executor_type']);
}
if (isset($data['model_name'])) {
$result->setModelName($data['model_name']);
}
if (isset($data['request'])) {
$result->request = $data['request'];
}
if (isset($data['response'])) {
$result->response = $data['response'];
}
if (isset($data['request_timestamp'])) {
$result->setRequestTimestamp(new \DateTimeImmutable($data['request_timestamp']));
}
if (isset($data['response_timestamp'])) {
$result->setResponseTimestamp(new \DateTimeImmutable($data['response_timestamp']));
}
if (isset($data['duration_ms'])) {
$result->setDurationMs((int) $data['duration_ms']);
}
if (isset($data['tokens_input'])) {
$result->tokensInput = (int) $data['tokens_input'];
}
if (isset($data['tokens_output'])) {
$result->tokensOutput = (int) $data['tokens_output'];
}
if (isset($data['tokens_total'])) {
$result->tokensTotal = (int) $data['tokens_total'];
}
if (isset($data['cost_usd'])) {
$result->setCostUsd((float) $data['cost_usd']);
}
if (isset($data['status'])) {
$result->status = $data['status'];
}
if (isset($data['error_message'])) {
$result->errorMessage = $data['error_message'];
}
if (isset($data['created_at'])) {
$result->setCreatedAt(new \DateTimeImmutable($data['created_at']));
}
return $result;
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 2000 |
8 |
modified |
7.0 KB |
2025-12-28 14:17 |
| 1949 |
7 |
modified |
7.4 KB |
2025-12-28 02:24 |
| 1948 |
6 |
modified |
7.7 KB |
2025-12-28 02:23 |
| 1400 |
5 |
modified |
7.6 KB |
2025-12-25 16:58 |
| 1385 |
4 |
modified |
7.9 KB |
2025-12-25 16:57 |
| 1381 |
3 |
modified |
9.2 KB |
2025-12-25 16:57 |
| 1372 |
2 |
modified |
9.4 KB |
2025-12-25 16:56 |
| 810 |
1 |
modified |
9.3 KB |
2025-12-23 08:08 |
← Zurück zur Übersicht