ygo 1.0.10__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ygo might be problematic. Click here for more details.
- ygo/__init__.py +7 -4
- ygo/delay.py +89 -0
- ygo/{ygo.py → pool.py} +41 -215
- ygo/utils.py +137 -0
- ygo-1.1.0.dist-info/METADATA +160 -0
- ygo-1.1.0.dist-info/RECORD +12 -0
- {ygo-1.0.10.dist-info → ygo-1.1.0.dist-info}/WHEEL +1 -1
- {ygo-1.0.10.dist-info → ygo-1.1.0.dist-info}/top_level.txt +0 -1
- ylog/__init__.py +2 -0
- ycat/__init__.py +0 -33
- ycat/client.py +0 -172
- ycat/parse.py +0 -64
- ycat/qdf/__init__.py +0 -530
- ycat/qdf/errors.py +0 -65
- ycat/qdf/expr.py +0 -308
- ycat/qdf/qdf.py +0 -180
- ycat/qdf/udf/__init__.py +0 -14
- ycat/qdf/udf/base_udf.py +0 -145
- ycat/qdf/udf/cs_udf.py +0 -97
- ycat/qdf/udf/d_udf.py +0 -176
- ycat/qdf/udf/ind_udf.py +0 -202
- ycat/qdf/udf/ts_udf.py +0 -175
- ycat/updator.py +0 -101
- ygo-1.0.10.dist-info/METADATA +0 -102
- ygo-1.0.10.dist-info/RECORD +0 -24
- {ygo-1.0.10.dist-info → ygo-1.1.0.dist-info}/licenses/LICENSE +0 -0
ycat/updator.py
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
---------------------------------------------
|
|
4
|
-
Created on 2025/5/23 01:34
|
|
5
|
-
@author: ZhangYundi
|
|
6
|
-
@email: yundi.xxii@outlook.com
|
|
7
|
-
---------------------------------------------
|
|
8
|
-
"""
|
|
9
|
-
import os
|
|
10
|
-
from datetime import datetime, timedelta
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
|
|
13
|
-
import ygo
|
|
14
|
-
import ylog
|
|
15
|
-
from .client import CATDB
|
|
16
|
-
|
|
17
|
-
DATE_FORMAT = "%Y-%m-%d"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class Updator:
|
|
21
|
-
"""
|
|
22
|
-
数据更新器
|
|
23
|
-
路径:{ycat.CATDB}/updator/{name}
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
def __init__(self, name: str, update_time="16:30"):
|
|
27
|
-
"""
|
|
28
|
-
数据更新器
|
|
29
|
-
:param name: 数据更新器名称
|
|
30
|
-
:param update_time: 数据更新时间,默认16:30
|
|
31
|
-
"""
|
|
32
|
-
self.name = name
|
|
33
|
-
self._tb_path = Path(CATDB) / "updator" / name
|
|
34
|
-
os.makedirs(self._tb_path, exist_ok=True)
|
|
35
|
-
self._update_time = update_time
|
|
36
|
-
self.present = datetime.now().today()
|
|
37
|
-
|
|
38
|
-
if self.present.strftime("%H:%M") >= self._update_time:
|
|
39
|
-
self.last_date = self.present.strftime(DATE_FORMAT)
|
|
40
|
-
else:
|
|
41
|
-
self.last_date = (self.present - timedelta(days=1)).strftime(DATE_FORMAT)
|
|
42
|
-
|
|
43
|
-
self._tasks = list()
|
|
44
|
-
self._last_run_file = self._tb_path / f".last_run"
|
|
45
|
-
self.logger = ylog.get_logger("updator")
|
|
46
|
-
|
|
47
|
-
@property
|
|
48
|
-
def last_update_date(self):
|
|
49
|
-
return self._read_last_run_date()
|
|
50
|
-
|
|
51
|
-
def _read_last_run_date(self):
|
|
52
|
-
if self._last_run_file.exists():
|
|
53
|
-
with open(self._last_run_file, "r") as f:
|
|
54
|
-
return f.read().strip()
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
def _write_last_run_date(self, date_str: str):
|
|
58
|
-
with open(self._last_run_file, "w") as f:
|
|
59
|
-
f.write(date_str)
|
|
60
|
-
|
|
61
|
-
def wrap_fn(self, task_name: str, update_fn: callable):
|
|
62
|
-
"""包装函数,添加异常处理"""
|
|
63
|
-
try:
|
|
64
|
-
update_fn()
|
|
65
|
-
return 0
|
|
66
|
-
except Exception as e:
|
|
67
|
-
self.logger.error(ygo.FailTaskError(task_name=task_name, error=e))
|
|
68
|
-
return 1
|
|
69
|
-
|
|
70
|
-
def add_task(self, task_name: str, update_fn: callable):
|
|
71
|
-
"""添加任务"""
|
|
72
|
-
self._tasks.append((task_name, ygo.delay(self.wrap_fn)(task_name=task_name, update_fn=update_fn)))
|
|
73
|
-
|
|
74
|
-
def do(self,
|
|
75
|
-
overwrite: bool = False,
|
|
76
|
-
n_jobs: int = 10,
|
|
77
|
-
backend: str = "threading"):
|
|
78
|
-
"""
|
|
79
|
-
执行任务
|
|
80
|
-
:param overwrite: 是否覆盖现有数据
|
|
81
|
-
:param n_jobs: 并发数
|
|
82
|
-
:param backend: loky/threading/multiprocessing
|
|
83
|
-
:return:
|
|
84
|
-
"""
|
|
85
|
-
if not overwrite:
|
|
86
|
-
local_last_date = self._read_last_run_date()
|
|
87
|
-
if local_last_date is not None:
|
|
88
|
-
if local_last_date >= self.last_date:
|
|
89
|
-
self.logger.info(f"[{self.name}] 已是最新数据,跳过更新")
|
|
90
|
-
return
|
|
91
|
-
self.logger.info(f"[{self.name}] 更新数据")
|
|
92
|
-
failed_num = 0
|
|
93
|
-
with ygo.pool(n_jobs=n_jobs, backend=backend) as go:
|
|
94
|
-
for task_name, task in self._tasks:
|
|
95
|
-
go.submit(task, job_name=task_name)()
|
|
96
|
-
for status in go.do():
|
|
97
|
-
failed_num += status
|
|
98
|
-
if failed_num < 1:
|
|
99
|
-
self._write_last_run_date(self.last_date)
|
|
100
|
-
self.logger.info(f"[{self.name}] 更新成功,最新数据日期:{self.last_date}")
|
|
101
|
-
self.logger.info(f"[{self.name}] 更新完成,失败任务数:{str(failed_num).zfill(2)}/{str(len(self._tasks)).zfill(2)}")
|
ygo-1.0.10.dist-info/METADATA
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: ygo
|
|
3
|
-
Version: 1.0.10
|
|
4
|
-
Project-URL: homepage, https://github.com/link-yundi/ygo
|
|
5
|
-
Project-URL: repository, https://github.com/link-yundi/ygo
|
|
6
|
-
Requires-Python: >=3.9
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
Requires-Dist: clickhouse-df>=0.1.5
|
|
10
|
-
Requires-Dist: clickhouse-driver>=0.2.9
|
|
11
|
-
Requires-Dist: connectorx>=0.3.3
|
|
12
|
-
Requires-Dist: dynaconf>=3.2.11
|
|
13
|
-
Requires-Dist: exchange-calendars>=4.2.8
|
|
14
|
-
Requires-Dist: joblib>=1.4.2
|
|
15
|
-
Requires-Dist: lark>=1.2.2
|
|
16
|
-
Requires-Dist: lightgbm>=4.6.0
|
|
17
|
-
Requires-Dist: loguru>=0.7.3
|
|
18
|
-
Requires-Dist: mlflow>=2.17.2
|
|
19
|
-
Requires-Dist: pandas>=2.0.3
|
|
20
|
-
Requires-Dist: polars>=1.8.2
|
|
21
|
-
Requires-Dist: pyarrow>=17.0.0
|
|
22
|
-
Requires-Dist: pymysql>=1.1.1
|
|
23
|
-
Requires-Dist: sqlalchemy>=2.0.40
|
|
24
|
-
Requires-Dist: sqlparse>=0.5.3
|
|
25
|
-
Requires-Dist: toolz>=1.0.0
|
|
26
|
-
Requires-Dist: torch>=2.5.1
|
|
27
|
-
Requires-Dist: tqdm>=4.67.1
|
|
28
|
-
Dynamic: license-file
|
|
29
|
-
|
|
30
|
-
# ygo
|
|
31
|
-
并发执行(加入进度条)以及延迟调用(基于joblib),以及获取对应函数的相关信息
|
|
32
|
-
|
|
33
|
-
### 安装
|
|
34
|
-
```shell
|
|
35
|
-
pip install -U git+https://github.com/link-yundi/ygo.git
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### 示例
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
├── a
|
|
42
|
-
│ ├── __init__.py
|
|
43
|
-
│ └── b
|
|
44
|
-
│ ├── __init__.py
|
|
45
|
-
│ └── c.py
|
|
46
|
-
└── test.py
|
|
47
|
-
|
|
48
|
-
c.py 中定义了目标函数
|
|
49
|
-
def test_fn(a, b=2):
|
|
50
|
-
return a+b
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
#### 场景1: 并发
|
|
54
|
-
|
|
55
|
-
```python
|
|
56
|
-
import ygo
|
|
57
|
-
import ylog
|
|
58
|
-
from a.b.c import test_fn
|
|
59
|
-
|
|
60
|
-
with ygo.pool(job_name="test parallel", show_progress=True) as go:
|
|
61
|
-
for i in range(10):
|
|
62
|
-
go.submit(test_fn)(a=i, b=2*i)
|
|
63
|
-
for res in go.do():
|
|
64
|
-
ylog.info(res)
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
#### 场景2: 延迟调用
|
|
68
|
-
|
|
69
|
-
```
|
|
70
|
-
>>> fn = delay(test_fn)(a=1, b=2)
|
|
71
|
-
>>> fn()
|
|
72
|
-
3
|
|
73
|
-
>>> # 逐步传递参数
|
|
74
|
-
>>> fn1 = delay(lambda a, b, c: a+b+c)(a=1)
|
|
75
|
-
>>> fn2 = delay(fn1)(b=2)
|
|
76
|
-
>>> fn2(c=3)
|
|
77
|
-
6
|
|
78
|
-
>>> # 参数更改
|
|
79
|
-
>>> fn1 = delay(lambda a, b, c: a+b+c)(a=1, b=2)
|
|
80
|
-
>>> fn2 = delay(fn1)(c=3, b=5)
|
|
81
|
-
>>> fn2()
|
|
82
|
-
9
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
#### 场景3: 获取目标函数信息
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
>>> ygo.fn_info(test_fn)
|
|
89
|
-
=============================================================
|
|
90
|
-
a.b.c.test_fn(a, b=2)
|
|
91
|
-
=============================================================
|
|
92
|
-
def test_fn(a, b=2):
|
|
93
|
-
return a+b
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
#### 场景4: 通过字符串解析函数并执行
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
>>> ygo.fn_from_str("a.b.c.test_fn")(a=1, b=5)
|
|
100
|
-
6
|
|
101
|
-
```
|
|
102
|
-
|
ygo-1.0.10.dist-info/RECORD
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
ycat/__init__.py,sha256=8cVsQXL476hDIU_yDxfoAC9ILC4_Tnp1Y1dDTs6vkXA,529
|
|
2
|
-
ycat/client.py,sha256=Z5lwybzXv6MADbbooDT-rhdr9JMI_t2TDAXt0ghongQ,5451
|
|
3
|
-
ycat/parse.py,sha256=piz_iciF7JFnn8v_qtUEHP6NZ_MWJidsA5gBpLtuZzw,2195
|
|
4
|
-
ycat/updator.py,sha256=dV2vhYVlaoK8eRQggAkNkZuu9zbOYFajicyggMt-r78,3393
|
|
5
|
-
ycat/qdf/__init__.py,sha256=8fIBr0FUAYGc33CYnWILY0Ur2DXdctWjw28S5qDWhD4,7572
|
|
6
|
-
ycat/qdf/errors.py,sha256=lJhhjDRdQOOKUFGlLQ9ELK4AexXBwYQSYus_V-kc5K8,1180
|
|
7
|
-
ycat/qdf/expr.py,sha256=ck_BHMCV29Q8-szci1_v4ud964QI7JoRRcmA0ppupsc,8454
|
|
8
|
-
ycat/qdf/qdf.py,sha256=XcnGyyfuRY1HqaG56kC5tB6psrIXqo9QVQtgH3mhips,7322
|
|
9
|
-
ycat/qdf/udf/__init__.py,sha256=DdrSGaCB__5C1YL0vd_5rjIB3KLrAKn3h3k9k50L0jA,313
|
|
10
|
-
ycat/qdf/udf/base_udf.py,sha256=6VDaCIGNLJxZ7UsoIDWtTH6PzUDj89b8FiwN-TEat2g,3437
|
|
11
|
-
ycat/qdf/udf/cs_udf.py,sha256=HT3EKBwAhOxOFDQnpfwb4YcMTT3-lqFXkdysdn5_FI4,3179
|
|
12
|
-
ycat/qdf/udf/d_udf.py,sha256=L9mkX6yDpQPwXvQTAebDepjEkirCqur1DfV2Fnl8KA0,5352
|
|
13
|
-
ycat/qdf/udf/ind_udf.py,sha256=hDCKfcLFCgIhdC9dQ5GYxLemZaOE6K7kQyAnjUrwePM,6482
|
|
14
|
-
ycat/qdf/udf/ts_udf.py,sha256=uUuZnKMY-V_uInP0nsBMblDpxY3ld3EwvrXTwWMqeig,5410
|
|
15
|
-
ygo/__init__.py,sha256=kQK7CwVCz8NJTj5eS9Xrt_G1kPHvDIbe2sTzHgWITxI,590
|
|
16
|
-
ygo/exceptions.py,sha256=0OYDYt_9KKo8mF2XBG5QkCMr3-ASp69VDSPOEwlIsrI,660
|
|
17
|
-
ygo/ygo.py,sha256=kcXI5vzndNOJqEEEZOeWbn61O47gW72UDiUWN1v9AYc,11290
|
|
18
|
-
ygo-1.0.10.dist-info/licenses/LICENSE,sha256=6AKUWQ1xe-jwPSFv_H6FMQLNNWb7AYqzuEUTwlP2S8M,1067
|
|
19
|
-
ylog/__init__.py,sha256=AoRCQ-o4gWAcJ8svw30wM5UJyccx45WhYIndrrkNv8o,428
|
|
20
|
-
ylog/core.py,sha256=d6QCFRDTvlyxgvS6JphUGOgX5Mgx9qPv9wB3g-4YOJw,9225
|
|
21
|
-
ygo-1.0.10.dist-info/METADATA,sha256=J0M_naeBSfTGAcep-85CtjOz-Tz0z2l8h_VKd7RLIq4,2235
|
|
22
|
-
ygo-1.0.10.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
|
23
|
-
ygo-1.0.10.dist-info/top_level.txt,sha256=jEbfiz5fX4iSzDg8_Npdv5SIC_Kphmb1m3vuyD9ZC1E,14
|
|
24
|
-
ygo-1.0.10.dist-info/RECORD,,
|
|
File without changes
|