public function getURLs($id) { $infix = Media::toString($this->media); if ($infix === null) { throw new BadMediaException(); } return [self::URL_MEDIA => 'https://myanimelist.net/' . $infix . '/' . $id, self::URL_RECS => 'https://myanimelist.net/' . $infix . '/' . $id . '/dummy/userrecs']; }
public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-list'; $viewContext->meta->title = $viewContext->user->name . ' — List (' . Media::toString($viewContext->media) . ') — ' . Config::$title; $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' list.'; WebMediaHelper::addTablesorter($viewContext); WebMediaHelper::addCustom($viewContext); $viewContext->list = $viewContext->user->getMixedUserMedia($viewContext->media); $viewContext->private = $viewContext->user->isUserMediaPrivate($viewContext->media); }
public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-list'; $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - list (' . Media::toString($viewContext->media) . ')'; $viewContext->meta->description = $viewContext->user->name . '’s ' . Media::toString($viewContext->media) . ' list 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::addTablesorter($viewContext); WebMediaHelper::addCustom($viewContext); $viewContext->list = $viewContext->user->getMixedUserMedia($viewContext->media); $viewContext->private = $viewContext->user->isUserMediaPrivate($viewContext->media); }
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-history'; $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - history (' . Media::toString($viewContext->media) . ')'; $viewContext->meta->description = $viewContext->user->name . '’s ' . Media::toString($viewContext->media) . ' activity history 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::addInfobox($viewContext); WebMediaHelper::addEntries($viewContext); WebMediaHelper::addCustom($viewContext); $list = $viewContext->user->getMixedUserMedia($viewContext->media); $listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished()); $monthlyHistoryGroups = []; $unknownEntries = []; $max = 0; foreach ($listFinished as $entry) { $key = $entry->end_date; list($year, $month, $day) = array_map('intval', explode('-', $key)); if (!$year or !$month) { $unknownEntries[] = $entry; continue; } if (!isset($monthlyHistoryGroups[$year])) { $monthlyHistoryGroups[$year] = []; } if (!isset($monthlyHistoryGroups[$year][$month])) { $monthlyHistoryGroups[$year][$month] = []; } $monthlyHistoryGroups[$year][$month][] = $entry; $max = max($max, count($monthlyHistoryGroups[$year][$month])); } krsort($monthlyHistoryGroups, SORT_NUMERIC); foreach ($monthlyHistoryGroups as &$group) { ksort($group, SORT_NUMERIC); } unset($group); $viewContext->monthlyHistoryMax = $max; $viewContext->monthlyHistoryGroups = $monthlyHistoryGroups; $viewContext->monthlyHistoryUnknownEntries = $unknownEntries; $dailyHistory = $viewContext->user->getHistory($viewContext->media); $dailyHistoryGroups = []; foreach ($dailyHistory as $historyEntry) { $key = date('Y-m-d', strtotime($historyEntry->timestamp)); if (!isset($dailyHistoryGroups[$key])) { $dailyHistoryGroups[$key] = []; } $dailyHistoryGroups[$key][] = $historyEntry; } krsort($dailyHistoryGroups); $viewContext->dailyHistoryGroups = $dailyHistoryGroups; $viewContext->isPrivate = $viewContext->user->isUserMediaPrivate($viewContext->media); }
public function process(array $documents, &$context) { Database::delete('usermedia', ['user_id' => $context->user->id]); $context->user->cool = false; foreach (Media::getConstList() as $media) { $key = $media == Media::Anime ? self::URL_ANIMELIST : self::URL_MANGALIST; $isPrivate = strpos($documents[$key]->content, 'This list has been made private by the owner') !== false; $key = $media == Media::Anime ? self::URL_ANIMEINFO : self::URL_MANGAINFO; $doc = $documents[$key]; $dom = self::getDOM($doc); $xpath = new DOMXPath($dom); if ($xpath->query('//myinfo')->length == 0) { throw new BadProcessorDocumentException($doc, 'myinfo block is missing'); } if (strpos($doc->content, '</myanimelist>') === false) { throw new BadProcessorDocumentException($doc, 'list is only partially downloaded'); } $nodes = $xpath->query('//anime | //manga'); $data = []; foreach ($nodes as $root) { $mediaMalId = Strings::makeInteger(self::getNodeValue($xpath, 'series_animedb_id | series_mangadb_id', $root)); $score = Strings::makeInteger(self::getNodeValue($xpath, 'my_score', $root)); $startDate = Strings::makeDate(self::getNodeValue($xpath, 'my_start_date', $root)); $finishDate = Strings::makeDate(self::getNodeValue($xpath, 'my_finish_date', $root)); $status = Strings::makeEnum(self::getNodeValue($xpath, 'my_status', $root), [1 => UserListStatus::Completing, 2 => UserListStatus::Finished, 3 => UserListStatus::OnHold, 4 => UserListStatus::Dropped, 6 => UserListStatus::Planned], UserListStatus::Unknown); $finishedEpisodes = null; $finishedChapters = null; $finishedVolumes = null; switch ($media) { case Media::Anime: $finishedEpisodes = Strings::makeInteger(self::getNodeValue($xpath, 'my_watched_episodes', $root)); break; case Media::Manga: $finishedChapters = Strings::makeInteger(self::getNodeValue($xpath, 'my_read_chapters', $root)); $finishedVolumes = Strings::makeInteger(self::getNodeValue($xpath, 'my_read_volumes', $root)); break; default: throw new BadMediaException(); } $data[] = ['user_id' => $context->user->id, 'mal_id' => $mediaMalId, 'media' => $media, 'score' => $score, 'start_date' => $startDate, 'end_date' => $finishDate, 'finished_episodes' => $finishedEpisodes, 'finished_chapters' => $finishedChapters, 'finished_volumes' => $finishedVolumes, 'status' => $status]; } Database::insert('usermedia', $data); $dist = RatingDistribution::fromEntries(ReflectionHelper::arraysToClasses($data)); $daysSpent = Strings::makeFloat(self::getNodeValue($xpath, '//user_days_spent_watching')); $user =& $context->user; $user->{Media::toString($media) . '_days_spent'} = $daysSpent; $user->{Media::toString($media) . '_private'} = $isPrivate; $user->cool |= ($dist->getRatedCount() >= 50 and $dist->getStandardDeviation() >= 1.5); R::store($user); } }
public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-history'; $viewContext->meta->title = $viewContext->user->name . ' — History (' . Media::toString($viewContext->media) . ') — ' . Config::$title; $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' history.'; WebMediaHelper::addHighcharts($viewContext); WebMediaHelper::addInfobox($viewContext); WebMediaHelper::addEntries($viewContext); WebMediaHelper::addCustom($viewContext); $list = $viewContext->user->getMixedUserMedia($viewContext->media); $listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished()); $monthlyHistoryGroups = []; $unknownEntries = []; $max = 0; foreach ($listFinished as $entry) { $key = $entry->end_date; list($year, $month, $day) = array_map('intval', explode('-', $key)); if (!$year or !$month) { $unknownEntries[] = $entry; continue; } if (!isset($monthlyHistoryGroups[$year])) { $monthlyHistoryGroups[$year] = []; } if (!isset($monthlyHistoryGroups[$year][$month])) { $monthlyHistoryGroups[$year][$month] = []; } $monthlyHistoryGroups[$year][$month][] = $entry; $max = max($max, count($monthlyHistoryGroups[$year][$month])); } krsort($monthlyHistoryGroups, SORT_NUMERIC); foreach ($monthlyHistoryGroups as &$group) { ksort($group, SORT_NUMERIC); } unset($group); $viewContext->monthlyHistoryMax = $max; $viewContext->monthlyHistoryGroups = $monthlyHistoryGroups; $viewContext->monthlyHistoryUnknownEntries = $unknownEntries; $dailyHistory = $viewContext->user->getHistory($viewContext->media); $dailyHistoryGroups = []; foreach ($dailyHistory as $historyEntry) { $key = date('Y-m-d', strtotime($historyEntry->timestamp)); if (!isset($dailyHistoryGroups[$key])) { $dailyHistoryGroups[$key] = []; } $dailyHistoryGroups[$key][] = $historyEntry; } krsort($dailyHistoryGroups); $viewContext->dailyHistoryGroups = $dailyHistoryGroups; $viewContext->isPrivate = $viewContext->user->isUserMediaPrivate($viewContext->media); }
public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-ratings'; $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - rating statistics (' . Media::toString($viewContext->media) . ')'; $viewContext->meta->description = $viewContext->user->name . '’s ' . Media::toString($viewContext->media) . ' rating statistics 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::addFarbtastic($viewContext); WebMediaHelper::addInfobox($viewContext); WebMediaHelper::addEntries($viewContext); WebMediaHelper::addCustom($viewContext); $list = $viewContext->user->getMixedUserMedia($viewContext->media); $list = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned()); $viewContext->ratingDistribution = RatingDistribution::fromEntries($list); $viewContext->ratingTimeDistribution = RatingTimeDistribution::fromEntries($list); $listNoMovies = UserMediaFilter::doFilter($list, UserMediaFilter::nonMovie()); $viewContext->lengthDistribution = MediaLengthDistribution::fromEntries($listNoMovies); $f = explode('-', $viewContext->user->join_date); if (count($f) != 3) { $viewContext->earliestTimeKnown = null; $viewContext->meanTime = null; } else { list($year, $month, $day) = $f; $earliest = mktime(0, 0, 0, $month, $day, $year); $totalTime = 0; foreach ($list as $mixedUserMedia) { $totalTime += $mixedUserMedia->finished_duration; foreach ([$mixedUserMedia->start_date, $mixedUserMedia->end_date] as $k) { $f = explode('-', $k); if (count($f) != 3) { continue; } $year = intval($f[0]); $month = intval($f[1]); $day = intval($f[2]); if (!$year or !$month or !$day) { continue; } $time = mktime(0, 0, 0, $month, $day, $year); if ($time < $earliest) { $earliest = $time; } } } $viewContext->earliestTimeKnown = $earliest; $viewContext->meanTime = $totalTime / max(1, (time() - $earliest) / (24.0 * 3600.0)); } }
public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-ratings'; $viewContext->meta->title = $viewContext->user->name . ' — Ratings (' . Media::toString($viewContext->media) . ') — ' . Config::$title; $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' ratings.'; WebMediaHelper::addHighcharts($viewContext); WebMediaHelper::addFarbtastic($viewContext); WebMediaHelper::addInfobox($viewContext); WebMediaHelper::addEntries($viewContext); WebMediaHelper::addCustom($viewContext); $list = $viewContext->user->getMixedUserMedia($viewContext->media); $list = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned()); $viewContext->ratingDistribution = RatingDistribution::fromEntries($list); $viewContext->ratingTimeDistribution = RatingTimeDistribution::fromEntries($list); $listNoMovies = UserMediaFilter::doFilter($list, UserMediaFilter::nonMovie()); $viewContext->lengthDistribution = MediaLengthDistribution::fromEntries($listNoMovies); $f = explode('-', $viewContext->user->join_date); if (count($f) != 3) { $viewContext->earliestTimeKnown = null; $viewContext->meanTime = null; } else { list($year, $month, $day) = $f; $earliest = mktime(0, 0, 0, $month, $day, $year); $totalTime = 0; foreach ($list as $mixedUserMedia) { $totalTime += $mixedUserMedia->finished_duration; foreach ([$mixedUserMedia->start_date, $mixedUserMedia->end_date] as $k) { $f = explode('-', $k); if (count($f) != 3) { continue; } $year = intval($f[0]); $month = intval($f[1]); $day = intval($f[2]); if (!$year or !$month or !$day) { continue; } $time = mktime(0, 0, 0, $month, $day, $year); if ($time < $earliest) { $earliest = $time; } } } $viewContext->earliestTimeKnown = $earliest; $viewContext->meanTime = $totalTime / max(1, (time() - $earliest) / (24.0 * 3600.0)); } }
/** * This method constructs the URL that is going to be used in layouts, * views, etc. */ public static function url() { $args = func_get_args(); $userName = array_shift($args); $media = array_shift($args); $urlParts = static::getUrlParts(); $bestPart = array_shift($urlParts); while (empty($bestPart) and !empty($urlParts)) { $bestPart = array_shift($urlParts); } $url = '/' . $userName; $url .= '/' . $bestPart; if (!empty(static::getMediaAvailability())) { $url .= ',' . Media::toString($media); } return UrlHelper::absoluteUrl($url); }
public function __construct(array $columns) { foreach ($columns as $key => $value) { $this->{$key} = $value; } if ($this->media == Media::Manga) { $this->duration = 10; } if (isset($this->finished_episodes) and $this->media == Media::Anime) { $this->finished_duration = $this->duration * $this->finished_episodes; } elseif (isset($this->finished_chapters) and $this->media == Media::Manga) { $this->finished_duration = $this->duration * $this->finished_chapters; } if (empty($this->title)) { $this->title = 'Unknown ' . Media::toString($this->media) . ' entry #' . $this->mal_id; } $this->mal_link = 'https://myanimelist.net/' . Media::toString($this->media) . '/' . $this->mal_id; }
<?php require_once __DIR__ . '/../src/core.php'; $mediaProcessors = [Media::Anime => new AnimeProcessor(), Media::Manga => new MangaProcessor()]; $mediaIds = []; foreach (Database::getAllDbNames() as $dbName) { Database::attachDatabase($dbName); $query = 'SELECT um.mal_id, um.media FROM usermedia um' . ' GROUP BY um.media, um.mal_id' . ' HAVING NOT EXISTS(' . 'SELECT null FROM media m' . ' WHERE m.mal_id = um.mal_id AND m.media = um.media' . ') ORDER BY um.mal_id'; $localMediaIds = array_map(function ($row) { $row = ReflectionHelper::arrayToClass($row); return TextHelper::serializeMediaId($row); }, R::getAll($query)); $mediaIds = array_merge($mediaIds, $localMediaIds); } $mediaIds = array_unique($mediaIds); $pad = strlen(count($mediaIds)); $done = 0; $exitCode = 0; foreach ($mediaIds as $mediaId) { try { ++$done; list($media, $malId) = TextHelper::deserializeMediaId($mediaId); printf("(%0{$pad}d/%d) Processing %s #%d" . PHP_EOL, $done, count($mediaIds), Media::toString($media), $malId); $mediaProcessors[$media]->process($malId); } catch (Exception $e) { echo $e->getMessage() . PHP_EOL; $exitCode = 1; } } exit($exitCode);
## Table of contents EOF; printf(PHP_EOL); foreach (Media::getConstList() as $media) { printf('### %s ' . PHP_EOL, ucfirst(Media::toString($media))); foreach ($achList[$media] as $groupData) { printf('* [%s / %s](#%s)' . PHP_EOL, ucfirst(Media::toString($media)), $groupData->{'wiki-title'}, md5($media . $groupData->{'wiki-title'})); } printf(PHP_EOL); } printf(PHP_EOL); foreach (Media::getConstList() as $media) { printf('## %s achievements' . PHP_EOL, ucfirst(Media::toString($media))); foreach ($achList[$media] as $groupData) { printf('<div id="%s"></div>' . PHP_EOL, md5($media . $groupData->{'wiki-title'})); printf('### %s / %s ' . PHP_EOL, ucfirst(Media::toString($media)), $groupData->{'wiki-title'}); if (isset($groupData->{'wiki-desc'})) { printf($groupData->{'wiki-desc'}); } printf(PHP_EOL); printf(PHP_EOL); printf('<table>'); foreach ($groupData->achievements as $achievement) { printf('<tr><td>'); if (isset($achievement->path)) { $url = '/media/img/ach/' . $achievement->path; printf('![%s](%s)' . PHP_EOL, $achievement->id, UrlHelper::absoluteUrl($url)); } printf('</td><td>'); printf('**%s** ' . PHP_EOL, $achievement->title); printf('%s' . PHP_EOL, $achievement->desc);
$mediaIds[] = TextHelper::serializeMediaId($entry); } } } $mediaQueue->enqueueMultiple(array_map(function ($mediaId) { return new QueueItem($mediaId); }, $mediaIds)); $logger->log('ok'); }); $mediaIds = []; foreach (Media::getConstList() as $media) { $entries = Model_Media::getOldest($media, 100); foreach ($entries as $entry) { $mediaAge = time() - strtotime($entry->processed); if ($mediaAge > Config::$mediaQueueMinWait) { $mediaIds[] = TextHelper::serializeMediaId($entry); } } } $mediaQueue->enqueueMultiple(array_map(function ($mediaId) { return new QueueItem($mediaId); }, $mediaIds)); #process media processQueue($mediaQueue, Config::$mediaPerCronRun, Config::$mediaQueueMaxAttempts, $logger, function ($key) use($mediaProcessors, $logger) { list($media, $malId) = TextHelper::deserializeMediaId($key); $logger->log('Processing %s #%d... ', Media::toString($media), $malId); #process the media $mediaProcessors[$media]->process($malId); $logger->log('ok'); }); });
public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-recommendations'; $viewContext->meta->title = $viewContext->user->name . ' — Recommendations (' . Media::toString($viewContext->media) . ') — ' . Config::$title; $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' recommendations.'; WebMediaHelper::addCustom($viewContext); $list = $viewContext->user->getMixedUserMedia($viewContext->media); $recsEngine = new RecommendationsEngine($viewContext->media, $list); $goal = 20; $viewContext->newRecommendations = $recsEngine->getNewRecommendations($goal); $viewContext->franchises = $recsEngine->getMissingTitles(); $viewContext->missingTitlesCount = $recsEngine->getMissingTitlesCount($viewContext->franchises); $viewContext->private = $viewContext->user->isUserMediaPrivate($viewContext->media); }
private static function getFooterImage($settings, $distribution, $media, $mirror = false) { $text = 'mean rated:'; $bboxSmall = self::getBoundingBox($settings->fontSizeNormal, $settings->font, $text); $text = join(' ', array_map(function ($x) { return ucfirst(Media::toString($x)); }, Media::getConstList())); $bboxBig = self::getBoundingBox($settings->fontSizeBig, $settings->font, $text); $w = $settings->barWidth; $h = $bboxBig->height; $img = imagecreatetruecolor($w, $h); imagealphablending($img, false); imagefilledrectangle($img, 0, 0, $w, $h, $settings->colors[self::COLOR_BACKGROUND]); imagealphablending($img, true); $text = ' ' . ucfirst(Media::toString($media)); $bbox = self::getBoundingBox($settings->fontSizeBig, $settings->font, 'Anime'); $x = $bbox->x + ($mirror ? $w - $bbox->width : 0); $y = $bbox->y + ($h - $bboxBig->height >> 1); imagettftext($img, $settings->fontSizeBig, 0, $x, $y, $settings->colors[self::COLOR_TITLE], $settings->font, $text); $lx = $mirror ? $w - $bbox->width : $bbox->width; $text1 = 'mean: '; $text2 = sprintf('%.02f', $distribution->getMeanScore()); $bbox1 = self::getBoundingBox($settings->fontSizeNormal, $settings->font, $text1); $bbox2 = self::getBoundingBox($settings->fontSizeBig, $settings->font, $text2); $x = $bbox1->x + ($mirror ? 0 : $w - $bbox1->width - $bbox2->width); $y = $bbox2->y + ($bbox2->height - $bboxSmall->height >> 1); imagettftext($img, $settings->fontSizeNormal, 0, $x, $y, $settings->colors[self::COLOR_FONT_LIGHT], $settings->font, $text1); $x += $bbox1->width + $bbox2->x; $y = $bboxBig->y + ($h - $bboxBig->height >> 1); imagettftext($img, $settings->fontSizeBig, 0, $x, $y, $settings->colors[self::COLOR_FONT_DARK], $settings->font, $text2); $rx = $mirror ? $bbox1->width + $bbox2->width : $w - $bbox1->width - $bbox2->width; $text1 = 'rated: '; $text2 = $distribution->getRatedCount(); $bbox1 = self::getBoundingBox($settings->fontSizeNormal, $settings->font, $text1); $bbox2 = self::getBoundingBox($settings->fontSizeBig, $settings->font, $text2); $x = $bbox1->x + $lx + ($rx - $lx - $bbox1->width - $bbox2->width >> 1); $y = $bbox2->y + ($bbox2->height - $bboxSmall->height >> 1); imagettftext($img, $settings->fontSizeNormal, 0, $x, $y, $settings->colors[self::COLOR_FONT_LIGHT], $settings->font, $text1); $x += $bbox1->width + $bbox2->x; $y = $bboxBig->y + ($h - $bboxBig->height >> 1); imagettftext($img, $settings->fontSizeBig, 0, $x, $y, $settings->colors[self::COLOR_FONT_DARK], $settings->font, $text2); return $img; }
public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-achievements'; $viewContext->meta->title = $viewContext->user->name . ' — Achievements (' . Media::toString($viewContext->media) . ') — ' . Config::$title; $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' achievements.'; WebMediaHelper::addEntries($viewContext); WebMediaHelper::addCustom($viewContext); $achList = self::getAchievementsDefinitions(); $list = $viewContext->user->getMixedUserMedia($viewContext->media); $listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished()); $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned()); $listDropped = UserMediaFilter::doFilter($list, UserMediaFilter::dropped()); $distribution = RatingDistribution::fromEntries($listNonPlanned); $evaluators = ['given-titles' => function ($groupData) use($listFinished) { $entriesOwned = UserMediaFilter::doFilter($listFinished, UserMediaFilter::givenMedia($groupData->requirement->titles)); return [count($entriesOwned), $entriesOwned]; }, 'genre-titles' => function ($groupData) use($viewContext, $listFinished) { $entriesOwned1 = UserMediaFilter::doFilter($listFinished, UserMediaFilter::genre($groupData->requirement->genre, $listFinished)); $entriesOwned2 = !empty($groupData->requirement->titles) ? UserMediaFilter::doFilter($listFinished, UserMediaFilter::givenMedia($groupData->requirement->titles)) : []; $entriesOwned = array_merge($entriesOwned1, $entriesOwned2); #array unique w/ callback $entriesOwned = array_intersect_key($entriesOwned, array_unique(array_map(function ($e) { return $e->media . $e->mal_id; }, $entriesOwned))); return [count($entriesOwned), $entriesOwned]; }, 'pervert' => function ($groupData) use($viewContext, $listFinished) { $entriesTotalCount = count($listFinished); if ($entriesTotalCount > 0) { $entriesEcchi = UserMediaFilter::doFilter($listFinished, UserMediaFilter::genre(9, $listFinished)); $entriesHentai = UserMediaFilter::doFilter($listFinished, UserMediaFilter::genre(12, $listFinished)); $score = 100 / $entriesTotalCount * (count($entriesEcchi) * 2 + count($entriesHentai) * 4); if ($score > 100) { $score = 100; } $entries = array_merge($entriesEcchi, $entriesHentai); $entries = array_intersect_key($entries, array_unique(array_map(function ($e) { return $e->media . $e->mal_id; }, $entries))); return [$score, $entries]; } return [0, null]; }, 'finished-titles' => function ($groupData) use($listFinished) { return [count($listFinished), null]; }, 'mean-score' => function ($groupData) use($listNonPlanned, $distribution) { if ($distribution->getRatedCount() > 0) { return [$distribution->getMeanScore(), null]; } return [null, null]; }, 'no-drop' => function ($groupData) use($listFinished, $listDropped) { if (count($listDropped) > 0) { return [0, null]; } return [count($listFinished), null]; }, 'old-titles' => function ($groupData) use($listFinished) { $entriesOwned = UserMediaFilter::doFilter($listFinished, function ($row) { $year = substr($row->published_to, 0, 4); return $year != '0000' and intval($year) <= 1980; }); return [count($entriesOwned), $entriesOwned]; }]; $viewContext->rito = ""; $achievements = []; $hiddenCount = 0; foreach ($achList[$viewContext->media] as $group => $groupData) { //get subject and entries basing on requirement type $evaluator = $evaluators[$groupData->requirement->type]; list($subject, $entriesOwned) = $evaluator($groupData); $groupData->achievements = array_reverse($groupData->achievements); if ($subject === null) { continue; } //give first achievement for which the subject fits into its threshold $localAchievements = []; foreach ($groupData->achievements as &$ach) { list($a, $b) = self::getThreshold($ach); $ach->thresholdLeft = $a; $ach->thresholdRight = $b; $ach->earned = (($subject >= $a or $a === null) and ($subject <= $b or $b === null)); if ($ach->next and $ach->next->earned) { $ach->earned = true; $ach->hidden = true; $hiddenCount++; } else { $ach->hidden = false; } if ($ach->earned) { //put additional info if (!empty($entriesOwned)) { DataSorter::sort($entriesOwned, DataSorter::Title); $ach->entries = $entriesOwned; } $ach->progress = 100; $ach->subject = round($subject, 2); if ($ach->next) { $ach->progress = ($subject - $a) * 100.0 / ($ach->next->thresholdLeft - $a); } $localAchievements[] = $ach; } } $achievements = array_merge($achievements, array_reverse($localAchievements)); } $viewContext->achievements = $achievements; $viewContext->private = $viewContext->user->isUserMediaPrivate($viewContext->media); $viewContext->hiddenCount = $hiddenCount; }
public function isUserMediaPrivate($media) { return $this->{Media::toString($media) . '_private'}; }
public static function work(&$controllerContext, &$viewContext) { $viewContext->viewName = 'user-recommendations'; $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - recommendations (' . Media::toString($viewContext->media) . ')'; $viewContext->meta->description = $viewContext->user->name . '’s ' . Media::toString($viewContext->media) . ' recommendations on MALgraph, an online tool that extends your MyAnimeList profile.'; $viewContext->meta->keywords = array_merge($viewContext->meta->keywords, ['profile', 'list', 'achievements', 'ratings', 'history', 'favorites', 'recommendations']); WebMediaHelper::addCustom($viewContext); $list = $viewContext->user->getMixedUserMedia($viewContext->media); $recsEngine = new RecommendationsEngine($viewContext->media, $list); $goal = 10; $viewContext->newRecommendations = $recsEngine->getNewRecommendations($goal); $viewContext->franchises = $recsEngine->getMissingTitles(); $viewContext->private = $viewContext->user->isUserMediaPrivate($viewContext->media); }
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); }