kabutobashi


Namekabutobashi JSON
Version 0.8.0 PyPI version JSON
download
home_pagehttps://github.com/gsy0911/kabutobashi
SummaryAnalyze stock
upload_time2024-06-01 02:24:43
maintainerNone
docs_urlNone
authoryoshiki
requires_python<3.13,>=3.10
licenseMIT
keywords stock
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # kabutobashi

[![pytest](https://github.com/gsy0911/kabutobashi/workflows/pytest/badge.svg)](https://github.com/gsy0911/kabutobashi/actions?query=workflow%3Apytest)
[![codecov](https://codecov.io/gh/gsy0911/kabutobashi/branch/main/graph/badge.svg)](https://codecov.io/gh/gsy0911/kabutobashi)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)

[![PythonVersion](https://img.shields.io/pypi/pyversions/kabutobashi.svg)](https://pypi.org/project/kabutobashi/)
[![PiPY](https://img.shields.io/pypi/v/kabutobashi.svg)](https://pypi.org/project/kabutobashi/)
[![Documentation Status](https://readthedocs.org/projects/kabutobashi/badge/?version=latest)](https://kabutobashi.readthedocs.io/en/latest/?badge=latest)

## concept

class-relationship.

- `E`: Entity
- `VO`: ValueObject
- `S`: Service
- `A`: Aggregate

```mermaid
graph TD;
  
  subgraph Stock
    stock[Stock:E]
    brand[StockBrand:E]
    record[StockRecord:E]
    indicator[StockIndicator:E]
    
    stock --> brand
    stock --> record
    stock --> indicator
  end

  subgraph Stock-to-Analysis
    aggregate[StockCodeSingleAggregate:A]
    processed[StockDataProcessed:VO]
    estimated[StockDataEstimated:VO]
    
    aggregate --- |Info| stock
    aggregate --- |Method| processed
    aggregate --- |Analysis| estimated
  end

  subgraph Repositories/Storage
    repositories[(Storage/Database)] --- | read/write | stock
  end

  subgraph Pages
    raw_html[RawHtml:VO]
    decoder[Decoder:S]
    decoded_html[DecodedHtml:VO]

    raw_html --> decoder
    decoder --> decoded_html
    decoded_html --> repositories
    decoded_html --> stock
  end

  subgraph Repositories/Web
    web[[Web]] --> | crawl | raw_html
  end
```


## usage

```python
import kabutobashi as kb

df = kb.example()
methods = kb.methods + [kb.basic, kb.pct_change, kb.volatility]
analysis = kb.stock_analysis
agg = kb.StockCodeSingleAggregate.of(entity=df, code="1234").with_processed(methods).with_estimated(stock_analysis=analysis)
print(agg)

# n日前までの営業日の日付リストを取得する関数
target_date = "2020-01-01"
date_list = kb.get_past_n_days(target_date, n=40)

```


# Core Concept

`@block`-decorator and `Flow`-class is important.
`@block` automatically generates input and output functions, allowing you to focus solely on the processing.
`Flow` allows you to focus solely on the process flow and input parameters.

## About `@block`-decorator

simple decorator is like below.

```python
def simple_decorator(func):
    def wrap_func() -> str:
        res = func()
        return f"Hello, {res}"
    return wrap_func


@simple_decorator
def world() -> str:
    return "world"


world()  # => "Hello, world"
```

A `decorator` is something that dynamically generates and adds processes to functions or classes, similar to its name.


First, prepare a function as follows and decorate it with `@block`.

```python
from kabutobashi import block

@block()
class UdfBlock:
    term: int = 10

    def _process(self):
        return {"doubled_term": self.term * 2}
```

The classes above is equivalent to the following class definition.

```python
import pandas as pd
from kabutobashi.domain.entity.blocks import BlockGlue

class UdfBlock:
    series: pd.DataFrame = None
    params: dict = None
    term: int = 10
    block_name: str = "udf_block"

    def _process(self):
        return {"doubled_term": self.term * 2}
    
    def process(self):
        return self._process()

    def factory(self, glue: BlockGlue) -> "UdfBlock":
        # Omitted. In reality, processes are described.
        ...

    def _factory(self, glue: BlockGlue) -> "UdfBlock":
        # Omitted. In reality, processes are described.
        ...

    def glue(self, glue: BlockGlue) -> BlockGlue:
        # Omitted. In reality, processes are described.
        ...

```

In classes decorated with `@block`, it is not recommended to execute the `__init__()` method. Instead, it is recommended to use the `factory()` class-method.

`factory()` method description.
`process()` method description.
`glue()` method description.


Up to this point, the use of the `@block` decorator with classes such as UdfClass has described, but using the Block class on its own is not intended. Please read the following explanation of the `Flow` class for more details.

### Read-Block

- input
  - params
- output
  - series

### Crawl-Block

- input
  - params
- output
  - output.params

### Extract-Block

- input
  - params
- output
  - output.params

### PreProcess-Block

- input
  - series
  - params
- output
  - series

### Process-Block

- input
  - series
  - params
- output
  - output.series

### Parameterize-Block

- input
  - series
  - params
- output
  - output.params

### Reduce-Block

- input
  - series
  - params
- output
  - params

## About `Flow`-class

> Blocks are meant to be combined.

Processes always consist of combinations of multiple simple operations. And the only tedious part is aligning their inputs and outputs.

Therefore, in `Flow`-class, it automatically resolves the sequence of those processes for users, as long as you provide the initial values.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gsy0911/kabutobashi",
    "name": "kabutobashi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.10",
    "maintainer_email": null,
    "keywords": "stock",
    "author": "yoshiki",
    "author_email": "yoshiki0911@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/99/10/6ac690da116edab3ce6dcfd35f0edd86cedaa4d0cc739e1e7382e8173500/kabutobashi-0.8.0.tar.gz",
    "platform": null,
    "description": "# kabutobashi\n\n[![pytest](https://github.com/gsy0911/kabutobashi/workflows/pytest/badge.svg)](https://github.com/gsy0911/kabutobashi/actions?query=workflow%3Apytest)\n[![codecov](https://codecov.io/gh/gsy0911/kabutobashi/branch/main/graph/badge.svg)](https://codecov.io/gh/gsy0911/kabutobashi)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n\n[![PythonVersion](https://img.shields.io/pypi/pyversions/kabutobashi.svg)](https://pypi.org/project/kabutobashi/)\n[![PiPY](https://img.shields.io/pypi/v/kabutobashi.svg)](https://pypi.org/project/kabutobashi/)\n[![Documentation Status](https://readthedocs.org/projects/kabutobashi/badge/?version=latest)](https://kabutobashi.readthedocs.io/en/latest/?badge=latest)\n\n## concept\n\nclass-relationship.\n\n- `E`: Entity\n- `VO`: ValueObject\n- `S`: Service\n- `A`: Aggregate\n\n```mermaid\ngraph TD;\n  \n  subgraph Stock\n    stock[Stock:E]\n    brand[StockBrand:E]\n    record[StockRecord:E]\n    indicator[StockIndicator:E]\n    \n    stock --> brand\n    stock --> record\n    stock --> indicator\n  end\n\n  subgraph Stock-to-Analysis\n    aggregate[StockCodeSingleAggregate:A]\n    processed[StockDataProcessed:VO]\n    estimated[StockDataEstimated:VO]\n    \n    aggregate --- |Info| stock\n    aggregate --- |Method| processed\n    aggregate --- |Analysis| estimated\n  end\n\n  subgraph Repositories/Storage\n    repositories[(Storage/Database)] --- | read/write | stock\n  end\n\n  subgraph Pages\n    raw_html[RawHtml:VO]\n    decoder[Decoder:S]\n    decoded_html[DecodedHtml:VO]\n\n    raw_html --> decoder\n    decoder --> decoded_html\n    decoded_html --> repositories\n    decoded_html --> stock\n  end\n\n  subgraph Repositories/Web\n    web[[Web]] --> | crawl | raw_html\n  end\n```\n\n\n## usage\n\n```python\nimport kabutobashi as kb\n\ndf = kb.example()\nmethods = kb.methods + [kb.basic, kb.pct_change, kb.volatility]\nanalysis = kb.stock_analysis\nagg = kb.StockCodeSingleAggregate.of(entity=df, code=\"1234\").with_processed(methods).with_estimated(stock_analysis=analysis)\nprint(agg)\n\n# n\u65e5\u524d\u307e\u3067\u306e\u55b6\u696d\u65e5\u306e\u65e5\u4ed8\u30ea\u30b9\u30c8\u3092\u53d6\u5f97\u3059\u308b\u95a2\u6570\ntarget_date = \"2020-01-01\"\ndate_list = kb.get_past_n_days(target_date, n=40)\n\n```\n\n\n# Core Concept\n\n`@block`-decorator and `Flow`-class is important.\n`@block` automatically generates input and output functions, allowing you to focus solely on the processing.\n`Flow` allows you to focus solely on the process flow and input parameters.\n\n## About `@block`-decorator\n\nsimple decorator is like below.\n\n```python\ndef simple_decorator(func):\n    def wrap_func() -> str:\n        res = func()\n        return f\"Hello, {res}\"\n    return wrap_func\n\n\n@simple_decorator\ndef world() -> str:\n    return \"world\"\n\n\nworld()  # => \"Hello, world\"\n```\n\nA `decorator` is something that dynamically generates and adds processes to functions or classes, similar to its name.\n\n\nFirst, prepare a function as follows and decorate it with `@block`.\n\n```python\nfrom kabutobashi import block\n\n@block()\nclass UdfBlock:\n    term: int = 10\n\n    def _process(self):\n        return {\"doubled_term\": self.term * 2}\n```\n\nThe classes above is equivalent to the following class definition.\n\n```python\nimport pandas as pd\nfrom kabutobashi.domain.entity.blocks import BlockGlue\n\nclass UdfBlock:\n    series: pd.DataFrame = None\n    params: dict = None\n    term: int = 10\n    block_name: str = \"udf_block\"\n\n    def _process(self):\n        return {\"doubled_term\": self.term * 2}\n    \n    def process(self):\n        return self._process()\n\n    def factory(self, glue: BlockGlue) -> \"UdfBlock\":\n        # Omitted. In reality, processes are described.\n        ...\n\n    def _factory(self, glue: BlockGlue) -> \"UdfBlock\":\n        # Omitted. In reality, processes are described.\n        ...\n\n    def glue(self, glue: BlockGlue) -> BlockGlue:\n        # Omitted. In reality, processes are described.\n        ...\n\n```\n\nIn classes decorated with `@block`, it is not recommended to execute the `__init__()` method. Instead, it is recommended to use the `factory()` class-method.\n\n`factory()` method description.\n`process()` method description.\n`glue()` method description.\n\n\nUp to this point, the use of the `@block` decorator with classes such as UdfClass has described, but using the Block class on its own is not intended. Please read the following explanation of the `Flow` class for more details.\n\n### Read-Block\n\n- input\n  - params\n- output\n  - series\n\n### Crawl-Block\n\n- input\n  - params\n- output\n  - output.params\n\n### Extract-Block\n\n- input\n  - params\n- output\n  - output.params\n\n### PreProcess-Block\n\n- input\n  - series\n  - params\n- output\n  - series\n\n### Process-Block\n\n- input\n  - series\n  - params\n- output\n  - output.series\n\n### Parameterize-Block\n\n- input\n  - series\n  - params\n- output\n  - output.params\n\n### Reduce-Block\n\n- input\n  - series\n  - params\n- output\n  - params\n\n## About `Flow`-class\n\n> Blocks are meant to be combined.\n\nProcesses always consist of combinations of multiple simple operations. And the only tedious part is aligning their inputs and outputs.\n\nTherefore, in `Flow`-class, it automatically resolves the sequence of those processes for users, as long as you provide the initial values.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Analyze stock",
    "version": "0.8.0",
    "project_urls": {
        "Homepage": "https://github.com/gsy0911/kabutobashi",
        "Repository": "https://github.com/gsy0911/kabutobashi"
    },
    "split_keywords": [
        "stock"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0bb5453cf22ccf26819560a4712806aa5fae0922c1161eb75436654080a7aa1",
                "md5": "69c15e691ffcb5f72190d45d26764531",
                "sha256": "fbbac0612773e889d62752a05141bc8d23a4a814159ab8d1509c156047a6671f"
            },
            "downloads": -1,
            "filename": "kabutobashi-0.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "69c15e691ffcb5f72190d45d26764531",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.10",
            "size": 77756,
            "upload_time": "2024-06-01T02:24:42",
            "upload_time_iso_8601": "2024-06-01T02:24:42.248056Z",
            "url": "https://files.pythonhosted.org/packages/b0/bb/5453cf22ccf26819560a4712806aa5fae0922c1161eb75436654080a7aa1/kabutobashi-0.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "99106ac690da116edab3ce6dcfd35f0edd86cedaa4d0cc739e1e7382e8173500",
                "md5": "f51c67bb37d0019972f25a1959577fff",
                "sha256": "b0df4c2949af3e18f1ad1f352c81e7765dfe7b3aa2784d2d862067a22cc7f289"
            },
            "downloads": -1,
            "filename": "kabutobashi-0.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f51c67bb37d0019972f25a1959577fff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.10",
            "size": 46849,
            "upload_time": "2024-06-01T02:24:43",
            "upload_time_iso_8601": "2024-06-01T02:24:43.837441Z",
            "url": "https://files.pythonhosted.org/packages/99/10/6ac690da116edab3ce6dcfd35f0edd86cedaa4d0cc739e1e7382e8173500/kabutobashi-0.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-01 02:24:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gsy0911",
    "github_project": "kabutobashi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "kabutobashi"
}
        
Elapsed time: 0.28586s