Weights-Calc


NameWeights-Calc JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
Summary一个简单易用的Python加权计算库,提供多种加权算法
upload_time2025-10-11 13:27:55
maintainerNone
docs_urlNone
authorqiufeng
requires_python<4.0,>=3.8
licenseMIT
keywords weights weight
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Weights-Calc
![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)
一个简单易用的Python加权计算库,提供多种加权算法

## 安装

```bash
pip install weights
```

## 功能

- **加权计算**: 基础的加权平均计算
- **加权随机**: 根据权重进行随机选择
- **时间衰减加权**: 基于时间的指数衰减加权

## 使用方法

### 导入
#### 方法1
```python
import importlib
Weights_Calc = importlib.import_module('Weights-Calc')
```

#### 方法2
```python
Weights_Calc = __import__('Weights-Calc')
```

### 加权计算

```python
values = [10, 20, 30]
weights = [0.2, 0.3, 0.5]
result = Weights_Calc.weighted_calculate(values, weights)
print(result)  # 输出: 23.0
```

### 加权随机

```python
items = ['A', 'B', 'C']
weights = [1, 2, 3]
selected = Weights_Calc.weighted_random(items, weights)
print(selected)  # 输出: ['B'] (概率更高)
```

### 时间衰减加权

```python
values = [100, 200, 300]
dates = [1, 5, 10]  # 时间点
half_life = 7  # 半衰期
result = Weights_Calc.time_decay_weighted(values, dates, half_life)
print(result)
```

## API参考

### weighted_calculate(values, weights)

计算加权结果。

**参数:**
- `values`: 数值列表
- `weights`: 权重列表

**返回:** 加权计算结果

### weighted_random(items, weights)

根据权重随机选择项目。

**参数:**
- `items`: 待选择的项目列表
- `weights`: 对应的权重列表

**返回:** 随机选择的项目列表

### time_decay_weighted(values, dates, half_life_days=7)

基于时间衰减的加权计算。

**参数:**
- `values`: 数值列表
- `dates`: 时间点列表
- `half_life_days`: 半衰期天数(默认7天)

**返回:** 时间衰减加权结果

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "Weights-Calc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "Weights, Weight",
    "author": "qiufeng",
    "author_email": "appleidqiufeng@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/4c/a5/32458f189b380b5d144a6d12b29458390776a5823cf2dc9a8fa1ceb1f358/weights_calc-1.0.1.tar.gz",
    "platform": null,
    "description": "# Weights-Calc\n![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)\n\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u7684Python\u52a0\u6743\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u591a\u79cd\u52a0\u6743\u7b97\u6cd5\n\n## \u5b89\u88c5\n\n```bash\npip install weights\n```\n\n## \u529f\u80fd\n\n- **\u52a0\u6743\u8ba1\u7b97**: \u57fa\u7840\u7684\u52a0\u6743\u5e73\u5747\u8ba1\u7b97\n- **\u52a0\u6743\u968f\u673a**: \u6839\u636e\u6743\u91cd\u8fdb\u884c\u968f\u673a\u9009\u62e9\n- **\u65f6\u95f4\u8870\u51cf\u52a0\u6743**: \u57fa\u4e8e\u65f6\u95f4\u7684\u6307\u6570\u8870\u51cf\u52a0\u6743\n\n## \u4f7f\u7528\u65b9\u6cd5\n\n### \u5bfc\u5165\n#### \u65b9\u6cd51\n```python\nimport importlib\nWeights_Calc = importlib.import_module('Weights-Calc')\n```\n\n#### \u65b9\u6cd52\n```python\nWeights_Calc = __import__('Weights-Calc')\n```\n\n### \u52a0\u6743\u8ba1\u7b97\n\n```python\nvalues = [10, 20, 30]\nweights = [0.2, 0.3, 0.5]\nresult = Weights_Calc.weighted_calculate(values, weights)\nprint(result)  # \u8f93\u51fa: 23.0\n```\n\n### \u52a0\u6743\u968f\u673a\n\n```python\nitems = ['A', 'B', 'C']\nweights = [1, 2, 3]\nselected = Weights_Calc.weighted_random(items, weights)\nprint(selected)  # \u8f93\u51fa: ['B'] (\u6982\u7387\u66f4\u9ad8)\n```\n\n### \u65f6\u95f4\u8870\u51cf\u52a0\u6743\n\n```python\nvalues = [100, 200, 300]\ndates = [1, 5, 10]  # \u65f6\u95f4\u70b9\nhalf_life = 7  # \u534a\u8870\u671f\nresult = Weights_Calc.time_decay_weighted(values, dates, half_life)\nprint(result)\n```\n\n## API\u53c2\u8003\n\n### weighted_calculate(values, weights)\n\n\u8ba1\u7b97\u52a0\u6743\u7ed3\u679c\u3002\n\n**\u53c2\u6570:**\n- `values`: \u6570\u503c\u5217\u8868\n- `weights`: \u6743\u91cd\u5217\u8868\n\n**\u8fd4\u56de:** \u52a0\u6743\u8ba1\u7b97\u7ed3\u679c\n\n### weighted_random(items, weights)\n\n\u6839\u636e\u6743\u91cd\u968f\u673a\u9009\u62e9\u9879\u76ee\u3002\n\n**\u53c2\u6570:**\n- `items`: \u5f85\u9009\u62e9\u7684\u9879\u76ee\u5217\u8868\n- `weights`: \u5bf9\u5e94\u7684\u6743\u91cd\u5217\u8868\n\n**\u8fd4\u56de:** \u968f\u673a\u9009\u62e9\u7684\u9879\u76ee\u5217\u8868\n\n### time_decay_weighted(values, dates, half_life_days=7)\n\n\u57fa\u4e8e\u65f6\u95f4\u8870\u51cf\u7684\u52a0\u6743\u8ba1\u7b97\u3002\n\n**\u53c2\u6570:**\n- `values`: \u6570\u503c\u5217\u8868\n- `dates`: \u65f6\u95f4\u70b9\u5217\u8868\n- `half_life_days`: \u534a\u8870\u671f\u5929\u6570(\u9ed8\u8ba47\u5929)\n\n**\u8fd4\u56de:** \u65f6\u95f4\u8870\u51cf\u52a0\u6743\u7ed3\u679c\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u7684Python\u52a0\u6743\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u591a\u79cd\u52a0\u6743\u7b97\u6cd5",
    "version": "1.0.1",
    "project_urls": null,
    "split_keywords": [
        "weights",
        " weight"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4826de99c9fc74a5ccb7a9ab79c48912cf48372732654ea9025e22ea55ab4831",
                "md5": "35e9868d2d6b91660aa77cb2fd2e5d1c",
                "sha256": "4532431bac6a074a753f1e7fe1d98666f637ba6ec2a4920c98bb9f245927f060"
            },
            "downloads": -1,
            "filename": "weights_calc-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "35e9868d2d6b91660aa77cb2fd2e5d1c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 3251,
            "upload_time": "2025-10-11T13:27:53",
            "upload_time_iso_8601": "2025-10-11T13:27:53.589813Z",
            "url": "https://files.pythonhosted.org/packages/48/26/de99c9fc74a5ccb7a9ab79c48912cf48372732654ea9025e22ea55ab4831/weights_calc-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4ca532458f189b380b5d144a6d12b29458390776a5823cf2dc9a8fa1ceb1f358",
                "md5": "e10201c22516b42974262377f69ec3a4",
                "sha256": "5099ef18b737645f89624b0e18d4c69d34da8b19a364dbeb49a661f105eb99dc"
            },
            "downloads": -1,
            "filename": "weights_calc-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e10201c22516b42974262377f69ec3a4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 2762,
            "upload_time": "2025-10-11T13:27:55",
            "upload_time_iso_8601": "2025-10-11T13:27:55.256839Z",
            "url": "https://files.pythonhosted.org/packages/4c/a5/32458f189b380b5d144a6d12b29458390776a5823cf2dc9a8fa1ceb1f358/weights_calc-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-11 13:27:55",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "weights-calc"
}
        
Elapsed time: 2.94746s