dataquant 1.1.6__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.
@@ -0,0 +1,125 @@
1
+ # -*- coding: utf-8 -*-
2
+ import time
3
+ import inspect
4
+ from functools import wraps
5
+
6
+
7
+ def retry(count, exp_name, time_delta=1.0):
8
+ def decorate(func):
9
+ @wraps(func)
10
+ def wrap(*args, **kwargs):
11
+ assert count
12
+ exec_count = 1
13
+ while exec_count < count:
14
+ try:
15
+ return func(*args, **kwargs)
16
+ except exp_name as ex:
17
+ exec_count += 1
18
+ if exec_count == count:
19
+ raise ex
20
+ print("Retry because Multi-Process")
21
+ if time_delta:
22
+ time.sleep(time_delta)
23
+
24
+ return wrap
25
+
26
+ return decorate
27
+
28
+
29
+ functions = []
30
+
31
+
32
+ def lru_cache(*args, **kwargs):
33
+ from functools import lru_cache as _lru_cache
34
+
35
+ def decorator(func):
36
+ func = _lru_cache(*args, **kwargs)(func)
37
+ functions.append(func)
38
+ return func
39
+
40
+ return decorator
41
+
42
+
43
+ def args_check(*checks):
44
+ def decorator(func):
45
+ @wraps(func)
46
+ def wrap(*args, **kwargs):
47
+ call_args = None
48
+ for check in checks:
49
+ if call_args is None:
50
+ call_args = inspect.getcallargs(get_original_func(func), *args, **kwargs)
51
+
52
+ check.check(func.__name__, call_args.get(check.arg_name, check.arg_name), kwargs)
53
+
54
+ return func(*args, **kwargs)
55
+ return wrap
56
+
57
+ return decorator
58
+
59
+
60
+ def get_original_func(func):
61
+ func_wrapped = getattr(func, "__wrapped__", None)
62
+ while func_wrapped:
63
+ func = func_wrapped
64
+ func_wrapped = getattr(func, "__wrapped__", None)
65
+
66
+ return func
67
+
68
+
69
+ class ArgumentChecker(object):
70
+
71
+ def __init__(self, args_name):
72
+ self._args_name = args_name
73
+ self._functions = []
74
+ self._required_func = None
75
+
76
+ def is_instance(self, _types):
77
+ from dataquant.utils.error import InvalidArgument
78
+
79
+ def warp(func, value):
80
+ if not isinstance(value, _types):
81
+ raise InvalidArgument("函数[{}] 参数类型异常,参数[{}]有效类型为[{}],实参类型为[{}]".format(
82
+ func, self._args_name, _types, type(value)))
83
+
84
+ self._functions.append(warp)
85
+ return self
86
+
87
+ def is_required(self):
88
+ from dataquant.utils.error import InvalidArgument
89
+
90
+ assert self.arg_name
91
+ if not isinstance(self.arg_name, (tuple, list)):
92
+ raise InvalidArgument("必填项装饰器,参数的有效类型为元组或数组,实参类型为[{}]".format(type(self._args_name)))
93
+
94
+ def warp(func, value):
95
+ checkd = False
96
+ for name in self.arg_name:
97
+ if name in value.keys() and value[name]:
98
+ checkd = True
99
+ break
100
+
101
+ if not checkd:
102
+ raise InvalidArgument("函数[{}] 必填项参数异常,参数[{}]至少填其中一个,实参传入为{}".format(
103
+ func, self._args_name, list(value.keys())))
104
+
105
+ self._required_func = warp
106
+ return self
107
+
108
+ def check(self, func, value, kwargs):
109
+ if self._required_func:
110
+ self._required_func(func, kwargs)
111
+ return
112
+
113
+ for check_func in self._functions:
114
+ check_func(func, value)
115
+
116
+ @property
117
+ def arg_name(self):
118
+ return self._args_name
119
+
120
+
121
+ def check(arg_name):
122
+ return ArgumentChecker(arg_name)
123
+
124
+
125
+
@@ -0,0 +1,159 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class ConnectionException(Exception):
4
+ pass
5
+
6
+
7
+ class ConnectionTimeOut(Exception):
8
+ pass
9
+
10
+
11
+ class RequestTimeOut(Exception):
12
+ pass
13
+
14
+
15
+ class RequestException(Exception):
16
+ pass
17
+
18
+
19
+ class ServerException(Exception):
20
+ pass
21
+
22
+
23
+ class GatewayException(Exception):
24
+ pass
25
+
26
+
27
+ class ArgumentsVaildError(Exception):
28
+ pass
29
+
30
+
31
+ class InvalidArgument(Exception):
32
+ pass
33
+
34
+
35
+ class MultiProcessException(Exception):
36
+ pass
37
+
38
+ class MaxTryExceed(Exception):
39
+ pass
40
+
41
+
42
+ class RunTimeError(Exception):
43
+ pass
44
+
45
+ ERROR_CHANNEL_BASE = 9100
46
+ GATEWAY_ERROR_DICT = {
47
+ ERROR_CHANNEL_BASE + 1: "no timestamp field",
48
+ ERROR_CHANNEL_BASE + 2: "error timestamp format",
49
+ ERROR_CHANNEL_BASE + 3: "error timestamp",
50
+ ERROR_CHANNEL_BASE + 4: "no signature head",
51
+ ERROR_CHANNEL_BASE + 5: "unkown HTTP method",
52
+ ERROR_CHANNEL_BASE + 6: "resty_sm3:new() failed",
53
+ ERROR_CHANNEL_BASE + 7: "sm3:update() failed",
54
+ ERROR_CHANNEL_BASE + 8: "error packet",
55
+ ERROR_CHANNEL_BASE + 9: "no appkey head",
56
+ ERROR_CHANNEL_BASE + 10: "redis not config, please check...",
57
+ ERROR_CHANNEL_BASE + 11: "no getinfo_byself.lua or no get_secret_byself function in getinfo_byself.lua",
58
+ ERROR_CHANNEL_BASE + 12: "no app_secret in redis or hget from redis timeout",
59
+ ERROR_CHANNEL_BASE + 13: "authentication failure,no client_key in clients",
60
+ ERROR_CHANNEL_BASE + 14: "authentication failure,ip not in whitelist",
61
+ ERROR_CHANNEL_BASE + 15: "authentication failure,ip in blacklist",
62
+ ERROR_CHANNEL_BASE + 16: "authentication failure,app_auth_type is nil",
63
+ ERROR_CHANNEL_BASE + 17: "no client_id in body",
64
+ ERROR_CHANNEL_BASE + 18: "no client_id in args",
65
+ ERROR_CHANNEL_BASE + 19: "error client id",
66
+ ERROR_CHANNEL_BASE + 20: "no client_id head",
67
+ ERROR_CHANNEL_BASE + 21: "error packet,no data_value with get request",
68
+ ERROR_CHANNEL_BASE + 22: "must json type",
69
+ ERROR_CHANNEL_BASE + 23: "error packet,not data_value in post_args",
70
+ ERROR_CHANNEL_BASE + 24: "error packet,not data_value in header or args"
71
+ }
72
+
73
+ SERVER_ERROR_DICT = {
74
+ 1002005: "该API不存在",
75
+ 1002007: "该API名称已存在!",
76
+ 1002008: "该API名称[{0}]已归档!",
77
+ 1002013: "json转换失败!",
78
+ 1002016: "该path已归档!",
79
+ 1002018: "微服务API[{0}]不符合发布规则",
80
+ 1002024: "该API已归档",
81
+ 1002025: "版本[{0}]正在审核,不能归档",
82
+ 1004001: "api版本信息已存在,不可删除!",
83
+ 1004002: "api版本信息已上线,不可归档!",
84
+ 1005001: "获取RestTemplate对象失败!",
85
+ 1005002: "请求URL不能为空!",
86
+ 1005003: "请求URL[{0}]不是HTTP协议!",
87
+ 1005004: "请求信息不能为空!",
88
+ 1005005: "请求头部信息不能为空!",
89
+ 1005006: "请求参数信息不能为空!",
90
+ 1005007: "请求头部信息缺少httpMethod配置!",
91
+ 1005009: "请求头部信息缺少contentType配置!",
92
+ 1005010: "远程访问地址[{0}],服务返回报文[{1}],发生异常!",
93
+ 1005011: "远程访问地址[{0}],HTTP状态[{1}],HTTP状态说明[{2}],发生异常!",
94
+ 1005012: "远程访问地址[{0}],发生异常!",
95
+ 1005013: "转换json结构失败!",
96
+ 1005016: "服务治理URL,获得失败!",
97
+ 100000: "发生异常",
98
+ 100011: "参数[{0}]不能为空",
99
+ 100027: "请求格式错误",
100
+ 100034: "参数[{0}]非法",
101
+ 100038: "只能删除空分组",
102
+ 100039: "上级分组不能是当前分组或当前分组的下级分组",
103
+ 100040: "分组[{0}]的上级分组出现循环引用",
104
+ 100041: "{0}[{1}]不存在",
105
+ 100042: "{0}[{1}]已存在",
106
+ 100043: "{0}JSON反序列化异常",
107
+ 100044: "{0}JSON序列化异常",
108
+ 101001: "未知的渠道过期状态[{0}]",
109
+ 101002: "未知的渠道状态[{0}]",
110
+ 102001: "审核记录的状态应为{0}目前是{1}",
111
+ 102002: "您只能撤回自己的申请",
112
+ 103001: "您已评论,每人只能评论一次",
113
+ 103002: "只能删除自己的评论",
114
+ 104001: "该API已上线,不能发起上线申请",
115
+ 104002: "该API已经在审核中,不能重复发起上线申请",
116
+ 104003: "当前已存在草稿版本,不能重复创建草稿版本",
117
+ 104004: "只能保存草稿版本",
118
+ 104005: "不能保存待审核的API",
119
+ 104006: "该API的审核状态不为待审核",
120
+ 104007: "审核记录的类型不为API上线申请",
121
+ 104008: "API[{0}]的[{1}]版本{2}待审核,不能删除",
122
+ 104009: "API[{0}]的[{1}]版本已上线,不能删除",
123
+ 104010: "API[{0}]的[{1}]版本{2}待审核,不能归档",
124
+ 104011: "API[{0}]的[{1}]版本已上线,不能归档",
125
+ 105001: "不能删除基分组",
126
+ 105002: "API分组[{}]不在系统ID关联的基分组下",
127
+ 200001: "未知的{0}",
128
+ 200002: "解析{0}失败",
129
+ 200003: "数据库连接失败:{0}",
130
+ 200004: "获取方言失败:{0}",
131
+ 200011: "参数校验失败:{0}",
132
+ 200012: "参数{0}校验失败:{1}",
133
+ 200013: "参数{0}转换失败:{1}",
134
+ 200014: "参数{0}不能为空",
135
+ 200015: "请求解析失败:{0}",
136
+ 200021: "生成SQL失败:{0}",
137
+ 200022: "自动分页失败,{0}",
138
+ 200023: "查询失败:{0}",
139
+ 200031: "CSV写入失败:{0}",
140
+ 200032: "FTP异常:{0}",
141
+ 200033: "DBF文件写入失败:{0}",
142
+ 200034: "SFTP异常:{0}",
143
+ 200041: "非法的URL:{0}",
144
+ 200042: "将请求参数序列化为JSON失败",
145
+ 200043: "HTTP请求失败:{0}",
146
+ 200044: "解析JSON响应失败",
147
+ 200050: "推库初始化异常:{0}",
148
+ 200051: "推库执行失败:{0}",
149
+ 804001: "ES获取日志失败",
150
+ 804002: "检查索引[{0}]是否存在发生异常",
151
+ 804003: "创建索引[{0}]的索引结构发生异常",
152
+ 804004: "删除索引[{0}]发生异常",
153
+ 804005: "新增索引[{0}]文档数据[{1}]发生异常",
154
+ 804006: "批量新增索引[{0}]文档数据发生异常",
155
+ 804007: "更新索引[{0}]文档数据[{1}]发生异常",
156
+ 804008: "删除索引[{0}]文档数据[{1}]发生异常",
157
+ 804009: "从索引[{0}]将数据迁移至索引[{1}]发生异常"
158
+ }
159
+
@@ -0,0 +1,48 @@
1
+ import multiprocessing
2
+ from multiprocessing import Pool
3
+ import pandas as pd
4
+ import numpy as np
5
+ from functools import partial
6
+
7
+
8
+ def parallel_df(df,func,**kwargs):
9
+ if 'parallel_num' not in kwargs:
10
+ cpus = multiprocessing.cpu_count()
11
+ parallel_num = cpus * 2
12
+ else:
13
+ parallel_num = kwargs['parallel_num']
14
+ del kwargs['parallel_num']
15
+ num_parts = parallel_num
16
+ num_cores = parallel_num
17
+
18
+ df_split = np.array_split(df,num_parts)
19
+ pool = Pool(num_cores)
20
+ pfunc = partial(func,**kwargs)
21
+ df = pd.concat(pool.map(pfunc,df_split),axis=0,ignore_index=True)
22
+ pool.close()
23
+ pool.join()
24
+ return df
25
+
26
+
27
+ def parallel_df2nd(df,func,**kwargs):
28
+ if 'parallel_num' not in kwargs:
29
+ cpus = multiprocessing.cpu_count()
30
+ parallel_num = cpus * 2
31
+ else:
32
+ parallel_num = kwargs['parallel_num']
33
+ del kwargs['parallel_num']
34
+ num_parts = parallel_num
35
+ num_cores = parallel_num
36
+
37
+ df_split = np.array_split(df,num_parts)
38
+ pool = Pool(num_cores)
39
+ pfunc = partial(func,**kwargs)
40
+ nd = np.concatenate(pool.map(pfunc,df_split),axis=0)
41
+ pool.close()
42
+ pool.join()
43
+ return nd
44
+
45
+
46
+ def warm_up_func(x):
47
+ ret = x * 2
48
+ return ret
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.1
2
+ Name: dataquant
3
+ Version: 1.1.6
4
+ Summary: UNKNOWN
5
+ Home-page: UNKNOWN
6
+ Author: zszq
7
+ Author-email: jiangchao@stocke.com.cn
8
+ License: UNKNOWN
9
+ Keywords: ZHESHANG SECURITES DATA QUANT
10
+ Platform: UNKNOWN
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: GNU General Public License (GPL)
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3.5
15
+ Classifier: Programming Language :: Python :: 3.6
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Requires-Dist: numpy (>=1.18.1)
19
+ Requires-Dist: six (>=1.13.0)
20
+ Requires-Dist: pandas (>=0.24.2)
21
+ Requires-Dist: requests (>=2.7.0)
22
+ Requires-Dist: contextlib2 (>=0.5.3)
23
+ Requires-Dist: simplejson (>=3.17.0)
24
+ Requires-Dist: PyYAML (>=3.13)
25
+ Requires-Dist: ruamel.yaml (>=0.15.0)
26
+ Requires-Dist: gevent (>=1.3.0)
27
+
28
+ UNKNOWN
29
+
30
+
@@ -0,0 +1,38 @@
1
+ dataquant/__init__.py,sha256=Tuq3BymP4PO3__7MKLKTRKvyL8buZ1TG_DQ_g-nHU6s,6703
2
+ dataquant/apis/__init__.py,sha256=-sDr1WLWXNIEjCtHd9d7-5GNTrbml2IO4yIPhgKpNrI,25
3
+ dataquant/apis/base/__init__.py,sha256=kAux9NS2UsHvU02ZRDvH7p9ol8Dhlw2OhZrSuy4APZQ,88
4
+ dataquant/apis/base/api.py,sha256=Zt9EVSrYB3cj0yK0_HkdR8tGJzKn5xJQ5Ua4Su957wM,2103
5
+ dataquant/apis/info/__init__.py,sha256=-sDr1WLWXNIEjCtHd9d7-5GNTrbml2IO4yIPhgKpNrI,25
6
+ dataquant/apis/info/api.py,sha256=1dzZSn4qTfLWl0Evho5UTE7uOI64s2888lTUmcWDFIw,104572
7
+ dataquant/apis/quote/__init__.py,sha256=-sDr1WLWXNIEjCtHd9d7-5GNTrbml2IO4yIPhgKpNrI,25
8
+ dataquant/apis/quote/api.py,sha256=kR40zEqf0Riwc-sMbo6SCXfKdKxAybYM4dZYTfWqWPk,57350
9
+ dataquant/cd/__init__.py,sha256=-sDr1WLWXNIEjCtHd9d7-5GNTrbml2IO4yIPhgKpNrI,25
10
+ dataquant/cd/api.py,sha256=iZ9rIFYxOnRBBDOPhHFqqh3SyqiyIBaonPO3dOr5_0E,22768
11
+ dataquant/hk/__init__.py,sha256=-sDr1WLWXNIEjCtHd9d7-5GNTrbml2IO4yIPhgKpNrI,25
12
+ dataquant/hk/api.py,sha256=WefEhQMZ0_TETp6jvnmsC2eSjSu19aFINwDy2CG5ujg,34577
13
+ dataquant/ic/__init__.py,sha256=-sDr1WLWXNIEjCtHd9d7-5GNTrbml2IO4yIPhgKpNrI,25
14
+ dataquant/ic/api.py,sha256=IdYqmi7NrJHj9LXhIO5W6cI1Sew7fK2w25Y7ANCZdiA,4608
15
+ dataquant/intl/__init__.py,sha256=-sDr1WLWXNIEjCtHd9d7-5GNTrbml2IO4yIPhgKpNrI,25
16
+ dataquant/intl/api.py,sha256=e-RZnao4tHgH3uqfEbX4iDCoJ4zayQuSBPQqlXR-Nf4,4084
17
+ dataquant/pof/__init__.py,sha256=-sDr1WLWXNIEjCtHd9d7-5GNTrbml2IO4yIPhgKpNrI,25
18
+ dataquant/pof/api.py,sha256=B6L9CQBrQmGTIAZkwH-JtFO-SN9S7tjPJpxvAT2EFaY,64996
19
+ dataquant/sql/__init__.py,sha256=-sDr1WLWXNIEjCtHd9d7-5GNTrbml2IO4yIPhgKpNrI,25
20
+ dataquant/sql/api.py,sha256=63UQYKoI_5odfKV0L3LE3i8bYEC72sjk8eQtFfw9eMc,1523
21
+ dataquant/utils/__init__.py,sha256=NycWnpngLBA2lIMwigUqvokiq0OPODIsrES14BjsQWc,78
22
+ dataquant/utils/client.py,sha256=3uzXFIB91S6t6UlVIDlDuwRk0aUDTcLj_CUR49HqMw0,6177
23
+ dataquant/utils/common.py,sha256=9MTIbUYezEOZrQ1rP4KW36y_kOWk1f6yCyDq69IqMOU,781
24
+ dataquant/utils/config.py,sha256=nSrTD_-yXDNEV98n9zHz0fw8Rou5314XTdCP1fGtqqI,724
25
+ dataquant/utils/config.yml,sha256=NgzuhzYQPp3A0jFcw1pvw9saIPn1H2dKatWcaZbEfls,1009
26
+ dataquant/utils/connection.py,sha256=ypLIeSUnWYooOeRcYo1n2Lo9m_QB-NZcm_D3uLrCIAA,17609
27
+ dataquant/utils/connection_pool.py,sha256=sWThbX-nFVWFILwxeNP7L0RXDNbl4nqV6U6u6RMOewY,2282
28
+ dataquant/utils/consts.py,sha256=5FQ0s_2rPa2Vpj_dOhp6usXXAHPT9X-MBVVZLP2Uoqo,23
29
+ dataquant/utils/convert.py,sha256=5H-Ln5eCENv2VQY_FLxwXy3lLCbaELL1MGFQGLolDiE,1541
30
+ dataquant/utils/datetime_func.py,sha256=7hGpGsA4r4TA4D0CcgsUlfj4VVPJlSjJ3HR06T75BR4,2454
31
+ dataquant/utils/decorators.py,sha256=jVuNiIBCvVwu_XQHKODGSiqS8w-iYLl4wKEUDDI0qIU,3539
32
+ dataquant/utils/error.py,sha256=WMH3Bmov5bibyuHpc-ldLB8B8UoHThD0dzci7Np7Nr4,6281
33
+ dataquant/utils/parallel.py,sha256=xkbT2wtYkWMDdnZWsS3hqkIawGTlMVl1LvlU4JSPLo4,1213
34
+ dataquant-1.1.6.dist-info/METADATA,sha256=FCPQMaUIOcCGFRIxrNu8MLJ29GluzPoB5boqFY2uMog,889
35
+ dataquant-1.1.6.dist-info/RECORD,,
36
+ dataquant-1.1.6.dist-info/WHEEL,sha256=NzFAKnL7g-U64xnS1s5e3mJnxKpOTeOtlXdFwS9yNXI,92
37
+ dataquant-1.1.6.dist-info/entry_points.txt,sha256=ZgdrSUUnnklMi7msu0gUGaFTXeoIGmKW3e9xi6DY36w,55
38
+ dataquant-1.1.6.dist-info/top_level.txt,sha256=z2BOKZHAM7WQu1DD-0rXZjkE9xLvpWKgxesk5SG1Qwo,10
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.31.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ dataquant = dataquant.__main__:main
3
+
@@ -0,0 +1 @@
1
+ dataquant