-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
5 changed files
with
206 additions
and
31 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
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,121 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Enums\ConversionStatus; | ||
use App\Models\Statistic; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Number; | ||
use Inertia\Inertia; | ||
use Throwable; | ||
|
||
class StatController extends Controller | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
return Inertia::render('Stats', [ | ||
'stats' => $this->getStats(), | ||
]); | ||
} | ||
|
||
private function getStats() | ||
{ | ||
$stats = []; | ||
|
||
$allUrls = Statistic::whereNotNull('url')->get(); | ||
$urls = null; | ||
try { | ||
$urls = $allUrls->groupBy(static function ($item) { | ||
return parse_url($item->url, PHP_URL_HOST); | ||
}); | ||
|
||
$synonyms = [ | ||
[ | ||
'youtube.com', | ||
'www.youtube.com', | ||
'youtu.be', | ||
'm.youtube.com', | ||
], | ||
]; | ||
|
||
foreach ($synonyms as $synonym) { | ||
$mainDomain = $synonym[0]; | ||
$urls[$mainDomain] = $urls[$mainDomain] ?? collect(); | ||
foreach ($synonym as $domain) { | ||
if ($domain !== $mainDomain) { | ||
$urls[$mainDomain] = $urls[$mainDomain]->merge($urls[$domain]); | ||
unset($urls[$domain]); | ||
} | ||
} | ||
} | ||
|
||
$urls = $urls->sortByDesc(fn ($item) => $item->count()); | ||
} catch (Throwable $th) { | ||
Log::error('Could not group urls by domain', ['exception' => $th]); | ||
} | ||
|
||
$stats['favorite_url'] = [ | ||
'title' => 'Beliebteste Download-URL', | ||
'value' => $urls ? $urls->keys()->first() : 'Keine URLs vorhanden', | ||
]; | ||
|
||
$stats['currently_converting'] = [ | ||
'title' => 'Aktuell konvertierende Videos', | ||
'value' => Statistic::whereIn('status', [ConversionStatus::PROCESSING, ConversionStatus::PREPARING, ConversionStatus::DOWNLOADING])->where('created_at', '>', now()->subHour())->count(), | ||
]; | ||
|
||
$stats['uploaded_size'] = [ | ||
'title' => 'Traffic für hochgeladene Videos', | ||
'value' => Number::fileSize(Statistic::sum('size'), 2), | ||
]; | ||
|
||
$stats['extensions'] = [ | ||
'title' => 'Am häufigsten hochgeladene Dateiendung', | ||
'value' => Statistic::select('extension') | ||
->groupBy('extension') | ||
->orderByRaw('COUNT(extension) DESC') | ||
->first()->extension, | ||
]; | ||
|
||
$stats['finished'] = [ | ||
'title' => 'Erfolgreiche Konvertierungen', | ||
'value' => Statistic::where('status', ConversionStatus::FINISHED)->count(), | ||
]; | ||
|
||
$stats['average_conversion_time'] = [ | ||
'title' => 'Durchschnittliche Konvertierungszeit', | ||
'value' => Number::format(Statistic::where('status', ConversionStatus::FINISHED)->avg('conversion_time'), 2, locale: 'de-DE') . ' Sekunden', | ||
]; | ||
|
||
$stats['favorite_time_to_convert'] = [ | ||
'title' => 'Beliebteste Konvertierungszeit', | ||
'value' => Statistic::selectRaw('HOUR(created_at) as hour, COUNT(id) as count') | ||
->groupBy('hour') | ||
->orderByRaw('COUNT(id) DESC') | ||
->first()->hour . ' Uhr', | ||
]; | ||
|
||
$stats['added_watermarks'] = [ | ||
'title' => 'Wasserzeichen hinzugefügt', | ||
'value' => Statistic::where('watermark', true)->where('status', ConversionStatus::FINISHED)->count() . ' Wasserzeichen', | ||
]; | ||
|
||
$stats['auto_crop'] = [ | ||
'title' => 'Automatisch zugeschnittene Videos', | ||
'value' => Statistic::where('auto_crop', true)->where('status', ConversionStatus::FINISHED)->count() . ' Videos', | ||
]; | ||
|
||
$stats['trimmed'] = [ | ||
'title' => 'Videos zugeschnitten', | ||
'value' => Statistic::whereNotNull('trim_start')->orWhereNotNull('trim_end')->count() . ' Videos', | ||
]; | ||
|
||
$stats['removed_audio'] = [ | ||
'title' => 'Audio entfernt', | ||
'value' => Statistic::where('audio', false)->count() . ' mal', | ||
]; | ||
|
||
return $stats; | ||
} | ||
} |
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,56 @@ | ||
<script setup> | ||
import { Head } from '@inertiajs/vue3'; | ||
import { | ||
Card, | ||
CardContent, | ||
CardHeader, | ||
CardTitle, | ||
} from '@/components/ui/card/index.js'; | ||
defineProps({ | ||
stats: { | ||
type: Array, | ||
required: true, | ||
}, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<Head> | ||
<title>Pr0verter - Statistik</title> | ||
<meta | ||
name="description" | ||
content="Der pr0verter ist ein Converter für das pr0gramm. Hier kannst Videos konvertieren." /> | ||
</Head> | ||
<div class="grid w-full items-start gap-6"> | ||
<h1 class="scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl"> | ||
Statistik | ||
</h1> | ||
|
||
<div v-if="stats" class="my-8 grid grid-cols-1 gap-4 sm:grid-cols-2"> | ||
<Card v-for="(stat, idx) in stats" :key="idx"> | ||
<CardHeader | ||
class="flex flex-row items-center justify-between space-y-0 pb-2"> | ||
<CardTitle class="text-sm font-medium"> | ||
{{ stat.title }} | ||
</CardTitle> | ||
</CardHeader> | ||
<CardContent> | ||
<div class="text-2xl font-bold"> | ||
{{ stat.value }} | ||
</div> | ||
</CardContent> | ||
</Card> | ||
</div> | ||
<div class="text-muted-foreground"> | ||
<p>Folgende Domains fungieren als Synonyme für youtube.com:</p> | ||
<ul> | ||
<li>www.youtube.com</li> | ||
<li>youtu.be</li> | ||
<li>m.youtube.com</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped></style> |
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