symlex/stream-sampler

基于Symlex Core的PHP命令行应用程序示例

v2.0.1 2019-01-04 11:12 UTC

This package is auto-updated.

Last update: 2024-09-09 16:32:26 UTC


README

License: MIT Build Status Documentation Community Chat

此应用程序与PHP 7.1+兼容,并已启用curl扩展。

将此存储库克隆到本地目录并运行composer

git clone https://github.com/symlex/stream-sampler.git
cd stream-sampler
composer update

或者您可以直接运行composer以从最新稳定版创建新项目并获取外部依赖项

composer create-project symlex/stream-sampler my-stream-sampler

Composer将要求输入配置值以为您生成app/config/parameters.yml

位于app/config中的YAML文件根据参数和服务配置应用程序。主要配置文件是app/config/console.yml

流采样器做什么?

它从长度未知且可能非常长的值流中随机返回k个项目的代表性样本。实现依赖于R算法,其复杂度为O(N)。请参阅https://en.wikipedia.org/wiki/Reservoir_sampling

用法

app/console sample [options]

Options:
  -i, --input[=INPUT]   Input source (stdin, random.org, internal) [default: "stdin"]
  -s, --size[=SIZE]     Sample size (1 - 2000) [default: 5]
  -V, --version         Display the application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output

注意:如果您使用random.org或内部随机字符源,输入数据大小将是样本大小的10倍。最大样本大小为2000。

示例

# app/console sample -i internal -s 10
vgB4xtQTF3

# app/console sample -i random.org -s 8
FcojkJX1

# app/console sample < LICENSE
TegcI

# echo 'Pe7emsXm0EHfwAVx' | app/console sample
Xe7es

测试

Stream Sampler附带预配置的PHPUnit环境,可自动执行在src/中找到的测试。

PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

.......                                         7 / 7 (100%)

Time: 431 ms, Memory: 8.00MB

OK (7 tests, 16892 assertions)

另请参阅:https://github.com/lastzero/test-tools(自动初始化数据库固定值和单元测试的依赖注入)

类似工作