staran 0.1.3__tar.gz → 0.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: staran
3
- Version: 0.1.3
3
+ Version: 0.2.1
4
4
  Summary: staran - 高性能Python工具库
5
5
  Home-page: https://github.com/starlxa/staran
6
6
  Author: StarAn
@@ -26,9 +26,9 @@ Dynamic: summary
26
26
 
27
27
  # Staran - 简化的Python工具库
28
28
 
29
- ## 轻量级Python实用工具集
29
+ ## 📦 轻量级Python实用工具集
30
30
 
31
- Staran是一个基于Python标准库的实用工具库,提供日期处理等常用功能,无需复杂依赖。
31
+ Staran是一个基于Python标准库的实用工具库,提供日期处理、SQL生成等常用功能,无需复杂依赖。
32
32
 
33
33
  ## 🚀 快速开始
34
34
 
@@ -37,7 +37,7 @@ Staran是一个基于Python标准库的实用工具库,提供日期处理等
37
37
  pip install staran
38
38
  ```
39
39
 
40
- ### 基本使用
40
+ ### Date工具 - 智能日期处理
41
41
 
42
42
  ```python
43
43
  from staran import Date
@@ -51,9 +51,28 @@ date3 = Date(2025, 4, 15) # 输出: 2025-04-15
51
51
  new_date = date1.add_months(2) # 输出: 202506 (保持YYYYMM格式)
52
52
  ```
53
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
+
54
73
  ## 📖 主要功能
55
74
 
56
- ### 1. 智能格式记忆
75
+ ### 1. Date工具 - 智能格式记忆
57
76
  Date类会根据输入格式自动设置默认输出格式:
58
77
 
59
78
  | 输入方式 | 默认输出 | 说明 |
@@ -63,7 +82,28 @@ Date类会根据输入格式自动设置默认输出格式:
63
82
  | `Date(2025, 4)` | `2025-04` | 年月格式 |
64
83
  | `Date(2025, 4, 15)` | `2025-04-15` | 完整格式 |
65
84
 
66
- ### 2. 多种输出格式
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工具)
67
107
  ```python
68
108
  date = Date('202504')
69
109
 
@@ -77,7 +117,7 @@ print(date.format_year_month()) # 2025-04
77
117
  print(date.format_compact()) # 20250401
78
118
  ```
79
119
 
80
- ### 3. 日期运算
120
+ ### 4. 日期运算
81
121
  ```python
82
122
  date = Date('202504')
83
123
 
@@ -89,20 +129,13 @@ tomorrow = date.add_days(1) # 202504 (智能处理)
89
129
  diff = date.difference(Date('202502')) # 天数差
90
130
  ```
91
131
 
92
- ### 4. 基本信息
93
- ```python
94
- date = Date(2024, 2, 29)
95
- print(date.is_leap_year()) # True
96
- print(date.weekday()) # 星期几
97
- print(date.days_in_month()) # 当月天数
98
- ```
99
-
100
132
  ## 🎯 设计特色
101
133
 
102
134
  - **格式智能** - 自动记忆输入格式,保持输出一致性
103
135
  - **零依赖** - 仅基于Python标准库
104
136
  - **直观API** - 符合Python习惯的设计
105
137
  - **类型安全** - 完整的参数验证和错误处理
138
+ - **代码生成** - 智能SQL特征工程代码生成
106
139
 
107
140
  ## 📁 项目结构
108
141
 
@@ -112,12 +145,19 @@ staran/
112
145
  ├── tools/
113
146
  │ ├── __init__.py # 工具模块
114
147
  │ └── date.py # Date类实现
148
+ ├── sql/
149
+ │ ├── __init__.py # SQL模块
150
+ │ ├── schema.py # 表结构定义
151
+ │ ├── generator.py # 特征生成器
152
+ │ └── engines.py # SQL引擎(Spark等)
115
153
  ├── setup.py # 安装配置
116
- └── README.md # 本文档
154
+ ├── README.md # 本文档
155
+ └── SQL_GUIDE.md # SQL工具详细指南
117
156
  ```
118
157
 
119
158
  ## 🧪 快速测试
120
159
 
160
+ ### Date工具测试
121
161
  ```python
122
162
  from staran import Date
123
163
 
@@ -131,6 +171,23 @@ print(f"中文: {date.format_chinese()}") # 2025年04月01日
131
171
  print(f"完整: {date.format_full()}") # 2025-04-01
132
172
  ```
133
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
+
134
191
  ## 📄 许可证
135
192
 
136
193
  MIT License
@@ -1,8 +1,8 @@
1
1
  # Staran - 简化的Python工具库
2
2
 
3
- ## 轻量级Python实用工具集
3
+ ## 📦 轻量级Python实用工具集
4
4
 
5
- Staran是一个基于Python标准库的实用工具库,提供日期处理等常用功能,无需复杂依赖。
5
+ Staran是一个基于Python标准库的实用工具库,提供日期处理、SQL生成等常用功能,无需复杂依赖。
6
6
 
7
7
  ## 🚀 快速开始
8
8
 
@@ -11,7 +11,7 @@ Staran是一个基于Python标准库的实用工具库,提供日期处理等
11
11
  pip install staran
12
12
  ```
13
13
 
14
- ### 基本使用
14
+ ### Date工具 - 智能日期处理
15
15
 
16
16
  ```python
17
17
  from staran import Date
@@ -25,9 +25,28 @@ date3 = Date(2025, 4, 15) # 输出: 2025-04-15
25
25
  new_date = date1.add_months(2) # 输出: 202506 (保持YYYYMM格式)
26
26
  ```
27
27
 
28
+ ### SQL工具 - 数据分析SQL生成
29
+
30
+ ```python
31
+ from staran import TableSchema, FeatureGenerator
32
+
33
+ # 定义表结构
34
+ schema = TableSchema('user_behavior')
35
+ schema.add_primary_key('user_id', 'string')
36
+ schema.add_date_field('date', 'date')
37
+ schema.add_field('amount', 'decimal', aggregatable=True)
38
+ schema.add_field('status', 'string')
39
+ schema.set_monthly_unique(True)
40
+
41
+ # 生成特征SQL
42
+ generator = FeatureGenerator(schema)
43
+ sql = generator.generate_spark_sql()
44
+ print(sql)
45
+ ```
46
+
28
47
  ## 📖 主要功能
29
48
 
30
- ### 1. 智能格式记忆
49
+ ### 1. Date工具 - 智能格式记忆
31
50
  Date类会根据输入格式自动设置默认输出格式:
32
51
 
33
52
  | 输入方式 | 默认输出 | 说明 |
@@ -37,7 +56,28 @@ Date类会根据输入格式自动设置默认输出格式:
37
56
  | `Date(2025, 4)` | `2025-04` | 年月格式 |
38
57
  | `Date(2025, 4, 15)` | `2025-04-15` | 完整格式 |
39
58
 
40
- ### 2. 多种输出格式
59
+ ### 2. SQL工具 - 特征工程SQL生成
60
+ 基于表结构自动生成数据分析SQL,支持:
61
+
62
+ - **原始字段拷贝**:非聚合字段的智能拷贝
63
+ - **聚合统计**:sum/avg/min/max/count/variance/stddev
64
+ - **环比特征**:月度差分对比(MoM)
65
+ - **同比特征**:年度差分对比(YoY)
66
+ - **Spark SQL**:生成优化的Spark SQL代码
67
+
68
+ ```python
69
+ # 特征生成配置
70
+ from staran.sql import FeatureConfig
71
+
72
+ config = FeatureConfig()
73
+ config.set_aggregation_types(['sum', 'avg', 'max'])
74
+ config.set_mom_months([1, 3]) # 1月、3月环比
75
+
76
+ generator = FeatureGenerator(schema, config)
77
+ generator.print_feature_summary() # 查看特征统计
78
+ ```
79
+
80
+ ### 3. 多种输出格式(Date工具)
41
81
  ```python
42
82
  date = Date('202504')
43
83
 
@@ -51,7 +91,7 @@ print(date.format_year_month()) # 2025-04
51
91
  print(date.format_compact()) # 20250401
52
92
  ```
53
93
 
54
- ### 3. 日期运算
94
+ ### 4. 日期运算
55
95
  ```python
56
96
  date = Date('202504')
57
97
 
@@ -63,20 +103,13 @@ tomorrow = date.add_days(1) # 202504 (智能处理)
63
103
  diff = date.difference(Date('202502')) # 天数差
64
104
  ```
65
105
 
66
- ### 4. 基本信息
67
- ```python
68
- date = Date(2024, 2, 29)
69
- print(date.is_leap_year()) # True
70
- print(date.weekday()) # 星期几
71
- print(date.days_in_month()) # 当月天数
72
- ```
73
-
74
106
  ## 🎯 设计特色
75
107
 
76
108
  - **格式智能** - 自动记忆输入格式,保持输出一致性
77
109
  - **零依赖** - 仅基于Python标准库
78
110
  - **直观API** - 符合Python习惯的设计
79
111
  - **类型安全** - 完整的参数验证和错误处理
112
+ - **代码生成** - 智能SQL特征工程代码生成
80
113
 
81
114
  ## 📁 项目结构
82
115
 
@@ -86,12 +119,19 @@ staran/
86
119
  ├── tools/
87
120
  │ ├── __init__.py # 工具模块
88
121
  │ └── date.py # Date类实现
122
+ ├── sql/
123
+ │ ├── __init__.py # SQL模块
124
+ │ ├── schema.py # 表结构定义
125
+ │ ├── generator.py # 特征生成器
126
+ │ └── engines.py # SQL引擎(Spark等)
89
127
  ├── setup.py # 安装配置
90
- └── README.md # 本文档
128
+ ├── README.md # 本文档
129
+ └── SQL_GUIDE.md # SQL工具详细指南
91
130
  ```
92
131
 
93
132
  ## 🧪 快速测试
94
133
 
134
+ ### Date工具测试
95
135
  ```python
96
136
  from staran import Date
97
137
 
@@ -105,6 +145,23 @@ print(f"中文: {date.format_chinese()}") # 2025年04月01日
105
145
  print(f"完整: {date.format_full()}") # 2025-04-01
106
146
  ```
107
147
 
148
+ ### SQL工具测试
149
+ ```python
150
+ from staran import TableSchema, FeatureGenerator
151
+
152
+ # 定义简单表结构
153
+ schema = TableSchema('user_stats')
154
+ schema.add_primary_key('user_id', 'string')
155
+ schema.add_date_field('date', 'date')
156
+ schema.add_field('amount', 'decimal', aggregatable=True)
157
+ schema.set_monthly_unique(True)
158
+
159
+ # 生成并查看特征
160
+ generator = FeatureGenerator(schema)
161
+ print(f"生成特征数: {generator.get_feature_summary()['total']}")
162
+ print(generator.generate_spark_sql())
163
+ ```
164
+
108
165
  ## 📄 许可证
109
166
 
110
167
  MIT License
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='staran',
5
- version='0.1.3',
5
+ version='0.2.1',
6
6
  description='staran - 高性能Python工具库',
7
7
  long_description=open('README.md', encoding='utf-8').read(),
8
8
  long_description_content_type='text/markdown',
@@ -5,7 +5,7 @@
5
5
  Staran - 简化的Python工具库
6
6
  =========================
7
7
 
8
- 基于Python标准库的轻量级实用工具集,提供日期处理等常用功能。
8
+ 基于Python标准库的轻量级实用工具集,提供日期处理、SQL生成等常用功能。
9
9
 
10
10
  主要特性:
11
11
  - 零依赖:仅基于Python标准库
@@ -13,10 +13,16 @@ Staran - 简化的Python工具库
13
13
  - 直观API:符合Python习惯的设计
14
14
  - 类型安全:完整的参数验证
15
15
 
16
+ 工具模块:
17
+ ---------
18
+ 1. Date工具 - 智能日期处理
19
+ 2. SQL工具 - 数据分析SQL生成
20
+
21
+
16
22
  快速开始:
17
23
  ---------
18
24
 
19
- 基本用法::
25
+ Date工具基本用法::
20
26
 
21
27
  from staran import Date
22
28
 
@@ -28,6 +34,23 @@ Staran - 简化的Python工具库
28
34
  # 格式保持
29
35
  new_date = date1.add_months(2) # 输出: 202506 (保持原格式)
30
36
 
37
+ SQL工具基本用法::
38
+
39
+ from staran import TableSchema, FeatureGenerator
40
+
41
+ # 定义表结构
42
+ schema = TableSchema('user_behavior')
43
+ schema.add_primary_key('user_id', 'string')
44
+ schema.add_date_field('date', 'date')
45
+ schema.add_field('amount', 'decimal', aggregatable=True)
46
+ schema.add_field('status', 'string')
47
+ schema.set_monthly_unique(True)
48
+
49
+ # 生成特征SQL
50
+ generator = FeatureGenerator(schema)
51
+ sql = generator.generate_spark_sql()
52
+ print(sql)
53
+
31
54
  多种输出格式::
32
55
 
33
56
  date = Date('202504')
@@ -37,6 +60,18 @@ Staran - 简化的Python工具库
37
60
  print(date.format_chinese()) # 2025年04月01日
38
61
  print(date.format_compact()) # 20250401
39
62
 
63
+ SQL特征生成::
64
+
65
+ # 配置特征生成
66
+ from staran.sql import FeatureConfig
67
+
68
+ config = FeatureConfig()
69
+ config.set_aggregation_types(['sum', 'avg', 'max'])
70
+ config.set_mom_months([1, 3]) # 1个月、3个月环比
71
+
72
+ generator = FeatureGenerator(schema, config)
73
+ generator.print_feature_summary()
74
+
40
75
  日期运算::
41
76
 
42
77
  date = Date(2025, 4, 15)
@@ -73,6 +108,7 @@ Staran - 简化的Python工具库
73
108
 
74
109
  核心功能:
75
110
  ---------
111
+ Date工具:
76
112
  - Date: 智能日期类,支持格式记忆和多种输出
77
113
  - 日期运算:add_days(), add_months()
78
114
  - 格式化:多种预设格式方法
@@ -80,6 +116,13 @@ Staran - 简化的Python工具库
80
116
  - 转换:to_timestamp(), to_date(), to_datetime()
81
117
  - 信息:is_leap_year(), weekday(), days_in_month()
82
118
 
119
+ SQL工具:
120
+ - TableSchema: 表结构定义,支持字段类型和特性配置
121
+ - FeatureGenerator: 特征生成器,支持聚合、环比、同比特征
122
+ - SparkSQLGenerator: Spark SQL代码生成
123
+ - 支持每人每月唯一数据的特征工程
124
+ - 可配置的聚合类型和时间窗口
125
+
83
126
  版本信息:
84
127
  ---------
85
128
  - 版本: 1.0.0
@@ -89,10 +132,14 @@ Staran - 简化的Python工具库
89
132
 
90
133
  # 导入主要功能
91
134
  from .tools import Date
135
+ from .sql import TableSchema, FeatureGenerator, SparkSQLGenerator
92
136
 
93
137
  # 主要导出
94
138
  __all__ = [
95
- 'Date'
139
+ 'Date',
140
+ 'TableSchema',
141
+ 'FeatureGenerator',
142
+ 'SparkSQLGenerator'
96
143
  ]
97
144
 
98
145
  # 包信息
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: staran
3
- Version: 0.1.3
3
+ Version: 0.2.1
4
4
  Summary: staran - 高性能Python工具库
5
5
  Home-page: https://github.com/starlxa/staran
6
6
  Author: StarAn
@@ -26,9 +26,9 @@ Dynamic: summary
26
26
 
27
27
  # Staran - 简化的Python工具库
28
28
 
29
- ## 轻量级Python实用工具集
29
+ ## 📦 轻量级Python实用工具集
30
30
 
31
- Staran是一个基于Python标准库的实用工具库,提供日期处理等常用功能,无需复杂依赖。
31
+ Staran是一个基于Python标准库的实用工具库,提供日期处理、SQL生成等常用功能,无需复杂依赖。
32
32
 
33
33
  ## 🚀 快速开始
34
34
 
@@ -37,7 +37,7 @@ Staran是一个基于Python标准库的实用工具库,提供日期处理等
37
37
  pip install staran
38
38
  ```
39
39
 
40
- ### 基本使用
40
+ ### Date工具 - 智能日期处理
41
41
 
42
42
  ```python
43
43
  from staran import Date
@@ -51,9 +51,28 @@ date3 = Date(2025, 4, 15) # 输出: 2025-04-15
51
51
  new_date = date1.add_months(2) # 输出: 202506 (保持YYYYMM格式)
52
52
  ```
53
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
+
54
73
  ## 📖 主要功能
55
74
 
56
- ### 1. 智能格式记忆
75
+ ### 1. Date工具 - 智能格式记忆
57
76
  Date类会根据输入格式自动设置默认输出格式:
58
77
 
59
78
  | 输入方式 | 默认输出 | 说明 |
@@ -63,7 +82,28 @@ Date类会根据输入格式自动设置默认输出格式:
63
82
  | `Date(2025, 4)` | `2025-04` | 年月格式 |
64
83
  | `Date(2025, 4, 15)` | `2025-04-15` | 完整格式 |
65
84
 
66
- ### 2. 多种输出格式
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工具)
67
107
  ```python
68
108
  date = Date('202504')
69
109
 
@@ -77,7 +117,7 @@ print(date.format_year_month()) # 2025-04
77
117
  print(date.format_compact()) # 20250401
78
118
  ```
79
119
 
80
- ### 3. 日期运算
120
+ ### 4. 日期运算
81
121
  ```python
82
122
  date = Date('202504')
83
123
 
@@ -89,20 +129,13 @@ tomorrow = date.add_days(1) # 202504 (智能处理)
89
129
  diff = date.difference(Date('202502')) # 天数差
90
130
  ```
91
131
 
92
- ### 4. 基本信息
93
- ```python
94
- date = Date(2024, 2, 29)
95
- print(date.is_leap_year()) # True
96
- print(date.weekday()) # 星期几
97
- print(date.days_in_month()) # 当月天数
98
- ```
99
-
100
132
  ## 🎯 设计特色
101
133
 
102
134
  - **格式智能** - 自动记忆输入格式,保持输出一致性
103
135
  - **零依赖** - 仅基于Python标准库
104
136
  - **直观API** - 符合Python习惯的设计
105
137
  - **类型安全** - 完整的参数验证和错误处理
138
+ - **代码生成** - 智能SQL特征工程代码生成
106
139
 
107
140
  ## 📁 项目结构
108
141
 
@@ -112,12 +145,19 @@ staran/
112
145
  ├── tools/
113
146
  │ ├── __init__.py # 工具模块
114
147
  │ └── date.py # Date类实现
148
+ ├── sql/
149
+ │ ├── __init__.py # SQL模块
150
+ │ ├── schema.py # 表结构定义
151
+ │ ├── generator.py # 特征生成器
152
+ │ └── engines.py # SQL引擎(Spark等)
115
153
  ├── setup.py # 安装配置
116
- └── README.md # 本文档
154
+ ├── README.md # 本文档
155
+ └── SQL_GUIDE.md # SQL工具详细指南
117
156
  ```
118
157
 
119
158
  ## 🧪 快速测试
120
159
 
160
+ ### Date工具测试
121
161
  ```python
122
162
  from staran import Date
123
163
 
@@ -131,6 +171,23 @@ print(f"中文: {date.format_chinese()}") # 2025年04月01日
131
171
  print(f"完整: {date.format_full()}") # 2025-04-01
132
172
  ```
133
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
+
134
191
  ## 📄 许可证
135
192
 
136
193
  MIT License
File without changes
File without changes
File without changes
File without changes