int, "exampleIndex" => int, "error" => float, "synaptic_weights" => array] public string $sessionId, public string $trainingId, ) { // } /** * Get the channels the event should broadcast on. * * @return array */ public function broadcastOn(): array { // Log::debug("Broadcasting on channel: " . $this->sessionId . '-perceptron-training'); return [ new Channel($this->sessionId.'-perceptron-training'), ]; } public function broadcastWith(): array { $iterations = self::normalizeForJson($this->iterations); $weights = collect($iterations) ->pluck('weights') ->first(fn (array $weights): bool => $weights !== []); $shouldBroadcastAllWeights = $weights !== null && count(Arr::flatten($weights)) <= config('perceptron.max_displayed_weights'); $lastIterationIndex = count($iterations) - 1; $iterations = array_map( fn (array $iteration, int $index): array => $shouldBroadcastAllWeights || $index === $lastIterationIndex ? $iteration : [...$iteration, 'weights' => []], $iterations, array_keys($iterations), ); return [ 'iterations' => $iterations, 'trainingId' => $this->trainingId, ]; } public static function normalizeForJson(mixed $value): mixed { if (is_float($value) && ! is_finite($value)) { return null; } if (! is_array($value)) { return $value; } return array_map( fn (mixed $item): mixed => self::normalizeForJson($item), $value, ); } }