pyxllib 0.0.43__py3-none-any.whl → 0.3.197__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.
- pyxllib/__init__.py +9 -2
- pyxllib/algo/__init__.py +8 -0
- pyxllib/algo/disjoint.py +54 -0
- pyxllib/algo/geo.py +541 -0
- pyxllib/{util/mathlib.py → algo/intervals.py} +172 -36
- pyxllib/algo/matcher.py +389 -0
- pyxllib/algo/newbie.py +166 -0
- pyxllib/algo/pupil.py +629 -0
- pyxllib/algo/shapelylib.py +67 -0
- pyxllib/algo/specialist.py +241 -0
- pyxllib/algo/stat.py +494 -0
- pyxllib/algo/treelib.py +149 -0
- pyxllib/algo/unitlib.py +66 -0
- pyxllib/autogui/__init__.py +5 -0
- pyxllib/autogui/activewin.py +246 -0
- pyxllib/autogui/all.py +9 -0
- pyxllib/autogui/autogui.py +852 -0
- pyxllib/autogui/uiautolib.py +362 -0
- pyxllib/autogui/virtualkey.py +102 -0
- pyxllib/autogui/wechat.py +827 -0
- pyxllib/autogui/wechat_msg.py +421 -0
- pyxllib/autogui/wxautolib.py +84 -0
- pyxllib/cv/__init__.py +1 -11
- pyxllib/cv/expert.py +267 -0
- pyxllib/cv/{imlib.py → imfile.py} +18 -83
- pyxllib/cv/imhash.py +39 -0
- pyxllib/cv/pupil.py +9 -0
- pyxllib/cv/rgbfmt.py +1525 -0
- pyxllib/cv/slidercaptcha.py +137 -0
- pyxllib/cv/trackbartools.py +163 -49
- pyxllib/cv/xlcvlib.py +1040 -0
- pyxllib/cv/xlpillib.py +423 -0
- pyxllib/data/__init__.py +0 -0
- pyxllib/data/echarts.py +240 -0
- pyxllib/data/jsonlib.py +89 -0
- pyxllib/{util/oss2_.py → data/oss.py} +11 -9
- pyxllib/data/pglib.py +1127 -0
- pyxllib/data/sqlite.py +568 -0
- pyxllib/{util → data}/sqllib.py +13 -31
- pyxllib/ext/JLineViewer.py +505 -0
- pyxllib/ext/__init__.py +6 -0
- pyxllib/{util → ext}/demolib.py +119 -35
- pyxllib/ext/drissionlib.py +277 -0
- pyxllib/ext/kq5034lib.py +12 -0
- pyxllib/{util/main.py → ext/old.py} +122 -284
- pyxllib/ext/qt.py +449 -0
- pyxllib/ext/robustprocfile.py +497 -0
- pyxllib/ext/seleniumlib.py +76 -0
- pyxllib/{util/tklib.py → ext/tk.py} +10 -11
- pyxllib/ext/unixlib.py +827 -0
- pyxllib/ext/utools.py +351 -0
- pyxllib/{util/webhooklib.py → ext/webhook.py} +45 -17
- pyxllib/ext/win32lib.py +40 -0
- pyxllib/ext/wjxlib.py +88 -0
- pyxllib/ext/wpsapi.py +124 -0
- pyxllib/ext/xlwork.py +9 -0
- pyxllib/ext/yuquelib.py +1105 -0
- pyxllib/file/__init__.py +17 -0
- pyxllib/file/docxlib.py +761 -0
- pyxllib/{util → file}/gitlib.py +40 -27
- pyxllib/file/libreoffice.py +165 -0
- pyxllib/file/movielib.py +148 -0
- pyxllib/file/newbie.py +10 -0
- pyxllib/file/onenotelib.py +1469 -0
- pyxllib/file/packlib/__init__.py +330 -0
- pyxllib/{util → file/packlib}/zipfile.py +598 -195
- pyxllib/file/pdflib.py +426 -0
- pyxllib/file/pupil.py +185 -0
- pyxllib/file/specialist/__init__.py +685 -0
- pyxllib/{basic/_5_dirlib.py → file/specialist/dirlib.py} +364 -93
- pyxllib/file/specialist/download.py +193 -0
- pyxllib/file/specialist/filelib.py +2829 -0
- pyxllib/file/xlsxlib.py +3131 -0
- pyxllib/file/xlsyncfile.py +341 -0
- pyxllib/prog/__init__.py +5 -0
- pyxllib/prog/cachetools.py +64 -0
- pyxllib/prog/deprecatedlib.py +233 -0
- pyxllib/prog/filelock.py +42 -0
- pyxllib/prog/ipyexec.py +253 -0
- pyxllib/prog/multiprogs.py +940 -0
- pyxllib/prog/newbie.py +451 -0
- pyxllib/prog/pupil.py +1197 -0
- pyxllib/{sitepackages.py → prog/sitepackages.py} +5 -3
- pyxllib/prog/specialist/__init__.py +391 -0
- pyxllib/prog/specialist/bc.py +203 -0
- pyxllib/prog/specialist/browser.py +497 -0
- pyxllib/prog/specialist/common.py +347 -0
- pyxllib/prog/specialist/datetime.py +199 -0
- pyxllib/prog/specialist/tictoc.py +240 -0
- pyxllib/prog/specialist/xllog.py +180 -0
- pyxllib/prog/xlosenv.py +108 -0
- pyxllib/stdlib/__init__.py +17 -0
- pyxllib/{util → stdlib}/tablepyxl/__init__.py +1 -3
- pyxllib/{util → stdlib}/tablepyxl/style.py +1 -1
- pyxllib/{util → stdlib}/tablepyxl/tablepyxl.py +2 -4
- pyxllib/text/__init__.py +8 -0
- pyxllib/text/ahocorasick.py +39 -0
- pyxllib/text/airscript.js +744 -0
- pyxllib/text/charclasslib.py +121 -0
- pyxllib/text/jiebalib.py +267 -0
- pyxllib/text/jinjalib.py +32 -0
- pyxllib/text/jsa_ai_prompt.md +271 -0
- pyxllib/text/jscode.py +922 -0
- pyxllib/text/latex/__init__.py +158 -0
- pyxllib/text/levenshtein.py +303 -0
- pyxllib/text/nestenv.py +1215 -0
- pyxllib/text/newbie.py +300 -0
- pyxllib/text/pupil/__init__.py +8 -0
- pyxllib/text/pupil/common.py +1121 -0
- pyxllib/text/pupil/xlalign.py +326 -0
- pyxllib/text/pycode.py +47 -0
- pyxllib/text/specialist/__init__.py +8 -0
- pyxllib/text/specialist/common.py +112 -0
- pyxllib/text/specialist/ptag.py +186 -0
- pyxllib/text/spellchecker.py +172 -0
- pyxllib/text/templates/echart_base.html +11 -0
- pyxllib/text/templates/highlight_code.html +17 -0
- pyxllib/text/templates/latex_editor.html +103 -0
- pyxllib/text/vbacode.py +17 -0
- pyxllib/text/xmllib.py +747 -0
- pyxllib/xl.py +39 -0
- pyxllib/xlcv.py +17 -0
- pyxllib-0.3.197.dist-info/METADATA +48 -0
- pyxllib-0.3.197.dist-info/RECORD +126 -0
- {pyxllib-0.0.43.dist-info → pyxllib-0.3.197.dist-info}/WHEEL +4 -5
- pyxllib/basic/_1_strlib.py +0 -945
- pyxllib/basic/_2_timelib.py +0 -488
- pyxllib/basic/_3_pathlib.py +0 -916
- pyxllib/basic/_4_loglib.py +0 -419
- pyxllib/basic/__init__.py +0 -54
- pyxllib/basic/arrow_.py +0 -250
- pyxllib/basic/chardet_.py +0 -66
- pyxllib/basic/dirlib.py +0 -529
- pyxllib/basic/dprint.py +0 -202
- pyxllib/basic/extension.py +0 -12
- pyxllib/basic/judge.py +0 -31
- pyxllib/basic/log.py +0 -204
- pyxllib/basic/pathlib_.py +0 -705
- pyxllib/basic/pytictoc.py +0 -102
- pyxllib/basic/qiniu_.py +0 -61
- pyxllib/basic/strlib.py +0 -761
- pyxllib/basic/timer.py +0 -132
- pyxllib/cv/cv.py +0 -834
- pyxllib/cv/cvlib/_1_geo.py +0 -543
- pyxllib/cv/cvlib/_2_cvprcs.py +0 -309
- pyxllib/cv/cvlib/_2_imgproc.py +0 -594
- pyxllib/cv/cvlib/_3_pilprcs.py +0 -80
- pyxllib/cv/cvlib/_4_cvimg.py +0 -211
- pyxllib/cv/cvlib/__init__.py +0 -10
- pyxllib/cv/debugtools.py +0 -82
- pyxllib/cv/fitz_.py +0 -300
- pyxllib/cv/installer.py +0 -42
- pyxllib/debug/_0_installer.py +0 -38
- pyxllib/debug/_1_typelib.py +0 -277
- pyxllib/debug/_2_chrome.py +0 -198
- pyxllib/debug/_3_showdir.py +0 -161
- pyxllib/debug/_4_bcompare.py +0 -140
- pyxllib/debug/__init__.py +0 -49
- pyxllib/debug/bcompare.py +0 -132
- pyxllib/debug/chrome.py +0 -198
- pyxllib/debug/installer.py +0 -38
- pyxllib/debug/showdir.py +0 -158
- pyxllib/debug/typelib.py +0 -278
- pyxllib/image/__init__.py +0 -12
- pyxllib/torch/__init__.py +0 -20
- pyxllib/torch/modellib.py +0 -37
- pyxllib/torch/trainlib.py +0 -344
- pyxllib/util/__init__.py +0 -20
- pyxllib/util/aip_.py +0 -141
- pyxllib/util/casiadb.py +0 -59
- pyxllib/util/excellib.py +0 -495
- pyxllib/util/filelib.py +0 -612
- pyxllib/util/jsondata.py +0 -27
- pyxllib/util/jsondata2.py +0 -92
- pyxllib/util/labelmelib.py +0 -139
- pyxllib/util/onepy/__init__.py +0 -29
- pyxllib/util/onepy/onepy.py +0 -574
- pyxllib/util/onepy/onmanager.py +0 -170
- pyxllib/util/pyautogui_.py +0 -219
- pyxllib/util/textlib.py +0 -1305
- pyxllib/util/unorder.py +0 -22
- pyxllib/util/xmllib.py +0 -639
- pyxllib-0.0.43.dist-info/METADATA +0 -39
- pyxllib-0.0.43.dist-info/RECORD +0 -80
- pyxllib-0.0.43.dist-info/top_level.txt +0 -1
- {pyxllib-0.0.43.dist-info → pyxllib-0.3.197.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,241 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# @Author : 陈坤泽
|
4
|
+
# @Email : 877362867@qq.com
|
5
|
+
# @Date : 2021/06/06 11:16
|
6
|
+
|
7
|
+
import copy
|
8
|
+
import itertools
|
9
|
+
|
10
|
+
import numpy as np
|
11
|
+
import pandas as pd
|
12
|
+
|
13
|
+
from pyxllib.prog.pupil import DictTool
|
14
|
+
# from pyxllib.prog.deprecatedlib import deprecated
|
15
|
+
from deprecated import deprecated
|
16
|
+
|
17
|
+
|
18
|
+
@deprecated(reason='这个实现方式不佳,请参考 make_index_function')
|
19
|
+
def sort_by_given_list(a, b):
|
20
|
+
r""" 本函数一般用在数据透视表中,分组中元素名为中文,没有按指定规律排序的情况
|
21
|
+
|
22
|
+
:param a: 需要排序的对象
|
23
|
+
:param b: 参照的排序数组
|
24
|
+
:return: 排序后的a
|
25
|
+
|
26
|
+
>>> sort_by_given_list(['初中', '小学', '高中'], ['少儿', '小学', '初中', '高中'])
|
27
|
+
['小学', '初中', '高中']
|
28
|
+
|
29
|
+
# 不在枚举项目里的,会统一列在最后面
|
30
|
+
>>> sort_by_given_list(['初中', '小学', '高中', '幼儿'], ['少儿', '小学', '初中', '高中'])
|
31
|
+
['小学', '初中', '高中', '幼儿']
|
32
|
+
"""
|
33
|
+
# 1 从b数组构造一个d字典,d[k]=i,值为k的元素在第i位
|
34
|
+
d = dict()
|
35
|
+
for i, bb in enumerate(b): d[bb] = i
|
36
|
+
# 2 a数组分两部分,可以通过d排序的a1,和不能通过d排序的a2
|
37
|
+
a1, a2 = [], []
|
38
|
+
for aa in a:
|
39
|
+
if aa in d:
|
40
|
+
a1.append(aa)
|
41
|
+
else:
|
42
|
+
a2.append(aa)
|
43
|
+
# 3 用不同的规则排序a1、a2后合并
|
44
|
+
a1 = sorted(a1, key=lambda x: d[x])
|
45
|
+
a2 = sorted(a2)
|
46
|
+
return a1 + a2
|
47
|
+
|
48
|
+
|
49
|
+
def product(*iterables, order=None, repeat=1):
|
50
|
+
""" 对 itertools 的product扩展orders参数的更高级的product迭代器
|
51
|
+
|
52
|
+
:param order: 假设iterables有n=3个迭代器,则默认 orders=[1, 2, 3] (起始编号1)
|
53
|
+
即标准的product,是按顺序对每个迭代器进行重置、遍历的
|
54
|
+
但是我扩展的这个接口,允许调整每个维度的更新顺序
|
55
|
+
例如设置为 [-2, 1, 3],表示先对第2维降序,然后按第1、3维的方式排序获得各个坐标点
|
56
|
+
注:可以只输入[-2],默认会自动补充维[1, 3]
|
57
|
+
|
58
|
+
不从0开始编号,是因为0没法记录正负排序情况
|
59
|
+
|
60
|
+
for x in product('ab', 'cd', 'ef', order=[3, -2, 1]):
|
61
|
+
print(x)
|
62
|
+
|
63
|
+
['a', 'd', 'e']
|
64
|
+
['b', 'd', 'e']
|
65
|
+
['a', 'c', 'e']
|
66
|
+
['b', 'c', 'e']
|
67
|
+
['a', 'd', 'f']
|
68
|
+
['b', 'd', 'f']
|
69
|
+
['a', 'c', 'f']
|
70
|
+
['b', 'c', 'f']
|
71
|
+
|
72
|
+
TODO 我在想numpy这么牛逼,会不会有等价的功能接口可以实现,我不用重复造轮子?
|
73
|
+
"""
|
74
|
+
# 一、标准调用方式
|
75
|
+
if order is None:
|
76
|
+
for x in itertools.product(*iterables, repeat=repeat):
|
77
|
+
yield x
|
78
|
+
return
|
79
|
+
|
80
|
+
# 二、输入orders参数的调用方式
|
81
|
+
# 1 补全orders参数长度
|
82
|
+
n = len(iterables)
|
83
|
+
for i in range(1, n + 1):
|
84
|
+
if not (i in order or -i in order):
|
85
|
+
order.append(i)
|
86
|
+
if len(order) != n: return ValueError(f'orders参数值有问题 {order}')
|
87
|
+
|
88
|
+
# 2 生成新的迭代器组
|
89
|
+
new_iterables = [(iterables[i - 1] if i > 0 else reversed(iterables[-i - 1])) for i in order]
|
90
|
+
idx = np.argsort([abs(i) - 1 for i in order])
|
91
|
+
for y in itertools.product(*new_iterables, repeat=repeat):
|
92
|
+
yield [y[i] for i in idx]
|
93
|
+
|
94
|
+
|
95
|
+
class MatchPairs:
|
96
|
+
""" 匹配类,对X,Y两组数据中的x,y等对象按照cmp_func的规则进行相似度配对
|
97
|
+
|
98
|
+
MatchBase(ys, cmp_func).matches(xs, least_score)
|
99
|
+
"""
|
100
|
+
|
101
|
+
def __init__(self, ys, cmp_func):
|
102
|
+
self.ys = list(ys)
|
103
|
+
self.cmp_func = cmp_func
|
104
|
+
|
105
|
+
def __getitem__(self, idx):
|
106
|
+
return self.ys[idx]
|
107
|
+
|
108
|
+
# def __del__(self, idx):
|
109
|
+
# del self.ys[idx]
|
110
|
+
|
111
|
+
def __len__(self):
|
112
|
+
return len(self.ys)
|
113
|
+
|
114
|
+
def match(self, x, k=1):
|
115
|
+
""" 匹配一个对象
|
116
|
+
|
117
|
+
:param x: 待匹配的一个对象
|
118
|
+
:param k: 返回次优的几个结果
|
119
|
+
:return:
|
120
|
+
当 k = 1 时,返回 (idx, score)
|
121
|
+
当 k > 1 时,返回 [(idx1, score1), (idx2, score2), ...]
|
122
|
+
"""
|
123
|
+
scores = [self.cmp_func(x, y) for y in self.ys]
|
124
|
+
if k == 1:
|
125
|
+
score = max(scores)
|
126
|
+
idx = scores.index(score)
|
127
|
+
return idx, score
|
128
|
+
else:
|
129
|
+
# 按权重从大到小排序
|
130
|
+
idxs = np.argsort(scores)
|
131
|
+
idxs = idxs[::-1][:k]
|
132
|
+
return [(idx, scores[idx]) for idx in idxs]
|
133
|
+
|
134
|
+
def matches(self, xs):
|
135
|
+
""" 对xs中每个元素都找到一个最佳匹配对象
|
136
|
+
|
137
|
+
注意:这个功能是支持ys中的元素被重复匹配的,而且哪怕相似度很低,也会返回一个最佳匹配结果
|
138
|
+
如果想限定相似度,或者不支持重复匹配,请到隔壁使用 matchpairs
|
139
|
+
|
140
|
+
:param xs: 要匹配的一组对象
|
141
|
+
:return: 为每个x找到一个最佳的匹配y,存储其下标和对应的分值
|
142
|
+
[(idx0, score0), (idx1, score1), ...] 长度 = len(xs)
|
143
|
+
|
144
|
+
>>> m = MatchPairs([1, 5, 8, 9, 2], lambda x,y: 1-abs(x-y)/max(x,y))
|
145
|
+
>>> m.matches([4, 6]) # 这里第1个值是下标,所以分别是对应5、8
|
146
|
+
[(1, 0.8), (1, 0.8333333333333334)]
|
147
|
+
|
148
|
+
# 要匹配的对象多于实际ys,则只会返回前len(ys)个结果
|
149
|
+
# 这种情况建议用matchpairs功能实现,或者实在想用就对调xs、ys
|
150
|
+
>>> m.matches([4, 6, 1, 2, 9, 4, 5])
|
151
|
+
[(1, 0.8), (1, 0.8333333333333334), (0, 1.0), (4, 1.0), (3, 1.0), (1, 0.8), (1, 1.0)]
|
152
|
+
"""
|
153
|
+
return [self.match(x) for x in xs]
|
154
|
+
|
155
|
+
|
156
|
+
def get_ndim(coords):
|
157
|
+
# 注意 np.array(coords[:1]),只需要取第一个元素就可以判断出ndim
|
158
|
+
coords = coords if isinstance(coords, np.ndarray) else np.array(coords[:1])
|
159
|
+
return coords.ndim
|
160
|
+
|
161
|
+
|
162
|
+
class DictCmper:
|
163
|
+
""" 字典结构比较工具
|
164
|
+
|
165
|
+
集合是字典的特殊情况,也支持集合间的对比
|
166
|
+
"""
|
167
|
+
|
168
|
+
def __init__(self, dicts):
|
169
|
+
"""
|
170
|
+
:param Dict[str, Dict|set] dicts: Dicts[dictname, dict_]
|
171
|
+
如果是set,会升级为dict,value默认为1
|
172
|
+
"""
|
173
|
+
self.dicts = {}
|
174
|
+
for k, v in dicts.items():
|
175
|
+
if isinstance(v, set):
|
176
|
+
self.dicts[k] = {k: 1 for k in v}
|
177
|
+
else:
|
178
|
+
self.dicts[k] = v
|
179
|
+
|
180
|
+
def details(self):
|
181
|
+
""" 返回详细的分析表
|
182
|
+
|
183
|
+
按行罗列所有键,按列罗列所有字典,中间显示各字典键值
|
184
|
+
可以把结果保存到excel,然后详细筛选分析
|
185
|
+
|
186
|
+
>>> dc = DictCmper({'d1': {'a': 1, 'b': 2}, 'd2': {'b': 3, 'e': 5}, 'd3': {'d': 4}})
|
187
|
+
>>> dc.details()
|
188
|
+
d1 d2 d3
|
189
|
+
a 1.0 NaN NaN
|
190
|
+
b 2.0 3.0 NaN
|
191
|
+
e NaN 5.0 NaN
|
192
|
+
d NaN NaN 4.0
|
193
|
+
"""
|
194
|
+
# 1 获得所有键
|
195
|
+
# 集合无法保存元素顺序,所以用合并字典来代替
|
196
|
+
# 还有个三方库orderedset,不想安装。就这样简便解决就好。
|
197
|
+
keys = DictTool.or_(*self.dicts.values()).keys()
|
198
|
+
|
199
|
+
# 2 取出所有字典值
|
200
|
+
ls = []
|
201
|
+
for k in keys:
|
202
|
+
ls.append([(d[k] if k in d else np.nan) for d in self.dicts.values()])
|
203
|
+
|
204
|
+
# 3 转为df表格
|
205
|
+
df = pd.DataFrame.from_records(ls, columns=self.dicts.keys())
|
206
|
+
df.index = keys
|
207
|
+
return df
|
208
|
+
|
209
|
+
def pair_summary(self, func=lambda x, y: len(x.keys() & y.keys())):
|
210
|
+
r""" 两两对比表
|
211
|
+
|
212
|
+
:param func: 默认是计算两个字典共有的键数量
|
213
|
+
:return: df
|
214
|
+
df对角线存储的是每个集合自身大小,df第i行第j列是第i个集合减去第j个集合的剩余元素数
|
215
|
+
|
216
|
+
>>> s1 = {1, 2, 3, 4, 5, 6, 7, 8, 9}
|
217
|
+
>>> s2 = {1, 3, 5, 7, 8}
|
218
|
+
>>> s3 = {2, 3, 5, 8}
|
219
|
+
>>> dc = DictCmper({'s1': s1, 's2': s2, 's3': s3})
|
220
|
+
>>> dc.pair_summary()
|
221
|
+
s1 s2 s3
|
222
|
+
s1 9 5 4
|
223
|
+
s2 5 5 3
|
224
|
+
s3 4 3 4
|
225
|
+
>>> dc.pair_summary(lambda x, y: len(x.keys() - y.keys()))
|
226
|
+
s1 s2 s3
|
227
|
+
s1 0 4 5
|
228
|
+
s2 0 0 2
|
229
|
+
s3 0 1 0
|
230
|
+
"""
|
231
|
+
dictnames = list(self.dicts.keys())
|
232
|
+
n = len(dictnames)
|
233
|
+
rows = []
|
234
|
+
for i, name1 in enumerate(dictnames):
|
235
|
+
row = [0] * n
|
236
|
+
for j, name2 in enumerate(dictnames):
|
237
|
+
row[j] = func(self.dicts[name1], self.dicts[name2])
|
238
|
+
rows.append(row)
|
239
|
+
df = pd.DataFrame.from_records(rows, columns=dictnames)
|
240
|
+
df.index = dictnames
|
241
|
+
return df
|