jomisacu/ranking-generator
Composer 安装命令:
composer require jomisacu/ranking-generator
包简介
A tool to rank items by well known criterias
README 文档
README
A simple way to create rankings
What is a ranking?
A ranking is a list that determines which items are higher and lower than others in a given aspect. For example, you can have a set of video camera models and list them based on the quality of the video produced.
It's not just about listing by number. There are general classifications based on multiple aspects, for example, we could have a classification called "the 10 best smartphones of 2022", where the place in the ranking would be given by the combination of multiple factors.
Installation
The most simple way to install this package is with composer:
composer require jomisacu/ranking-generator
How to use this library?
There are two ways to use this library. First, we can convert our objects into "rankable". That is, implements the RankableItemInterface interface. These objects can be used to create an instance of the Ranking class and that's it.
To help in the implementation we have added the RankableItemTrait. Let's see an example:
<?php use Jomisacu\RankingGenerator\Contracts\RankableItemInterface; use Jomisacu\RankingGenerator\RankableItemTrait; final class VideoCamera implements RankableItemInterface { use RankableItemTrait; private int $pixels; // 1090 private string $modelName; // Ej. 'Xiaomi camera xyz'; public function __construct(string $modelName, int $pixels) { $this->modelName = $modelName; $this->pixels = $pixels; } public function getValue() { return $this->pixels; } protected function getUniqueDomainIdentifier(): string { return $this->modelName; } protected function computeRating(): \Jomisacu\RankingGenerator\Rating { $maxPixelsPossible = 4000; return new Rating($this->getValue() * 100 / $maxPixelsPossible); // ensures return a value between 1 and 100 } }
Second, using a ranking generator. In certain situations it is possible to require complex calculations to generate the ranking. For these cases we have provided the RankingGeneratorInterface contract, which provides the build method that receives a collection of arbitrary items and returns a collection of RankableItemInterface objects. In these cases it is totally valid to use the RankingItem generic class instead of modifying our business objects, very useful when you need multiple rankings based on the same items.
<?php class MyRankingGenerator implements \Jomisacu\RankingGenerator\Contracts\RankingGeneratorInterface { public function build(array $items) : array { $final = []; foreach ($items as $item) { $alreadyComputedRating = $this->someComplexLogic($item); $final[] = new \Jomisacu\RankingGenerator\RankingItem( $item['value_used_to_compute_the_rating'], $item['name_to_identify_the_item_in_the_context'], $alreadyComputedRating, ); } return $final; } function someComplexLogic(array $item): \Jomisacu\RankingGenerator\Rating { // complex logic implementation } }
The RankingItem class is very simple. You can generate a rating based on the input, or you can use a pre-computed value.
jomisacu/ranking-generator 适用场景与选型建议
jomisacu/ranking-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jomisacu/ranking-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jomisacu/ranking-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-02