extractData($datesDir); // dd($this->processingUnits); $this->calculateStatistics(); // Output the statistics $this->info('Total sum: '.$this->totalSum); $this->info('Total count: '.$this->totalCount); $this->info('Overall average: '.$this->overallAvg); $this->info('Standard deviation: '.$this->stdDev); } private function extractProcessingUnitsFromFile($filePath) { $data = json_decode(Storage::get($filePath), true); $responseHeaders = $data['response']['headers']; $processingUnits = $responseHeaders['x-processingunits-spent']; return $processingUnits; } private function calculateStatistics() { foreach ($this->processingUnits as $date => $values) { $processingUnitsPerDate = array_sum($values); $this->totalSum += $processingUnitsPerDate; $this->totalCount++; $this->allValues[$date] = $processingUnitsPerDate; } $this->overallAvg = $this->totalSum / $this->totalCount; $variance = array_reduce($this->allValues, function ($carry, $item) { return $carry + pow($item - $this->overallAvg, 2); }, 0) / $this->totalCount; $this->stdDev = sqrt($variance); } private function extractData(array $datesDir): void { foreach ($datesDir as $dateDir) { $date = basename($dateDir); $subdirectories = Storage::directories($dateDir); $this->processingUnits[$date] = []; foreach ($subdirectories as $subdirectory) { $requestPath = $subdirectory.'/request.json'; if (Storage::fileExists($requestPath)) { $this->processingUnits[$date][] = $this->extractProcessingUnitsFromFile($requestPath); } } } } }