68 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
use App\Models\Episode as EpisodeModel;
 | 
						|
use App\Subtitles as AppSubtitles;
 | 
						|
use App\Helpers;
 | 
						|
use Illuminate\Support\Facades\Route;
 | 
						|
use Wikidata\Wikidata;
 | 
						|
use Podlove\Webvtt\Parser;
 | 
						|
use Podlove\Webvtt\ParserException;
 | 
						|
 | 
						|
 | 
						|
use App\Models\Episode;
 | 
						|
 | 
						|
Route::get('/', function () {
 | 
						|
    $episodes = Episode::all();
 | 
						|
    return view('list', ['episodes' => $episodes]);
 | 
						|
});
 | 
						|
 | 
						|
Route::get('/detail/{id}', function(int $id) {
 | 
						|
 | 
						|
    $eps = EpisodeModel::all()->pluck('id');
 | 
						|
    $ep = Episode::find($id);
 | 
						|
    $title = $ep->title;
 | 
						|
    $subtitles = $ep->subtitles;
 | 
						|
    $mediacomposition = json_decode($ep->mediacomposition, 1);
 | 
						|
    $durationSteps = $mediacomposition['chapterList'][0]['duration'] / 1000 / 10;
 | 
						|
    $topics = json_decode($ep->topics, 1);
 | 
						|
 | 
						|
    $subdata = json_decode($ep->subtitle_data, 1);
 | 
						|
    $subdata_senti = json_decode($ep->sentiments_from_sub, 1);
 | 
						|
 | 
						|
    $subdata_senti['data'] = "";
 | 
						|
    $subdata_senti['weights'] = "";
 | 
						|
    $subdata_senti['verteilung'] = ['neutral' => 0, 'negative' => 0, 'positive' => 0];
 | 
						|
 | 
						|
    foreach ($subdata_senti['sentiments'] as $value) {
 | 
						|
        $subdata_senti['data'] .= $value[0].",";
 | 
						|
        $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']++;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    $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']];
 | 
						|
 | 
						|
 | 
						|
    $wordsPerMinute = array_slice($subdata['word_count'], -1)[0] / (($mediacomposition['chapterList'][0]['duration'] / 1000) / 60);
 | 
						|
 | 
						|
    $parser = new Podlove\Webvtt\Parser();
 | 
						|
    $subtitles = $parser->parse($subtitles);
 | 
						|
 | 
						|
    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));
 | 
						|
 | 
						|
});
 |