From d85f3cc36907668ccf231fd20db8b66296ad59aa Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 28 Jan 2024 16:20:52 +0100 Subject: [PATCH 1/3] Update title --- _pages/dashboard.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pages/dashboard.blade.php b/_pages/dashboard.blade.php index fdf628b5..0e4dba38 100644 --- a/_pages/dashboard.blade.php +++ b/_pages/dashboard.blade.php @@ -2,7 +2,7 @@ @section('content')

- Statistics + HydePHP Statistics

Data compiled {{ Carbon\Carbon::now() }}. From e9560247ef02f978a26159157c6211e314e520e4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 28 Jan 2024 17:55:51 +0100 Subject: [PATCH 2/3] Update statistics controller to use our API --- app/StatisticsController.php | 75 +++---------------- .../views/components/statistics.blade.php | 10 +-- 2 files changed, 14 insertions(+), 71 deletions(-) diff --git a/app/StatisticsController.php b/app/StatisticsController.php index d0fe0526..1aa1372c 100644 --- a/app/StatisticsController.php +++ b/app/StatisticsController.php @@ -10,92 +10,35 @@ */ class StatisticsController { - public object $framework; - - public object $views; - - public object $linesOfCode; + /** @var object{packagistInstalls: string, githubViews: string, githubClones: string, githubViewsWeekly: string, githubClonesWeekly: string} */ + public object $stats; + public int $linesOfCode; public function __construct() { - $this->framework = $this->getFrameworkStats(); - unset($this->framework->versions); - - $this->views = $this->getViewStats(); + $this->stats = $this->getStats(); $this->linesOfCode = $this->getLinesOfCode(); } - protected function getFrameworkStats() + protected function getStats() { - // Mock - // $frameworkStats = '{"downloads":{"total":2497,"monthly":2290,"daily":76},"versions":["dev-master","v0.23.2-beta","v0.23.1-beta","v0.23.0-beta","v0.22.0-beta","v0.21.6-beta","v0.21.5-beta","v0.21.4-beta","v0.21.3-beta","v0.21.2-beta","v0.21.1-beta","v0.21.0-beta","v0.20.0-beta","v0.19.0-beta","v0.18.0-beta","v0.17.0-beta","v0.16.1-beta","v0.16.0-beta","v0.15.0-beta","v0.14.0-beta","v0.13.0-beta","v0.12.0-beta","v0.11.0-beta","v0.10.0-beta","v0.9.0-beta","v0.8.1-beta","v0.8.0-beta","v0.7.5-alpha","v0.7.4-alpha","v0.7.3-alpha","v0.7.2-alpha","v0.7.1-alpha","v0.7.0-alpha","v0.6.2-alpha","v0.6.1-alpha","v0.6.0-alpha","v0.5.3-alpha","v0.5.2-alpha","v0.5.1-alpha","v0.5.0-alpha","v0.4.3-alpha","v0.4.2-alpha","v0.4.1-alpha","v0.4.0-alpha","v0.3.1-alpha","v0.3.0-alpha","dev-update-changelog","dev-refactor-documentation-sidebar-internals","dev-analysis-KZEPOj","dev-analysis-BMOd0g","dev-analysis-OMWvDR","dev-refactor-docs-layout","dev-refactor-script-interactions","dev-analysis-vQEZPr","dev-analysis-L3GZVm","dev-280-feature-hide-the-hyde-install-command-once-it-has-been-run"],"average":"daily","date":"2022-03-21"}'; - // $frameworkStats = json_decode($frameworkStats); - - // return $frameworkStats; - $response = Http::withHeaders([ 'Accept' => 'application/json', 'User-Agent' => 'HydeDocsCI/dev-master (Twitter contact: @CodeWithCaen)', - ])->get('https://packagist.org/packages/hyde/framework/stats.json'); + ])->get('https://analytics.hydephp.com/api/stats'); return $response->object(); } - protected function getViewStats() + protected function getLinesOfCode() { $response = Http::withHeaders([ 'Accept' => 'application/json', 'User-Agent' => 'HydeDocsCI/dev-master (Twitter contact: @CodeWithCaen)', - ])->get('https://git.desilva.se/GitHubAnalyticsExplorer/table.json'); - - $collection = $response->collect(); - - $views = new Collection(); - - foreach ($collection as $item) { - if ($item['type'] === 'traffic/views') { - $views->push((object) $item); - } - } - - $views = $views->sortBy('bucket'); - - $oldest = $views->first(); - $newest = $views->last(); - - // Calculate the number of weeks between the oldest and newest view (the date is string) - $weeks = ((strtotime($newest->bucket) - strtotime($oldest->bucket)) / (60 * 60 * 24 * 7)); - - $object = new \stdClass(); - $object->oldest = $oldest; - $object->newest = $newest; - $object->weeks = $weeks; - $object->views = $views; - $object->weekly = (int) ($views->sum('total') / $weeks); - - return $object; - } - - protected function getLinesOfCode() - { - try { - $response = Http::withHeaders([ - 'Accept' => 'application/json', - 'User-Agent' => 'HydeDocsCI/dev-master (Twitter contact: @CodeWithCaen)', - ])->get('https://tokei.ekzhang.com/b1/github/hydephp/develop'); - } catch (\Throwable $th) { - // Return last known count - $object = new \stdClass(); - $object->total = 87513; - return $object; - } - - $object = new \stdClass(); - - $object->total = $response->object()->lines; + ])->get('https://analytics.hydephp.com/api/stats/lines_of_code'); - return $object; + return $response->json('data.total'); } } diff --git a/resources/views/components/statistics.blade.php b/resources/views/components/statistics.blade.php index de1a677b..af48b71e 100644 --- a/resources/views/components/statistics.blade.php +++ b/resources/views/components/statistics.blade.php @@ -9,7 +9,7 @@

Total Downloads

- {{ ($statistics->framework->downloads->total) }} + {{ number_format($statistics->stats->packagistInstalls) }}
@@ -18,18 +18,18 @@

Weekly GitHub Views

- {{ $statistics->views->weekly }} + {{ number_format($statistics->stats->githubViewsWeekly) }} - +

Lines of Code

- {{ ($statistics->linesOfCode->total) }} + {{ number_format($statistics->linesOfCode) }} - +
From bbf2baa58090710becf405c13f57fd7b947403db Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 28 Jan 2024 18:17:44 +0100 Subject: [PATCH 3/3] Fix data access --- resources/views/components/statistics.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/components/statistics.blade.php b/resources/views/components/statistics.blade.php index af48b71e..c11aedfb 100644 --- a/resources/views/components/statistics.blade.php +++ b/resources/views/components/statistics.blade.php @@ -9,7 +9,7 @@

Total Downloads

- {{ number_format($statistics->stats->packagistInstalls) }} + {{ number_format($statistics->stats->data->packagistInstalls) }}
@@ -18,7 +18,7 @@

Weekly GitHub Views

- {{ number_format($statistics->stats->githubViewsWeekly) }} + {{ number_format($statistics->stats->data->githubViewsWeekly) }}