Backup #1815
| ID | 1815 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Domain/ValueObject/ExecutionMetrics.php |
| Version | 1 |
| Typ |
modified |
| Größe | 2.6 KB |
| Hash | aac550ffa03d9c5d800da1554340ff34e320a7c750d1a1687e7986b5ec36b2ae |
| Datum | 2025-12-27 15:39:09 |
| 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\ValueObject;
// @responsibility: Immutables Value Object für Ausführungs-Metriken (Tokens + Kosten + Dauer)
final class ExecutionMetrics
{
private function __construct(
private TokenCount $tokens,
private ?float $costUsd,
private ?int $durationMs
) {
}
public static function create(TokenCount $tokens, ?float $costUsd = null, ?int $durationMs = null): self
{
return new self($tokens, $costUsd, $durationMs);
}
public static function zero(): self
{
return new self(TokenCount::zero(), null, null);
}
public static function fromEstimation(string $request, string $response): self
{
$inputTokens = max(1, (int) (strlen($request) / 4));
$outputTokens = max(1, (int) (strlen($response) / 4));
return new self(TokenCount::create($inputTokens, $outputTokens), null, null);
}
public function tokens(): TokenCount
{
return $this->tokens;
}
public function costUsd(): ?float
{
return $this->costUsd;
}
public function durationMs(): ?int
{
return $this->durationMs;
}
public function withCost(float $costUsd): self
{
return new self($this->tokens, $costUsd, $this->durationMs);
}
public function withDuration(int $durationMs): self
{
return new self($this->tokens, $this->costUsd, $durationMs);
}
public function withTokens(TokenCount $tokens): self
{
return new self($tokens, $this->costUsd, $this->durationMs);
}
public function hasCost(): bool
{
return $this->costUsd !== null;
}
public function hasDuration(): bool
{
return $this->durationMs !== null;
}
public function format(): string
{
$parts = [$this->tokens->format()];
if ($this->costUsd !== null) {
$parts[] = sprintf('$%.4f', $this->costUsd);
}
if ($this->durationMs !== null) {
if ($this->durationMs < 1000) {
$parts[] = "{$this->durationMs}ms";
} else {
$parts[] = sprintf('%.2fs', $this->durationMs / 1000);
}
}
return implode(' | ', $parts);
}
public function toArray(): array
{
return [
'tokens_input' => $this->tokens->input(),
'tokens_output' => $this->tokens->output(),
'tokens_total' => $this->tokens->total(),
'cost_usd' => $this->costUsd,
'duration_ms' => $this->durationMs,
];
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1816 |
2 |
modified |
2.6 KB |
2025-12-27 15:39 |
| 1815 |
1 |
modified |
2.6 KB |
2025-12-27 15:39 |
← Zurück zur Übersicht