本文整理汇总了PHP中TextHelper::roundPercentages方法的典型用法代码示例。如果您正苦于以下问题:PHP TextHelper::roundPercentages方法的具体用法?PHP TextHelper::roundPercentages怎么用?PHP TextHelper::roundPercentages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextHelper
的用法示例。
在下文中一共展示了TextHelper::roundPercentages方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: work
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);
}
示例2: work
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);
}
示例3: getBarsBandsImage
private static function getBarsBandsImage($settings, $distribution, $mirror = false)
{
$margin = 6;
$distributionArray = [];
foreach ($distribution->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY) as $key) {
$distributionArray[$key] = $distribution->getGroupSize($key);
}
$percentages = TextHelper::roundPercentages($distributionArray);
$texts1 = array_map(function ($x) {
return " {$x} ";
}, $distributionArray);
$texts2 = array_map(function ($x) {
return " ({$x}%) ";
}, $percentages);
$bbox1 = [];
$bbox2 = [];
$w = 0;
foreach (array_keys($texts1) as $key) {
$text1 = $texts1[$key];
$text2 = $texts2[$key];
$bbox1[$key] = self::getBoundingBox($settings->fontSizeNormal, $settings->font, $text1);
$bbox2[$key] = self::getBoundingBox($settings->fontSizeSmall, $settings->font, $text2);
$w = max($w, $bbox1[$key]->width + $bbox2[$key]->width);
}
$w += $margin;
$img = imagecreatetruecolor($w, ($settings->barHeight + $settings->barPadding) * count($percentages));
imagealphablending($img, false);
imagefilledrectangle($img, 0, 0, imagesx($img), imagesy($img), $settings->colors[self::COLOR_BACKGROUND]);
imagealphablending($img, true);
$bbox1max = max(array_map(function ($bbox) {
return $bbox->width;
}, $bbox1));
$bbox2max = max(array_map(function ($bbox) {
return $bbox->width;
}, $bbox2));
$i = 0;
foreach (array_keys($texts1) as $key) {
$text1 = $texts1[$key];
$text2 = $texts2[$key];
$x = $mirror ? $bbox2max + $bbox1max - $bbox1[$key]->width : $margin + $bbox1max - $bbox1[$key]->width;
$x += $bbox1[$key]->x;
$yb = $i * ($settings->barHeight + $settings->barPadding);
$y = $yb;
$y += $settings->barHeight + $settings->barPadding - $bbox1[$key]->height >> 1;
$y += $bbox1[$key]->y;
imagettftext($img, $settings->fontSizeNormal, 0, $x, $y, $settings->colors[self::COLOR_FONT_DARK], $settings->font, $text1);
$x = $mirror ? $bbox2max - $bbox2[$key]->width : $margin + $bbox1max;
$x += $bbox2[$key]->x;
$y = $yb;
$y += $settings->barHeight + $settings->barPadding - $bbox2[$key]->height >> 1;
$y += $bbox2[$key]->y;
imagettftext($img, $settings->fontSizeSmall, 0, $x, $y, $settings->colors[self::COLOR_FONT_LIGHT], $settings->font, $text2);
++$i;
}
return $img;
}
示例4: work
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);
}