Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9eedcab
commit 1c759ba
Showing
15 changed files
with
2,137 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: php | ||
|
||
php: 7.3 | ||
php: '7.3' | ||
|
||
install: | ||
- composer install | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
layout: "_layouts/default.twig" | ||
title: "PHP Framework Trends" | ||
id: trends | ||
--- | ||
|
||
<div class="container-fluid" id="blog"> | ||
<h1>{{ title }}</h1> | ||
|
||
{% for framework in php_framework_trends %} | ||
<table class="table table-bordered"> | ||
<thead class="thead-inverse"> | ||
<tr> | ||
<th colspan="4" class="text-center"> | ||
<h3>{{ framework.name }}</h3> | ||
</th> | ||
</tr> | ||
<tr> | ||
<th>Package</th> | ||
<th class="text-center"> | ||
Last month Daily | ||
<p class="text-muted text"> | ||
Total {{ framework.vendor_total_last_month|number_format }} | ||
</p> | ||
</th> | ||
<th class="text-center"> | ||
Total Last Year | ||
<p class="text-muted text"> | ||
Total {{ framework.vendor_total_last_year|number_format }} | ||
</p> | ||
</th> | ||
<th class="text-center"> | ||
Trend Last Year | ||
<p class="text-muted text"> | ||
{{ framework.average_last_year_trend }} % | ||
</p> | ||
</th> | ||
</tr> | ||
</thead> | ||
{% for package in framework.packages_data %} | ||
<tr> | ||
<th> | ||
{{ package.package_name }} | ||
<small class="text-muted"> | ||
<a href="https://packagist.org/packages/{{ package.package_name }}/stats">see downloads</a> | ||
</small> | ||
</th> | ||
|
||
<td class="text-right">{{ package.last_month_average_daily_downloads|number_format }}</td> | ||
<td class="text-right">{{ package.last_year_total|number_format }}</td> | ||
<td class="text-right"> | ||
<strong> | ||
{% if package.last_year_trend > 0 %} | ||
<span class="text-success"> | ||
+{{ package.last_year_trend|number_format }} % | ||
</span> | ||
{% else %} | ||
<span class="text-danger"> | ||
{{ package.last_year_trend|number_format }} % | ||
</span> | ||
{% endif %} | ||
</strong> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
|
||
<br> | ||
<br> | ||
{% endfor %} | ||
|
||
<p>Notes</p> | ||
|
||
<ul> | ||
<li>packages with <strong>less than 500 downloads</strong> a month were dropped</li> | ||
<li>phpstan/phpstan downloads are cleaned from statistics to prevent miss-leading numbers</li> | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace TomasVotruba\Website; | ||
|
||
final class ArrayUtils | ||
{ | ||
/** | ||
* @param mixed[] $packagesData | ||
*/ | ||
public function getArrayKeyAverage(array $packagesData, string $key): float | ||
{ | ||
$total = []; | ||
foreach ($packagesData as $packageData) { | ||
$total[] = $packageData[$key]; | ||
} | ||
|
||
$average = array_sum($total) / count($total); | ||
|
||
return round($average, 2); | ||
} | ||
|
||
/** | ||
* @param mixed[] $array | ||
*/ | ||
public function getArrayKeySum(array $array, string $key): int | ||
{ | ||
$total = 0; | ||
foreach ($array as $item) { | ||
$total += (int) $item[$key]; | ||
} | ||
|
||
return $total; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace TomasVotruba\Website\Command; | ||
|
||
use Nette\Utils\DateTime; | ||
use Nette\Utils\Strings; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symplify\PackageBuilder\Console\Command\CommandNaming; | ||
use Symplify\PackageBuilder\Console\ShellCode; | ||
use Symplify\Statie\FileSystem\GeneratedFilesDumper; | ||
use TomasVotruba\Website\ArrayUtils; | ||
use TomasVotruba\Website\Exception\ShouldNotHappenException; | ||
use TomasVotruba\Website\Packagist\PackageMonthlyDownloadsProvider; | ||
use TomasVotruba\Website\Packagist\VendorPackagesProvider; | ||
use TomasVotruba\Website\Statistics; | ||
|
||
final class GeneratePackageStatsCommand extends Command | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $frameworkVendorToName = [ | ||
'nette' => 'Nette', | ||
'symfony' => 'Symfony', | ||
// laravel | ||
'illuminate' => 'Laravel', | ||
'cakephp' => 'CakePHP', | ||
// single monorepos | ||
'zendframework' => 'Zend', | ||
'yiisoft' => 'Yii', | ||
'codeigniter' => 'Code Igniter', | ||
]; | ||
|
||
/** | ||
* @var SymfonyStyle | ||
*/ | ||
private $symfonyStyle; | ||
|
||
/** | ||
* @var GeneratedFilesDumper | ||
*/ | ||
private $generatedFilesDumper; | ||
|
||
/** | ||
* @var PackageMonthlyDownloadsProvider | ||
*/ | ||
private $packageMonthlyDownloadsProvider; | ||
|
||
/** | ||
* @var VendorPackagesProvider | ||
*/ | ||
private $vendorPackagesProvider; | ||
|
||
/** | ||
* @var ArrayUtils | ||
*/ | ||
private $arrayUtils; | ||
|
||
/** | ||
* @var Statistics | ||
*/ | ||
private $statistics; | ||
|
||
public function __construct( | ||
SymfonyStyle $symfonyStyle, | ||
GeneratedFilesDumper $generatedFilesDumper, | ||
PackageMonthlyDownloadsProvider $packageMonthlyDownloadsProvider, | ||
VendorPackagesProvider $vendorPackagesProvider, | ||
ArrayUtils $arrayUtils, | ||
Statistics $statistics | ||
) { | ||
parent::__construct(); | ||
$this->symfonyStyle = $symfonyStyle; | ||
$this->generatedFilesDumper = $generatedFilesDumper; | ||
$this->packageMonthlyDownloadsProvider = $packageMonthlyDownloadsProvider; | ||
$this->vendorPackagesProvider = $vendorPackagesProvider; | ||
$this->arrayUtils = $arrayUtils; | ||
$this->statistics = $statistics; | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this->setName(CommandNaming::classToName(self::class)); | ||
$this->setDescription('Generates downloads stats data for PHP frameworks'); | ||
|
||
// @todo include releases, how often, median | ||
// @todo | ||
// - phpstan | ||
// - phpunit | ||
// - php-cs-fixer | ||
// - php code sniffer | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$vendorData = $this->createVendorData(); | ||
$this->generatedFilesDumper->dump('php_framework_trends', $vendorData); | ||
$this->symfonyStyle->success('Data imported!'); | ||
|
||
return ShellCode::SUCCESS; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
private function createVendorData(): array | ||
{ | ||
$vendorData = []; | ||
|
||
foreach ($this->frameworkVendorToName as $vendorName => $frameworkName) { | ||
$packagesInVendorJson = $this->vendorPackagesProvider->provideForVendor($vendorName); | ||
|
||
$this->symfonyStyle->title(sprintf('Loading data for "%s" vendor', $vendorName)); | ||
if (! isset($packagesInVendorJson['packageNames'])) { | ||
throw new ShouldNotHappenException(); | ||
} | ||
|
||
$packagesData = []; | ||
foreach ($packagesInVendorJson['packageNames'] as $packageName) { | ||
$monthlyDownloadsFromOldestToNewest = $this->packageMonthlyDownloadsProvider->provideForPackage( | ||
$packageName | ||
); | ||
|
||
$packageKey = $this->createPackageKey($packageName); | ||
|
||
$lastMonthDailyDownloads = $monthlyDownloadsFromOldestToNewest[0]; | ||
|
||
// few data → skip | ||
if ($lastMonthDailyDownloads <= 500) { | ||
continue; | ||
} | ||
|
||
$lastYearTrend = $this->statistics->resolveTrend($monthlyDownloadsFromOldestToNewest, 12); | ||
if ($lastYearTrend === null) { | ||
continue; | ||
} | ||
|
||
$packageData = [ | ||
'package_name' => $packageName, | ||
'last_month_average_daily_downloads' => $lastMonthDailyDownloads, | ||
'last_year_trend' => $lastYearTrend, | ||
'last_year_total' => $this->statistics->resolveTotal($monthlyDownloadsFromOldestToNewest, 12), | ||
'last_2_years_trend' => $this->statistics->resolveTrend($monthlyDownloadsFromOldestToNewest, 24), | ||
]; | ||
|
||
$packagesData[$packageKey] = $packageData; | ||
} | ||
|
||
$packagesData = $this->sortByLastMonthAverage($packagesData); | ||
|
||
$vendorTotalLastMonth = $this->arrayUtils->getArrayKeySum( | ||
$packagesData, | ||
'last_month_average_daily_downloads' | ||
); | ||
$vendorTotalLastYear = $this->arrayUtils->getArrayKeySum($packagesData, 'last_year_total'); | ||
$averageLastYearTrend = $this->arrayUtils->getArrayKeyAverage($packagesData, 'last_year_trend'); | ||
|
||
$vendorData[$vendorName] = [ | ||
'name' => $frameworkName, | ||
'updated_at' => (new DateTime())->format('Y-m-d'), | ||
// totals | ||
'vendor_total_last_month' => $vendorTotalLastMonth, | ||
'vendor_total_last_year' => $vendorTotalLastYear, | ||
'average_last_year_trend' => $averageLastYearTrend, | ||
// packages details | ||
'packages_data' => $packagesData, | ||
]; | ||
} | ||
|
||
return $vendorData; | ||
} | ||
|
||
private function createPackageKey(string $packageName): string | ||
{ | ||
return Strings::replace($packageName, '#(/|-)#', '_'); | ||
} | ||
|
||
/** | ||
* @param mixed[] $packagesData | ||
* @return mixed[] | ||
*/ | ||
private function sortByLastMonthAverage(array $packagesData): array | ||
{ | ||
usort($packagesData, function (array $firstPackage, array $secondPackage) { | ||
return $secondPackage['last_month_average_daily_downloads'] <=> $firstPackage['last_month_average_daily_downloads']; | ||
}); | ||
|
||
return $packagesData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace TomasVotruba\Website\Exception; | ||
|
||
use Exception; | ||
|
||
final class ShouldNotHappenException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace TomasVotruba\Website\Json; | ||
|
||
use Nette\Utils\FileSystem; | ||
use Nette\Utils\Json; | ||
|
||
final class FileToJsonLoader | ||
{ | ||
public function load(string $file): array | ||
{ | ||
return Json::decode(FileSystem::read($file), Json::FORCE_ARRAY); | ||
} | ||
} |
Oops, something went wrong.