public static function buildTableData(array $torrentList) { $headers = ['Name', 'Id', 'Age', 'Size', 'Uploaded', 'Per day']; $rows = []; foreach ($torrentList as $torrent) { $age = TorrentUtils::getTorrentAgeInDays($torrent); $perDay = $age ? TorrentUtils::getSizeInGb($torrent[Torrent\Get::UPLOAD_EVER] / $age) : 0; $rows[] = [$torrent[Torrent\Get::NAME], $torrent[Torrent\Get::ID], $age, TorrentUtils::getSizeInGb($torrent[Torrent\Get::TOTAL_SIZE]), TorrentUtils::getSizeInGb($torrent[Torrent\Get::UPLOAD_EVER]), $perDay]; } return ['headers' => $headers, 'rows' => $rows]; }
private function buildTableData(array $torrentList, $sort, $limit) { $rows = []; foreach ($torrentList as $torrent) { $rows[] = [$torrent[Torrent\Get::NAME], $torrent[Torrent\Get::ID], $torrent['age'], TorrentUtils::getSizeInGb($torrent[Torrent\Get::TOTAL_SIZE]), TorrentUtils::getSizeInGb($torrent['uploaded']), $torrent['per_day'], $torrent['profit']]; } $rows = TableUtils::sortRowsByColumnNumber($rows, $sort); $rows = TableUtils::limitRows($rows, $limit); return ['headers' => ['Name', 'Id', 'Age, days', 'Size, GB', 'Uploaded, GB', 'Per day, GB', 'Profit, %'], 'rows' => $rows, 'totals' => ['Total: ' . count($rows), '', '', TorrentListUtils::sumArrayField($rows, 3), TorrentListUtils::sumArrayField($rows, 4), TorrentListUtils::sumArrayField($rows, 5), TorrentListUtils::sumArrayField($rows, 6)]]; }
protected function execute(InputInterface $input, OutputInterface $output) { $client = $this->getApplication()->getClient(); $torrentList = $client->getTorrentData(); $torrentList = array_map(function ($torrent) { $torrent['age'] = TorrentUtils::getTorrentAgeInDays($torrent); return $torrent; }, $torrentList); $torrentList = TorrentListUtils::filterTorrents($torrentList, ['age' => $input->getOption('age'), 'name' => $input->getOption('name')]); TorrentListUtils::printTorrentsTable($torrentList, $output, $input->getOption('sort'), $input->getOption('limit')); $freeSpace = $client->getFreeSpace(); $output->writeln('Free space: ' . TorrentUtils::getSizeInGb($freeSpace) . ' GB'); }