public static function getAchievementsDefinitions()
 {
     $dir = Config::$achievementsDefinitionsDirectory;
     $imgFiles = scandir(Config::$imageDirectory . DIRECTORY_SEPARATOR . 'achievement');
     $definitions = array_fill_keys(Media::getConstList(), []);
     foreach (glob($dir . DIRECTORY_SEPARATOR . '*.json') as $file) {
         $definition = TextHelper::loadJson($file);
         $prevAch = null;
         foreach ($definition->achievements as &$ach) {
             foreach ($imgFiles as $f) {
                 if (preg_match('/' . $ach->id . '[^0-9a-zA-Z_-]/', $f)) {
                     $ach->path = $f;
                 }
             }
             $ach->next = null;
         }
         foreach ($definition->achievements as &$ach) {
             if ($prevAch !== null) {
                 $prevAch->next = $ach;
             }
             $ach->prev = $prevAch;
             $prevAch =& $ach;
         }
         unset($ach);
         unset($prevAch);
         $definitions[$definition->media][] = $definition;
     }
     foreach (Media::getConstList() as $key) {
         uasort($definitions[$key], function ($a, $b) {
             return $a->order - $b->order;
         });
     }
     return $definitions;
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-profile';
     $viewContext->meta->title = $viewContext->user->name . '\'s profile — ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s profile.';
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addMiniSections($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $viewContext->yearsOnMal = null;
     if (intval($viewContext->user->join_date)) {
         list($year, $month, $day) = explode('-', $viewContext->user->join_date);
         $time = mktime(0, 0, 0, $month, $day, $year);
         $diff = time() - $time;
         $diff /= 3600 * 24;
         $viewContext->yearsOnMal = $diff / 361.25;
     }
     $viewContext->friends = $viewContext->user->getFriends();
     $viewContext->finished = [];
     $viewContext->meanUserScore = [];
     $viewContext->meanGlobalScore = [];
     $viewContext->franchiseCount = [];
     $viewContext->mismatchedCount = [];
     foreach (Media::getConstList() as $media) {
         $list = $viewContext->user->getMixedUserMedia($media);
         $listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished());
         $viewContext->finished[$media] = count($listFinished);
         unset($listFinished);
         $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
         $viewContext->meanUserScore[$media] = RatingDistribution::fromEntries($listNonPlanned)->getMeanScore();
         $franchises = Model_MixedUserMedia::getFranchises($listNonPlanned);
         $viewContext->franchiseCount[$media] = count(array_filter($franchises, function ($franchise) {
             return count($franchise->ownEntries) > 1;
         }));
         unset($franchises);
         unset($listNonPlanned);
         if ($media == Media::Anime) {
             $viewContext->episodes = array_sum(array_map(function ($mixedMediaEntry) {
                 return $mixedMediaEntry->finished_episodes;
             }, $list));
         } else {
             $viewContext->chapters = array_sum(array_map(function ($mixedMediaEntry) {
                 return $mixedMediaEntry->finished_chapters;
             }, $list));
         }
         $mismatched = $viewContext->user->getMismatchedUserMedia($list);
         $viewContext->mismatchedCount[$media] = count($mismatched);
         unset($mismatched);
         unset($list);
         $globalsCache = file_exists(Config::$globalsCachePath) ? TextHelper::loadJson(Config::$globalsCachePath, true) : [];
         $viewContext->meanGlobalScore[$media] = array_map(function ($v) {
             return RatingDistribution::fromArray($v);
         }, $globalsCache['rating-dist'])[$media]->getMeanScore();
     }
 }
Beispiel #3
0
 public static function doInit()
 {
     $list = TextHelper::loadSimpleList(Config::$bannedUsersListPath);
     foreach ($list as $line) {
         $tmp = strpos($line, "\t") === false ? [$line, self::USER_BAN_TOTAL] : explode("\t", $line);
         list($userName, $banType) = $tmp;
         self::$bannedUsers[strtolower($userName)] = $banType;
     }
     self::$bannedGenres = TextHelper::loadSimpleList(Config::$bannedGenresListPath);
     self::$bannedCreators = TextHelper::loadSimpleList(Config::$bannedCreatorsListPath);
     self::$bannedGenresForRecs = TextHelper::loadSimpleList(Config::$bannedGenresForRecsListPath);
     self::$bannedFranchiseCoupling = TextHelper::loadJson(Config::$bannedFranchiseCouplingListPath, true);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'index-globals';
     $viewContext->meta->title = 'MALgraph - global statistics';
     $viewContext->meta->description = 'Global community statistics on MALgraph, an online tool that extends your MyAnimeList profile.';
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addMiniSections($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $globalsCache = file_exists(Config::$globalsCachePath) ? TextHelper::loadJson(Config::$globalsCachePath, true) : [];
     $viewContext->userCount = $globalsCache['user-count'];
     $viewContext->mediaCount = $globalsCache['media-count'];
     $viewContext->ratingDistribution = array_map(function ($v) {
         return RatingDistribution::fromArray($v);
     }, $globalsCache['rating-dist']);
     $viewContext->queuedUserCount = (new Queue(Config::$userQueuePath))->size();
     $viewContext->queueSizes = TextHelper::loadJson(Config::$userQueueSizesPath, true);
 }
Beispiel #5
0
<?php

require_once __DIR__ . '/../src/core.php';
CronRunner::run(__FILE__, function ($logger) {
    $limit = 2 * 24 * 60 / 5;
    $queueSizes = TextHelper::loadJson(Config::$userQueueSizesPath, true);
    $userQueue = new Queue(Config::$userQueuePath);
    $mediaQueue = new Queue(Config::$mediaQueuePath);
    $key = date('c');
    $queueSizes[$key] = [$userQueue->size(), $mediaQueue->size()];
    ksort($queueSizes, SORT_NATURAL | SORT_FLAG_CASE);
    while (count($queueSizes) > $limit) {
        array_shift($queueSizes);
    }
    TextHelper::putJson(Config::$userQueueSizesPath, $queueSizes);
});