<?php
declare(strict_types=1);
namespace PpPhp\Core\Platform\Event\Streaming\Replay;
final class StreamPersistenceStatistics
{
    public static function from(array $events, array $replays): array { $topics=[]; foreach($events as $event){$topic=(string)($event['topic']??''); if($topic!=='') $topics[$topic]=true;} $replayed=0; $totalTime=0.0; foreach($replays as $replay){$replayed+=(int)($replay['replayed']??0); $totalTime+=(float)($replay['replayTimeMs']??0);} return ['events'=>count($events),'topics'=>count($topics),'replays'=>count($replays),'replayed'=>$replayed,'averageReplayTimeMs'=>count($replays)>0?round($totalTime/count($replays),3):0,'throughput'=>$totalTime>0?round(($replayed/max(0.001,$totalTime))*1000,2):0]; }
}
