public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-favorites'; $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - favorites (' . Media::toString($viewContext->media) . ')'; $viewContext->meta->description = $viewContext->user->name . '’s ' . Media::toString($viewContext->media) . ' favorites on MALgraph, an online tool that extends your MyAnimeList profile.'; $viewContext->meta->keywords = array_merge($viewContext->meta->keywords, ['profile', 'list', 'achievements', 'ratings', 'history', 'favorites', 'suggestions', 'recommendations']); WebMediaHelper::addHighcharts($viewContext); WebMediaHelper::addTablesorter($viewContext); WebMediaHelper::addInfobox($viewContext); WebMediaHelper::addEntries($viewContext); WebMediaHelper::addCustom($viewContext); $list = $viewContext->user->getMixedUserMedia($viewContext->media); $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned()); $favCreators = MediaCreatorDistribution::fromEntries($listNonPlanned); $favGenres = MediaGenreDistribution::fromEntries($listNonPlanned); $favYears = MediaYearDistribution::fromEntries($listNonPlanned); $favDecades = MediaDecadeDistribution::fromEntries($listNonPlanned); $favTypes = MediaTypeDistribution::fromEntries($listNonPlanned); $viewContext->favCreators = $favCreators; $viewContext->favGenres = $favGenres; $viewContext->favYears = $favYears; $viewContext->favDecades = $favDecades; $viewContext->favTypes = $favTypes; $distMeanScore = []; $distTimeSpent = []; foreach ([$favCreators, $favGenres, $favDecades, $favYears] as $dist) { $meanScore = []; $timeSpent = []; foreach ($dist->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY) as $safeKey => $key) { $meanScore[$safeKey] = 0; $timeSpent[$safeKey] = 0; $subEntries = $dist->getGroupEntries($key); $scoreCount = 0; foreach ($subEntries as $entry) { $timeSpent[$safeKey] += $entry->finished_duration; $meanScore[$safeKey] += $entry->score; $scoreCount += $entry->score > 0; } $meanScore[$safeKey] /= max(1, $scoreCount); } $distMeanScore[get_class($dist)] = $meanScore; $distTimeSpent[get_class($dist)] = $timeSpent; } $viewContext->creatorScores = $distMeanScore[get_class($favCreators)]; $viewContext->genreScores = $distMeanScore[get_class($favGenres)]; $viewContext->yearScores = $distMeanScore[get_class($favYears)]; $viewContext->decadeScores = $distMeanScore[get_class($favDecades)]; $viewContext->creatorTimeSpent = $distTimeSpent[get_class($favCreators)]; $viewContext->genreTimeSpent = $distTimeSpent[get_class($favGenres)]; $viewContext->typePercentages = TextHelper::roundPercentages($favTypes->getGroupsSizes()); $viewContext->genreValues = DistributionEvaluator::evaluate($favGenres); $viewContext->creatorValues = DistributionEvaluator::evaluate($favCreators); }
public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-favorites'; $viewContext->meta->title = $viewContext->user->name . ' — Favorites (' . Media::toString($viewContext->media) . ') — ' . Config::$title; $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' favorites.'; WebMediaHelper::addHighcharts($viewContext); WebMediaHelper::addTablesorter($viewContext); WebMediaHelper::addInfobox($viewContext); WebMediaHelper::addEntries($viewContext); WebMediaHelper::addCustom($viewContext); $list = $viewContext->user->getMixedUserMedia($viewContext->media); $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned()); $favCreators = MediaCreatorDistribution::fromEntries($listNonPlanned); $favGenres = MediaGenreDistribution::fromEntries($listNonPlanned); $favYears = MediaYearDistribution::fromEntries($listNonPlanned); $favDecades = MediaDecadeDistribution::fromEntries($listNonPlanned); $favTypes = MediaTypeDistribution::fromEntries($listNonPlanned); $viewContext->favCreators = $favCreators; $viewContext->favGenres = $favGenres; $viewContext->favYears = $favYears; $viewContext->favDecades = $favDecades; $viewContext->favTypes = $favTypes; $distMeanScore = []; $distTimeSpent = []; foreach ([$favCreators, $favGenres, $favDecades, $favYears] as $dist) { $meanScore = []; $timeSpent = []; foreach ($dist->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY) as $safeKey => $key) { $meanScore[$safeKey] = 0; $timeSpent[$safeKey] = 0; $subEntries = $dist->getGroupEntries($key); $scoreCount = 0; foreach ($subEntries as $entry) { $timeSpent[$safeKey] += $entry->finished_duration; $meanScore[$safeKey] += $entry->score; $scoreCount += $entry->score > 0; } $meanScore[$safeKey] /= max(1, $scoreCount); } $distMeanScore[get_class($dist)] = $meanScore; $distTimeSpent[get_class($dist)] = $timeSpent; } $viewContext->creatorScores = $distMeanScore[get_class($favCreators)]; $viewContext->genreScores = $distMeanScore[get_class($favGenres)]; $viewContext->yearScores = $distMeanScore[get_class($favYears)]; $viewContext->decadeScores = $distMeanScore[get_class($favDecades)]; $viewContext->creatorTimeSpent = $distTimeSpent[get_class($favCreators)]; $viewContext->genreTimeSpent = $distTimeSpent[get_class($favGenres)]; $viewContext->typePercentages = TextHelper::roundPercentages($favTypes->getGroupsSizes()); $viewContext->genreValues = DistributionEvaluator::evaluate($favGenres); $viewContext->creatorValues = DistributionEvaluator::evaluate($favCreators); }
public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-favorites'; $viewContext->meta->title = $viewContext->user->name . ' — Favorites (' . Media::toString($viewContext->media) . ') — ' . Config::$title; $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' favorites.'; WebMediaHelper::addHighcharts($viewContext); WebMediaHelper::addTablesorter($viewContext); WebMediaHelper::addInfobox($viewContext); WebMediaHelper::addEntries($viewContext); WebMediaHelper::addCustom($viewContext); $list = $viewContext->user->getMixedUserMedia($viewContext->media); $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned()); $favCreators = MediaCreatorDistribution::fromEntries($listNonPlanned); $favGenres = MediaGenreDistribution::fromEntries($listNonPlanned); $favYears = MediaYearDistribution::fromEntries($listNonPlanned); $favDecades = MediaDecadeDistribution::fromEntries($listNonPlanned); $favTypes = MediaTypeDistribution::fromEntries($listNonPlanned); $viewContext->yearName = ["", MediaType::toString(1, $viewContext->media), '', 'Dropped/On-Hold']; $favWatchedYears = []; foreach ($favTypes->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY | AbstractDistribution::IGNORE_EMPTY_GROUPS) as $type) { if ($type != 1) { $viewContext->yearName[2] .= ucfirst(MediaType::toString($type, $viewContext->media) . '/'); } foreach ($favTypes->getGroupEntries($type) as $entry) { $category = 2; if ($entry->sub_type == 1) { $category = 1; } if ($entry->status == UserListStatus::Dropped || $entry->status == UserListStatus::OnHold) { $category = 3; } $favWatchedYears[$category][MediaYearDistribution::getPublishedYear($entry)][] = $entry; } } $viewContext->yearName[2] = trim($viewContext->yearName[2], '/'); $favWatchedDecades = []; foreach ($favTypes->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY | AbstractDistribution::IGNORE_EMPTY_GROUPS) as $type) { foreach ($favTypes->getGroupEntries($type) as $entry) { $category = 2; if ($entry->sub_type == 1) { $category = 1; } if ($entry->status == UserListStatus::Dropped || $entry->status == UserListStatus::OnHold) { $category = 3; } $favWatchedDecades[$category][MediaDecadeDistribution::getPublishedDecade($entry)][] = $entry; } } $maxYear = max(array_keys($favYears->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY))); $maxDecade = max(array_keys($favDecades->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY))); for ($i = 1; $i < 4; $i++) { if (!isset($favWatchedYears[$i])) { $favWatchedYears[$i][$maxYear] = []; } if (!isset($favWatchedDecades[$i])) { $favWatchedDecades[$i][$maxDecade] = []; } } $viewContext->favCreators = $favCreators; $viewContext->favGenres = $favGenres; $viewContext->favYears = $favYears; $viewContext->favDecades = $favDecades; $viewContext->favTypes = $favTypes; $viewContext->favWatchedYears = $favWatchedYears; $viewContext->favWatchedDecades = $favWatchedDecades; $distMeanScore = []; $distTimeSpent = []; foreach ([$favCreators, $favGenres, $favDecades, $favYears] as $dist) { $meanScore = []; $timeSpent = []; foreach ($dist->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY) as $safeKey => $key) { $meanScore[$safeKey] = 0; $timeSpent[$safeKey] = 0; $subEntries = $dist->getGroupEntries($key); $scoreCount = 0; foreach ($subEntries as $entry) { $timeSpent[$safeKey] += $entry->finished_duration; $meanScore[$safeKey] += $entry->score; $scoreCount += $entry->score > 0; } $meanScore[$safeKey] /= max(1, $scoreCount); } $distMeanScore[get_class($dist)] = $meanScore; $distTimeSpent[get_class($dist)] = $timeSpent; } $viewContext->creatorScores = $distMeanScore[get_class($favCreators)]; $viewContext->genreScores = $distMeanScore[get_class($favGenres)]; $viewContext->yearScores = $distMeanScore[get_class($favYears)]; $viewContext->decadeScores = $distMeanScore[get_class($favDecades)]; $viewContext->creatorTimeSpent = $distTimeSpent[get_class($favCreators)]; $viewContext->genreTimeSpent = $distTimeSpent[get_class($favGenres)]; $viewContext->typePercentages = TextHelper::roundPercentages($favTypes->getGroupsSizes()); $viewContext->genreValues = DistributionEvaluator::evaluate($favGenres); $viewContext->creatorValues = DistributionEvaluator::evaluate($favCreators); }