tankertrackers/convert
Composer 安装命令:
composer require tankertrackers/convert
包简介
Convert freely between various types of petroleum-related fluid measurements
README 文档
README
This package is mainly concerned with converting between the following three units of measurement:
- API Gravity
- Barrels per Tonne
- Specific Gravity, AKA "Relative Density"
It was developed to be compatible with PHP 8.0 and greater and is intentionally as light-weight as possible, not requiring any external dependencies or relying on any non-standard PHP libraries.
Please note that future versions may require PHP 8.1 and greater due to the built-in support for Enums that it offers. A new Major release of this library will be released if PHP version dependencies change. At the moment, no significant changes are planned that would require this package to require PHP 8.2 or greater.
Installation
composer require tankertrackers/convert
Usage
If you are doing calculations on an oil grade with a specific gravity (relative density) of 0.983, you can create an Gravity object by calling on the
appropriate static method on the TankerTrackers\Convert class like so: Convert::gravity(0.983). If you wanted to see the corresponding API value for
this Gravity value, you can instead call Convert::gravity(0.983)->toApi().
Converting all three measurements between each other is done in the same way, and all three methods - ->toApi(), ->toBpt(), and ->toGravity() - are
available on all three measurements.
>>> TankerTrackers\Convert::api(34.12)->toBpt(); => TankerTrackers\FluidMeasures\BarrelsPerTonne {#2684 +value: 7.3613796475321, } >>> TankerTrackers\Convert::bpt(6.59)->toGravity() => TankerTrackers\FluidMeasures\Gravity {#2686 +value: 0.95437149864956, } >>> TankerTrackers\Convert::gravity(1.19)->toApi() => TankerTrackers\FluidMeasures\ApiGrade {#2689 +value: 5.897726515101, } // You can also juggle types back and forth as much as you want. >>> TankerTrackers\Convert::api(30)->toGravity()->toBpt()->toApi()->toBpt()->toGravity()->toApi() => TankerTrackers\FluidMeasures\ApiGrade {#2682 +value: 30.0, }
Note that the
$valueattribute is always returned as afloat; even if the value is1.0it is not cast to anint.
You can also access the values directly by calling ->apiValue(), ->bptValue() or ->gravityValue(). This gives the same value as converting to that
measurement type and accessing the $value attribute:
>>> TankerTrackers\Convert::api(31)->toGravity()->value => 0.87076923076923 >>> TankerTrackers\Convert::api(31)->gravityValue() => 0.87076923076923
Future Development
Api Grade Categories
In the future, this package may see some additional bells and whistles when it comes to analyzing the values of the various measurements. For example, the
ApiGrade class might offer a ->getCategory() method so that something like this is possible:
>>> $api = Convert::bpt(7.12)->toApi() >>> $api->getCategory() => "Medium"
Pre-defined Listings
I might also consider adding a number of well known oil grades via Enum classes so that one can reference values directly, something like:
>>> \TankerTrackers\Common\Grade::ATHABASCA_BITUMEN->getApi() => 31.0 >>> \TankerTrackers\Common\Grade::ATHABASCA_BITUMEN->getGravity() => 0.87076923076923
Improvements to Value Checking
At the moment, the system trusts that the values you are entering are valid for that category, so it has no reason to suspect anything is weird if you ask
it to create a BarrelsPerTonne object with the value of -718. Some sanity checks could be implemented that catch scenarios like this and throw
Exceptions when we know something is out of the ordinary.
Copyright / License
This library is released under an MIT License. See the LICENSE file for further details.
tankertrackers/convert 适用场景与选型建议
tankertrackers/convert 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.57k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tankertrackers/convert 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tankertrackers/convert 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-30