cangling-ai 0.1.4__tar.gz

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,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: cangling-ai
3
+ Version: 0.1.4
4
+ Summary: cangling ai library
5
+ Author-email: zhangjianshe <zhangjianshe@gmail.com>
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: kafka-python==2.2.15
8
+
9
+ # cangling ai library
10
+
11
+ ## 准备
12
+ ```shell
13
+ pip install twine
14
+ pip install build
15
+ ```
16
+
17
+ ## 编译打包
18
+ ```shell
19
+ pip -m build
20
+ ```
21
+
22
+ ## 预发布
23
+ ```shell
24
+ python -m twine upload --repository testpypi dist/*
25
+ ```
26
+
27
+ ## 发布
28
+ ```shell
29
+ python -m twine upload -r nexus dist/*
30
+ ```
31
+
32
+ ## 使用
33
+ ```shell
34
+ pip install cangling-ai
35
+ ```
36
+
37
+
38
+
39
+ ## 发布到repo.cangling.cn
40
+ > 在HOME目录下创建 .pypirc 文件
41
+ > 内容如下
42
+ ```toml
43
+ [distutils]
44
+ index-servers =
45
+ nexus
46
+
47
+ [nexus]
48
+ repository = https://repo.cangling.cn/repository/cangling-py/
49
+ username = cangling
50
+ password = <PASSWORD>
51
+ ```
52
+
53
+ ## 客户端配置
54
+ Create or edit your pip.conf (Linux/macOS: ~/.config/pip/pip.conf; Windows: %APPDATA%\pip\pip.ini):
55
+
56
+ ```toml
57
+ [global]
58
+ index-url = https://repo.cangling.cn/repository/pypi-all/simple
59
+ trusted-host = repo.cangling.cn
60
+ ```
@@ -0,0 +1,52 @@
1
+ # cangling ai library
2
+
3
+ ## 准备
4
+ ```shell
5
+ pip install twine
6
+ pip install build
7
+ ```
8
+
9
+ ## 编译打包
10
+ ```shell
11
+ pip -m build
12
+ ```
13
+
14
+ ## 预发布
15
+ ```shell
16
+ python -m twine upload --repository testpypi dist/*
17
+ ```
18
+
19
+ ## 发布
20
+ ```shell
21
+ python -m twine upload -r nexus dist/*
22
+ ```
23
+
24
+ ## 使用
25
+ ```shell
26
+ pip install cangling-ai
27
+ ```
28
+
29
+
30
+
31
+ ## 发布到repo.cangling.cn
32
+ > 在HOME目录下创建 .pypirc 文件
33
+ > 内容如下
34
+ ```toml
35
+ [distutils]
36
+ index-servers =
37
+ nexus
38
+
39
+ [nexus]
40
+ repository = https://repo.cangling.cn/repository/cangling-py/
41
+ username = cangling
42
+ password = <PASSWORD>
43
+ ```
44
+
45
+ ## 客户端配置
46
+ Create or edit your pip.conf (Linux/macOS: ~/.config/pip/pip.conf; Windows: %APPDATA%\pip\pip.ini):
47
+
48
+ ```toml
49
+ [global]
50
+ index-url = https://repo.cangling.cn/repository/pypi-all/simple
51
+ trusted-host = repo.cangling.cn
52
+ ```
File without changes
@@ -0,0 +1,112 @@
1
+ from kafka import KafkaProducer
2
+ import json
3
+ import time
4
+ import uuid
5
+ from copy import deepcopy
6
+ import os
7
+ import time
8
+
9
+ class ProgressMessageSender():
10
+ def __init__(self, bootstrap_servers='', topic='', taskId=None):
11
+ try:
12
+ self.producer = KafkaProducer(bootstrap_servers=bootstrap_servers)
13
+ except:
14
+ self.producer = None
15
+ print('failed to create sender.')
16
+ return
17
+ self.topic = topic
18
+ if taskId is None:
19
+ taskId = str(uuid.uuid4())
20
+ self.taskId = taskId
21
+ self.msg_dict_default = {
22
+ 'messageType': 'progress',
23
+ 'sendTime': '0000-00-00 00:00:00',
24
+ 'taskId': self.taskId,
25
+ }
26
+ self.titleId = str(uuid.uuid4())
27
+ self.fixed_msg_dict = {
28
+ 'version': '3',
29
+ 'title': 'unknown',
30
+ 'titleId': self.titleId,
31
+ 'source': 'default',
32
+ 'rank': 0,
33
+ }
34
+ '''
35
+ @message template
36
+ version: 3 @str
37
+ progress: 0 @int
38
+ runningStatus: running @str # running, completed
39
+ runningInfo: starting @str ## Anything
40
+ title: module name @str ## Anything
41
+ titleId: module id @str ## Anything
42
+ source: module @str # module, engine
43
+ rank: 0 @int
44
+ totalProgress: 0 @int
45
+ totalRunningStatus: running @str # running, completed
46
+ totalRunningInfo: starting @str ## Anything
47
+ inferProgress: 0 @int
48
+ inferFilename: somefile.tif @str
49
+ inferPreviewFilename: somefile_id.tif @str
50
+ inferGeoInfo: POLYGON(({x1} {y1}, {x2} {y2}, {x3} {y3}, {x4} {y4}, {x1} {y1})) @str - list
51
+ inferObjectGeoInfo: POLYGON(({x1} {y1}, {x2} {y2}, {x3} {y3}, {x4} {y4}, {x1} {y1})) @str - list
52
+ '''
53
+
54
+ def _build_msg_dict(self, msg_dict):
55
+ _msg_dict = deepcopy(self.msg_dict_default)
56
+ _message_key = []
57
+ _message_content = {}
58
+ for k, v in msg_dict.items():
59
+ _message_key.append(k)
60
+ _message_content[k] = v
61
+ _msg_dict['messageKey'] = _message_key
62
+ _msg_dict['messageContent'] = _message_content
63
+ _msg_dict['sendTime'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
64
+ return _msg_dict
65
+
66
+ def _check_basic_message(self, message_dict):
67
+ if 'progress' not in message_dict:
68
+ message_dict['progress'] = 0
69
+ if 'runningStatus' not in message_dict:
70
+ message_dict['runningStatus'] = 'unknown'
71
+ if 'runningInfo' not in message_dict:
72
+ message_dict['runningInfo'] = 'null'
73
+ return message_dict
74
+
75
+ def _append_fixed_message(self, message_dict):
76
+ for k, v in self.fixed_msg_dict.items():
77
+ message_dict[k] = v
78
+ return message_dict
79
+
80
+ def is_none(self):
81
+ return self.producer is None
82
+
83
+ def get_task_id(self):
84
+ if self.producer is not None:
85
+ return self.taskId
86
+
87
+ def set_title(self, title=None, titleId=None):
88
+ if title is not None:
89
+ self.fixed_msg_dict['title'] = title
90
+ if titleId is not None:
91
+ self.fixed_msg_dict['titleId'] = titleId
92
+
93
+ def set_source(self, source=None, rank=None):
94
+ if source is not None:
95
+ self.fixed_msg_dict['source'] = source
96
+ if rank is not None:
97
+ self.fixed_msg_dict['rank'] = rank
98
+
99
+ def send(self, message_dict):
100
+ if self.producer is not None:
101
+ message_dict = self._check_basic_message(message_dict)
102
+ message_dict = self._append_fixed_message(message_dict)
103
+ message_dict = self._build_msg_dict(message_dict)
104
+ msg = json.dumps(message_dict).encode('utf-8')
105
+ #try:
106
+ self.producer.send(self.topic, msg)
107
+ self.producer.flush()
108
+ #except:
109
+ # print('failed to send message.')
110
+
111
+ def calc_progress_value(self, index, total, min_value=0, max_value=100):
112
+ return int(index / total * (max_value - min_value) + min_value)
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: cangling-ai
3
+ Version: 0.1.4
4
+ Summary: cangling ai library
5
+ Author-email: zhangjianshe <zhangjianshe@gmail.com>
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: kafka-python==2.2.15
8
+
9
+ # cangling ai library
10
+
11
+ ## 准备
12
+ ```shell
13
+ pip install twine
14
+ pip install build
15
+ ```
16
+
17
+ ## 编译打包
18
+ ```shell
19
+ pip -m build
20
+ ```
21
+
22
+ ## 预发布
23
+ ```shell
24
+ python -m twine upload --repository testpypi dist/*
25
+ ```
26
+
27
+ ## 发布
28
+ ```shell
29
+ python -m twine upload -r nexus dist/*
30
+ ```
31
+
32
+ ## 使用
33
+ ```shell
34
+ pip install cangling-ai
35
+ ```
36
+
37
+
38
+
39
+ ## 发布到repo.cangling.cn
40
+ > 在HOME目录下创建 .pypirc 文件
41
+ > 内容如下
42
+ ```toml
43
+ [distutils]
44
+ index-servers =
45
+ nexus
46
+
47
+ [nexus]
48
+ repository = https://repo.cangling.cn/repository/cangling-py/
49
+ username = cangling
50
+ password = <PASSWORD>
51
+ ```
52
+
53
+ ## 客户端配置
54
+ Create or edit your pip.conf (Linux/macOS: ~/.config/pip/pip.conf; Windows: %APPDATA%\pip\pip.ini):
55
+
56
+ ```toml
57
+ [global]
58
+ index-url = https://repo.cangling.cn/repository/pypi-all/simple
59
+ trusted-host = repo.cangling.cn
60
+ ```
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ cangling/logger/__init__.py
4
+ cangling/logger/message_sender.py
5
+ cangling_ai.egg-info/PKG-INFO
6
+ cangling_ai.egg-info/SOURCES.txt
7
+ cangling_ai.egg-info/dependency_links.txt
8
+ cangling_ai.egg-info/requires.txt
9
+ cangling_ai.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ kafka-python==2.2.15
@@ -0,0 +1 @@
1
+ cangling
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "cangling-ai"
3
+ version = "0.1.4"
4
+ description = "cangling ai library"
5
+ readme = "README.md"
6
+ authors = [{name = "zhangjianshe", email = "zhangjianshe@gmail.com"}]
7
+ dependencies = [
8
+ "kafka-python==2.2.15",
9
+ ]
10
+
11
+ [tool.setuptools.packages.find]
12
+ where = ["."]
13
+ include = ["canglin*"]
14
+
15
+ [build-system]
16
+ requires = ["setuptools", "wheel"]
17
+ build-backend = "setuptools.build_meta"
18
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+