VANA/VANA-php/routes/web.php

68 lines
2.5 KiB
PHP
Raw Normal View History

2024-10-11 08:02:45 +02:00
<?php
2024-10-11 11:20:39 +02:00
use App\Models\Episode as EpisodeModel;
2024-10-11 08:02:45 +02:00
use App\Subtitles as AppSubtitles;
2024-11-01 09:45:32 +01:00
use App\Helpers;
2024-10-11 08:02:45 +02:00
use Illuminate\Support\Facades\Route;
2024-10-18 17:47:20 +02:00
use Wikidata\Wikidata;
2024-10-29 21:27:29 +01:00
use Podlove\Webvtt\Parser;
use Podlove\Webvtt\ParserException;
2024-10-18 17:47:20 +02:00
use App\Models\Episode;
2024-10-11 08:02:45 +02:00
Route::get('/', function () {
2024-10-18 17:47:20 +02:00
$episodes = Episode::all();
return view('list', ['episodes' => $episodes]);
});
Route::get('/detail/{id}', function(int $id) {
2025-01-24 19:56:11 +01:00
$eps = EpisodeModel::all()->pluck('id');
2024-10-18 17:47:20 +02:00
$ep = Episode::find($id);
$title = $ep->title;
$subtitles = $ep->subtitles;
$mediacomposition = json_decode($ep->mediacomposition, 1);
2024-11-01 09:45:32 +01:00
$durationSteps = $mediacomposition['chapterList'][0]['duration'] / 1000 / 10;
2025-01-26 23:26:55 +01:00
$topics = json_decode($ep->topics, 1);
2024-11-30 12:45:02 +01:00
2024-11-23 16:29:44 +01:00
$subdata = json_decode($ep->subtitle_data, 1);
2024-11-30 12:45:02 +01:00
$subdata_senti = json_decode($ep->sentiments_from_sub, 1);
2025-01-17 08:54:42 +01:00
2024-11-30 12:45:02 +01:00
$subdata_senti['data'] = "";
$subdata_senti['weights'] = "";
2025-01-17 08:54:42 +01:00
$subdata_senti['verteilung'] = ['neutral' => 0, 'negative' => 0, 'positive' => 0];
2024-11-30 12:45:02 +01:00
foreach ($subdata_senti['sentiments'] as $value) {
$subdata_senti['data'] .= $value[0].",";
2025-01-17 08:54:42 +01:00
$subdata_senti['weights'] .= (50 * $value[1]).",";
if($value[0] === 0){
$subdata_senti['verteilung']['neutral']++;
}else if($value[0] === 1){
$subdata_senti['verteilung']['positive']++;
}else{
$subdata_senti['verteilung']['negative']++;
}
2024-11-30 12:45:02 +01:00
}
2025-01-17 08:54:42 +01:00
$subdata_senti_all = $subdata_senti['verteilung']['neutral'] + $subdata_senti['verteilung']['negative'] + $subdata_senti['verteilung']['positive'];
$subdata_senti['verteilung_perc'] = ['negative' => (100 / $subdata_senti_all) * $subdata_senti['verteilung']['negative'], 'neutral' => (100 / $subdata_senti_all) * $subdata_senti['verteilung']['neutral'], 'positive' => (100 / $subdata_senti_all) * $subdata_senti['verteilung']['positive']];
2024-11-30 12:45:02 +01:00
$wordsPerMinute = array_slice($subdata['word_count'], -1)[0] / (($mediacomposition['chapterList'][0]['duration'] / 1000) / 60);
2024-11-23 16:29:44 +01:00
2024-10-29 21:27:29 +01:00
$parser = new Podlove\Webvtt\Parser();
$subtitles = $parser->parse($subtitles);
2025-01-24 19:56:11 +01:00
return view('detail', ['eps' => $eps, 'title' => $title, 'subtitles' => $subtitles, 'mediacomposition' => $mediacomposition, 'durationSteps' => $durationSteps, 'dom_color' => $ep->viz_data, 'subdata' => $subdata, 'senti_subdata' => $subdata_senti, 'wpm' => $wordsPerMinute, 'topics' => $topics]);
});
Route::get('/detail/{id}/wpm', function(int $id) {
$ep = Episode::find($id);
return response()->json(json_decode($ep->subtitle_data, 1));
2024-10-11 08:02:45 +02:00
});