staran 0.2.0__py3-none-any.whl → 0.2.1__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.
- staran/__init__.py +1 -0
- staran-0.2.1.dist-info/METADATA +197 -0
- staran-0.2.1.dist-info/RECORD +8 -0
- staran-0.2.0.dist-info/METADATA +0 -24
- staran-0.2.0.dist-info/RECORD +0 -8
- {staran-0.2.0.dist-info → staran-0.2.1.dist-info}/WHEEL +0 -0
- {staran-0.2.0.dist-info → staran-0.2.1.dist-info}/licenses/LICENSE +0 -0
- {staran-0.2.0.dist-info → staran-0.2.1.dist-info}/top_level.txt +0 -0
staran/__init__.py
CHANGED
@@ -0,0 +1,197 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: staran
|
3
|
+
Version: 0.2.1
|
4
|
+
Summary: staran - 高性能Python工具库
|
5
|
+
Home-page: https://github.com/starlxa/staran
|
6
|
+
Author: StarAn
|
7
|
+
Author-email: starlxa@icloud.com
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Requires-Python: >=3.7
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
License-File: LICENSE
|
13
|
+
Requires-Dist: datetime
|
14
|
+
Requires-Dist: calendar
|
15
|
+
Requires-Dist: re
|
16
|
+
Dynamic: author
|
17
|
+
Dynamic: author-email
|
18
|
+
Dynamic: classifier
|
19
|
+
Dynamic: description
|
20
|
+
Dynamic: description-content-type
|
21
|
+
Dynamic: home-page
|
22
|
+
Dynamic: license-file
|
23
|
+
Dynamic: requires-dist
|
24
|
+
Dynamic: requires-python
|
25
|
+
Dynamic: summary
|
26
|
+
|
27
|
+
# Staran - 简化的Python工具库
|
28
|
+
|
29
|
+
## 📦 轻量级Python实用工具集
|
30
|
+
|
31
|
+
Staran是一个基于Python标准库的实用工具库,提供日期处理、SQL生成等常用功能,无需复杂依赖。
|
32
|
+
|
33
|
+
## 🚀 快速开始
|
34
|
+
|
35
|
+
### 安装
|
36
|
+
```bash
|
37
|
+
pip install staran
|
38
|
+
```
|
39
|
+
|
40
|
+
### Date工具 - 智能日期处理
|
41
|
+
|
42
|
+
```python
|
43
|
+
from staran import Date
|
44
|
+
|
45
|
+
# 创建日期 - 智能格式记忆
|
46
|
+
date1 = Date('202504') # 输出: 202504 (记住年月格式)
|
47
|
+
date2 = Date('20250415') # 输出: 20250415 (记住完整格式)
|
48
|
+
date3 = Date(2025, 4, 15) # 输出: 2025-04-15
|
49
|
+
|
50
|
+
# 日期运算保持格式
|
51
|
+
new_date = date1.add_months(2) # 输出: 202506 (保持YYYYMM格式)
|
52
|
+
```
|
53
|
+
|
54
|
+
### SQL工具 - 数据分析SQL生成
|
55
|
+
|
56
|
+
```python
|
57
|
+
from staran import TableSchema, FeatureGenerator
|
58
|
+
|
59
|
+
# 定义表结构
|
60
|
+
schema = TableSchema('user_behavior')
|
61
|
+
schema.add_primary_key('user_id', 'string')
|
62
|
+
schema.add_date_field('date', 'date')
|
63
|
+
schema.add_field('amount', 'decimal', aggregatable=True)
|
64
|
+
schema.add_field('status', 'string')
|
65
|
+
schema.set_monthly_unique(True)
|
66
|
+
|
67
|
+
# 生成特征SQL
|
68
|
+
generator = FeatureGenerator(schema)
|
69
|
+
sql = generator.generate_spark_sql()
|
70
|
+
print(sql)
|
71
|
+
```
|
72
|
+
|
73
|
+
## 📖 主要功能
|
74
|
+
|
75
|
+
### 1. Date工具 - 智能格式记忆
|
76
|
+
Date类会根据输入格式自动设置默认输出格式:
|
77
|
+
|
78
|
+
| 输入方式 | 默认输出 | 说明 |
|
79
|
+
|---------|---------|------|
|
80
|
+
| `Date('202504')` | `202504` | 年月紧凑格式 |
|
81
|
+
| `Date('20250415')` | `20250415` | 完整紧凑格式 |
|
82
|
+
| `Date(2025, 4)` | `2025-04` | 年月格式 |
|
83
|
+
| `Date(2025, 4, 15)` | `2025-04-15` | 完整格式 |
|
84
|
+
|
85
|
+
### 2. SQL工具 - 特征工程SQL生成
|
86
|
+
基于表结构自动生成数据分析SQL,支持:
|
87
|
+
|
88
|
+
- **原始字段拷贝**:非聚合字段的智能拷贝
|
89
|
+
- **聚合统计**:sum/avg/min/max/count/variance/stddev
|
90
|
+
- **环比特征**:月度差分对比(MoM)
|
91
|
+
- **同比特征**:年度差分对比(YoY)
|
92
|
+
- **Spark SQL**:生成优化的Spark SQL代码
|
93
|
+
|
94
|
+
```python
|
95
|
+
# 特征生成配置
|
96
|
+
from staran.sql import FeatureConfig
|
97
|
+
|
98
|
+
config = FeatureConfig()
|
99
|
+
config.set_aggregation_types(['sum', 'avg', 'max'])
|
100
|
+
config.set_mom_months([1, 3]) # 1月、3月环比
|
101
|
+
|
102
|
+
generator = FeatureGenerator(schema, config)
|
103
|
+
generator.print_feature_summary() # 查看特征统计
|
104
|
+
```
|
105
|
+
|
106
|
+
### 3. 多种输出格式(Date工具)
|
107
|
+
```python
|
108
|
+
date = Date('202504')
|
109
|
+
|
110
|
+
# 默认格式(保持输入风格)
|
111
|
+
print(date) # 202504
|
112
|
+
|
113
|
+
# 常用格式
|
114
|
+
print(date.format_full()) # 2025-04-01
|
115
|
+
print(date.format_chinese()) # 2025年04月01日
|
116
|
+
print(date.format_year_month()) # 2025-04
|
117
|
+
print(date.format_compact()) # 20250401
|
118
|
+
```
|
119
|
+
|
120
|
+
### 4. 日期运算
|
121
|
+
```python
|
122
|
+
date = Date('202504')
|
123
|
+
|
124
|
+
# 运算后保持原格式
|
125
|
+
next_month = date.add_months(1) # 202505
|
126
|
+
tomorrow = date.add_days(1) # 202504 (智能处理)
|
127
|
+
|
128
|
+
# 日期差计算
|
129
|
+
diff = date.difference(Date('202502')) # 天数差
|
130
|
+
```
|
131
|
+
|
132
|
+
## 🎯 设计特色
|
133
|
+
|
134
|
+
- **格式智能** - 自动记忆输入格式,保持输出一致性
|
135
|
+
- **零依赖** - 仅基于Python标准库
|
136
|
+
- **直观API** - 符合Python习惯的设计
|
137
|
+
- **类型安全** - 完整的参数验证和错误处理
|
138
|
+
- **代码生成** - 智能SQL特征工程代码生成
|
139
|
+
|
140
|
+
## 📁 项目结构
|
141
|
+
|
142
|
+
```
|
143
|
+
staran/
|
144
|
+
├── __init__.py # 主包入口,包含使用示例
|
145
|
+
├── tools/
|
146
|
+
│ ├── __init__.py # 工具模块
|
147
|
+
│ └── date.py # Date类实现
|
148
|
+
├── sql/
|
149
|
+
│ ├── __init__.py # SQL模块
|
150
|
+
│ ├── schema.py # 表结构定义
|
151
|
+
│ ├── generator.py # 特征生成器
|
152
|
+
│ └── engines.py # SQL引擎(Spark等)
|
153
|
+
├── setup.py # 安装配置
|
154
|
+
├── README.md # 本文档
|
155
|
+
└── SQL_GUIDE.md # SQL工具详细指南
|
156
|
+
```
|
157
|
+
|
158
|
+
## 🧪 快速测试
|
159
|
+
|
160
|
+
### Date工具测试
|
161
|
+
```python
|
162
|
+
from staran import Date
|
163
|
+
|
164
|
+
# 测试格式记忆
|
165
|
+
date = Date('202504')
|
166
|
+
print(f"原始: {date}") # 202504
|
167
|
+
print(f"加2月: {date.add_months(2)}") # 202506
|
168
|
+
|
169
|
+
# 测试多格式输出
|
170
|
+
print(f"中文: {date.format_chinese()}") # 2025年04月01日
|
171
|
+
print(f"完整: {date.format_full()}") # 2025-04-01
|
172
|
+
```
|
173
|
+
|
174
|
+
### SQL工具测试
|
175
|
+
```python
|
176
|
+
from staran import TableSchema, FeatureGenerator
|
177
|
+
|
178
|
+
# 定义简单表结构
|
179
|
+
schema = TableSchema('user_stats')
|
180
|
+
schema.add_primary_key('user_id', 'string')
|
181
|
+
schema.add_date_field('date', 'date')
|
182
|
+
schema.add_field('amount', 'decimal', aggregatable=True)
|
183
|
+
schema.set_monthly_unique(True)
|
184
|
+
|
185
|
+
# 生成并查看特征
|
186
|
+
generator = FeatureGenerator(schema)
|
187
|
+
print(f"生成特征数: {generator.get_feature_summary()['total']}")
|
188
|
+
print(generator.generate_spark_sql())
|
189
|
+
```
|
190
|
+
|
191
|
+
## 📄 许可证
|
192
|
+
|
193
|
+
MIT License
|
194
|
+
|
195
|
+
---
|
196
|
+
|
197
|
+
**Staran** - 让Python工具使用更简单 🌟
|
@@ -0,0 +1,8 @@
|
|
1
|
+
staran/__init__.py,sha256=J-w06e5VGb5hGb7FLk4L869rFjhaNn6eGBJsT4V_f70,5046
|
2
|
+
staran/tools/__init__.py,sha256=KtudrYnxKD9HZEL4H-mrWlKrmsI3rYjJrLeC9YDTpG4,1054
|
3
|
+
staran/tools/date.py,sha256=-QyEMWVx6czMuOIwcV7kR3gBMRVOwb5qevo7GEFSJKE,10488
|
4
|
+
staran-0.2.1.dist-info/licenses/LICENSE,sha256=2EmsBIyDCono4iVXNpv5_px9qt2b7hfPq1WuyGVMNP4,1361
|
5
|
+
staran-0.2.1.dist-info/METADATA,sha256=FhdKvyXGUxK0Bw4PZu7xvM-LQvYC10Sf6CnDbesd1eI,5331
|
6
|
+
staran-0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
staran-0.2.1.dist-info/top_level.txt,sha256=NOUZtXSh5oSIEjHrC0lQ9WmoKtD010Q00dghWyag-Zs,7
|
8
|
+
staran-0.2.1.dist-info/RECORD,,
|
staran-0.2.0.dist-info/METADATA
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: staran
|
3
|
-
Version: 0.2.0
|
4
|
-
Summary: staran - 高性能Python工具库
|
5
|
-
Home-page: https://github.com/starlxa/staran
|
6
|
-
Author: StarAn
|
7
|
-
Author-email: starlxa@icloud.com
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
10
|
-
Requires-Python: >=3.7
|
11
|
-
Description-Content-Type: text/markdown
|
12
|
-
License-File: LICENSE
|
13
|
-
Requires-Dist: datetime
|
14
|
-
Requires-Dist: calendar
|
15
|
-
Requires-Dist: re
|
16
|
-
Dynamic: author
|
17
|
-
Dynamic: author-email
|
18
|
-
Dynamic: classifier
|
19
|
-
Dynamic: description-content-type
|
20
|
-
Dynamic: home-page
|
21
|
-
Dynamic: license-file
|
22
|
-
Dynamic: requires-dist
|
23
|
-
Dynamic: requires-python
|
24
|
-
Dynamic: summary
|
staran-0.2.0.dist-info/RECORD
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
staran/__init__.py,sha256=FdJTZ11EB1R2z70W8FsCSgudpbPE68rMEud19pp8VsU,5045
|
2
|
-
staran/tools/__init__.py,sha256=KtudrYnxKD9HZEL4H-mrWlKrmsI3rYjJrLeC9YDTpG4,1054
|
3
|
-
staran/tools/date.py,sha256=-QyEMWVx6czMuOIwcV7kR3gBMRVOwb5qevo7GEFSJKE,10488
|
4
|
-
staran-0.2.0.dist-info/licenses/LICENSE,sha256=2EmsBIyDCono4iVXNpv5_px9qt2b7hfPq1WuyGVMNP4,1361
|
5
|
-
staran-0.2.0.dist-info/METADATA,sha256=ReWJRHI_LYkUc4YWsBTsX2cqCA3XKyJgtm65jAPLjOI,634
|
6
|
-
staran-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
-
staran-0.2.0.dist-info/top_level.txt,sha256=NOUZtXSh5oSIEjHrC0lQ9WmoKtD010Q00dghWyag-Zs,7
|
8
|
-
staran-0.2.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|