staran 0.2.4__tar.gz → 0.4.0__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.
Files changed (31) hide show
  1. {staran-0.2.4/staran.egg-info → staran-0.4.0}/PKG-INFO +151 -33
  2. {staran-0.2.4 → staran-0.4.0}/README.md +150 -32
  3. staran-0.4.0/setup.py +31 -0
  4. {staran-0.2.4 → staran-0.4.0}/staran/__init__.py +24 -9
  5. staran-0.4.0/staran/engines/__init__.py +65 -0
  6. staran-0.4.0/staran/engines/base.py +255 -0
  7. staran-0.4.0/staran/engines/hive.py +163 -0
  8. staran-0.4.0/staran/engines/spark.py +252 -0
  9. staran-0.4.0/staran/engines/turing.py +439 -0
  10. staran-0.4.0/staran/examples/__init__.py +8 -0
  11. staran-0.4.0/staran/examples/aum_longtail.py +250 -0
  12. staran-0.4.0/staran/examples/aum_longtail_old.py +487 -0
  13. staran-0.4.0/staran/features/__init__.py +59 -0
  14. staran-0.4.0/staran/features/engines.py +284 -0
  15. staran-0.4.0/staran/features/generator.py +603 -0
  16. staran-0.4.0/staran/features/manager.py +155 -0
  17. staran-0.4.0/staran/features/schema.py +193 -0
  18. staran-0.4.0/staran/schemas/__init__.py +28 -0
  19. staran-0.4.0/staran/schemas/aum/__init__.py +314 -0
  20. staran-0.4.0/staran/schemas/document_generator.py +337 -0
  21. {staran-0.2.4 → staran-0.4.0/staran.egg-info}/PKG-INFO +151 -33
  22. staran-0.4.0/staran.egg-info/SOURCES.txt +27 -0
  23. staran-0.2.4/setup.py +0 -23
  24. staran-0.2.4/staran.egg-info/SOURCES.txt +0 -11
  25. {staran-0.2.4 → staran-0.4.0}/LICENSE +0 -0
  26. {staran-0.2.4 → staran-0.4.0}/setup.cfg +0 -0
  27. {staran-0.2.4 → staran-0.4.0}/staran/tools/__init__.py +0 -0
  28. {staran-0.2.4 → staran-0.4.0}/staran/tools/date.py +0 -0
  29. {staran-0.2.4 → staran-0.4.0}/staran.egg-info/dependency_links.txt +0 -0
  30. {staran-0.2.4 → staran-0.4.0}/staran.egg-info/requires.txt +0 -0
  31. {staran-0.2.4 → staran-0.4.0}/staran.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: staran
3
- Version: 0.2.4
3
+ Version: 0.4.0
4
4
  Summary: staran - 高性能Python工具库
5
5
  Home-page: https://github.com/starlxa/staran
6
6
  Author: StarAn
@@ -24,13 +24,25 @@ Dynamic: requires-dist
24
24
  Dynamic: requires-python
25
25
  Dynamic: summary
26
26
 
27
- # Staran - 智能特征工程工具包
27
+ # Star## v0.4.0 新特性
28
+
29
+ - 📋 **独立Schema模块** - 专门的表结构定义和管理模块
30
+ - 📄 **文档自动生成** - 支持Markdown/PDF/HTML格式的技术文档生成
31
+ - 🏢 **业务域支持** - AUM等业务领域的标准表结构定义
32
+ - 🔗 **无缝集成** - Schema与特征工程examples模块完美集成
33
+ - 🛠️ **模块化引擎架构** - 独立的引擎模块,支持Spark、Hive、图灵平台
34
+ - 🔧 **统一接口设计** - 所有引擎提供一致的SQL生成、执行和下载接口
35
+ - 🎯 **继承复用架构** - TuringEngine继承SparkEngine,复用SQL生成逻辑
36
+ - 📦 **清晰代码分离** - SQL生成与平台特定执行逻辑完全分离
37
+ - 🚀 **易于扩展** - 新增数据库支持只需实现BaseEngine接口
38
+ - 📁 **独立引擎存储** - engines/文件夹专门存放所有数据库引擎
39
+ - 🔄 **向后兼容** - 保持对原有API的完全兼容工程工具包
28
40
 
29
41
  ## � 专为机器学习设计的Python工具包
30
42
 
31
43
  Staran是一个强大的特征工程和数据处理工具包,提供从数据到模型的完整解决方案。特别针对工银图灵平台优化,让特征工程和模型训练变得前所未有的简单。
32
44
 
33
- ## ✨ v0.2.4 新特性
45
+ ## ✨ v0.4.0 新特性
34
46
 
35
47
  - �️ **模块化引擎架构** - 独立的引擎模块,支持Spark、Hive、图灵平台
36
48
  - 🔧 **统一接口设计** - 所有引擎提供一致的SQL生成、执行和下载接口
@@ -82,6 +94,40 @@ result = turing_engine.create_table('my_table', sql, execute=True)
82
94
  download = turing_engine.download_table_data('my_table', 'file:///nfsHome/data.parquet')
83
95
  ```
84
96
 
97
+ ### Schema模块 - 表结构管理与文档生成
98
+
99
+ ```python
100
+ from staran import get_aum_schemas, export_aum_docs, SchemaDocumentGenerator
101
+
102
+ # 1. 获取预定义业务表结构
103
+ schemas = get_aum_schemas() # 获取AUM业务域的所有表结构
104
+
105
+ for table_type, schema in schemas.items():
106
+ print(f"{table_type}: {schema.table_name} ({len(schema.fields)}个字段)")
107
+
108
+ # 2. 生成业务文档
109
+ docs = export_aum_docs('./docs', 'markdown') # 生成Markdown格式文档
110
+
111
+ # 3. 自定义文档生成
112
+ generator = SchemaDocumentGenerator()
113
+ doc_path = generator.export_schema_doc(
114
+ schema=schemas['behavior'],
115
+ business_domain="AUM",
116
+ table_type="behavior",
117
+ format_type="markdown"
118
+ )
119
+
120
+ # 4. 与特征工程集成
121
+ from staran import create_aum_example, run_aum_example
122
+
123
+ # 基于预定义schema创建特征工程示例
124
+ example = create_aum_example()
125
+ summary = example.get_summary() # 获取特征统计信息
126
+
127
+ # 一键运行完整流程
128
+ results = run_aum_example('202507') # 生成916个特征
129
+ ```
130
+
85
131
  ### 特征工程 - SQL自动生成
86
132
 
87
133
  ```python
@@ -315,7 +361,12 @@ tomorrow = date.add_days(1) # 202504 (智能处理)
315
361
 
316
362
  ```
317
363
  staran/
318
- ├── __init__.py # 主包入口,v0.2.4功能导出
364
+ ├── __init__.py # 主包入口,v0.4.0功能导出
365
+ ├── schemas/ # 🆕 表结构定义与文档生成模块
366
+ │ ├── __init__.py # Schema模块入口
367
+ │ ├── document_generator.py # 文档生成器 (MD/PDF/HTML)
368
+ │ └── aum/ # AUM业务域表结构
369
+ │ └── __init__.py # AUM表结构定义
319
370
  ├── engines/ # 🆕 模块化引擎架构
320
371
  │ ├── __init__.py # 引擎模块入口
321
372
  │ ├── base.py # BaseEngine抽象基类
@@ -327,11 +378,14 @@ staran/
327
378
  │ ├── manager.py # FeatureManager (使用引擎架构)
328
379
  │ ├── schema.py # 表结构定义
329
380
  │ └── generator.py # 特征生成器
381
+ ├── examples/ # 🆕 完整示例模块
382
+ │ ├── __init__.py # 示例模块入口
383
+ │ └── aum_longtail.py # AUM代发长尾模型示例
330
384
  ├── tools/
331
385
  │ ├── __init__.py # 工具模块
332
386
  │ └── date.py # Date类实现
333
387
  ├── setup.py # 安装配置
334
- ├── README.md # 本文档 v0.2.4
388
+ ├── README.md # 本文档 v0.4.0
335
389
  └── quick-upload.sh # 快速部署脚本
336
390
  ```
337
391
 
@@ -355,27 +409,26 @@ sql = turing.generate_sql("SELECT user_id, amount FROM users", {"table": "test"}
355
409
  print(f"SQL生成测试: {'success' if sql else 'failed'}")
356
410
  ```
357
411
 
358
- ### 特征工程测试
412
+ ### AUM示例测试
359
413
  ```python
360
- from staran import TableSchema, FeatureManager
414
+ from staran import create_aum_example
361
415
 
362
- # 定义表结构
363
- schema = TableSchema('user_stats')
364
- schema.add_primary_key('user_id', 'string')
365
- schema.add_date_field('date', 'date')
366
- schema.add_field('amount', 'decimal', aggregatable=True)
367
- schema.set_monthly_unique(True)
416
+ # 创建示例并查看摘要
417
+ example = create_aum_example("dwegdata03000")
418
+ example.print_summary()
368
419
 
369
- # 创建管理器(使用引擎架构)
370
- manager = FeatureManager(engine_type='spark', database='analytics_db')
420
+ # 快速运行(测试模式,不执行实际SQL)
421
+ print("🎯 AUM长尾模型示例已准备就绪")
422
+ print("📊 包含4张业务表的完整特征工程流程")
423
+ ```
371
424
 
372
- # 生成特征并查看摘要
373
- summary = manager.get_feature_summary(schema)
374
- print(f"生成特征数: {summary['total']}")
425
+ ### 一键运行示例
426
+ ```python
427
+ from staran import run_aum_example
375
428
 
376
- # 生成聚合特征SQL
377
- result = manager.generate_feature_by_type(schema, 'aggregation', 2025, 7)
378
- print("SQL长度:", len(result['sql']))
429
+ # 最简单的使用方式
430
+ results = run_aum_example("202507") # 指定特征月份
431
+ print(f" 处理完成: {len(results)} 个表")
379
432
  ```
380
433
 
381
434
  ### Date工具测试
@@ -408,21 +461,38 @@ print(f"✅ 继承关系: 继承自{turing.__class__.__bases__[0].__name__}")
408
461
  print("🚀 环境就绪!开始特征工程之旅")
409
462
  ```
410
463
 
411
- ### 2. 完整ML流程
464
+ ### 2. 运行AUM示例
412
465
  ```python
413
- # 使用新引擎架构进行特征工程
414
- from staran import FeatureManager
415
-
416
- # 创建基于Turing引擎的特征管理器
417
- manager = FeatureManager(engine_type='turing', database='production_analytics')
466
+ # 最简单的方式 - 一行代码完成复杂特征工程
467
+ from staran import run_aum_example
418
468
 
419
- # 执行SQL并下载结果
420
- result = manager.execute_and_download(
421
- sql="SELECT user_id, features FROM ml_features WHERE dt='2025-07-28'",
422
- output_path="file:///nfsHome/ml_pipeline/"
469
+ results = run_aum_example(
470
+ feature_date="202507", # 特征月份
471
+ database="dwegdata03000", # 数据库名
472
+ output_path="file:///nfsHome/aum_features" # 输出路径
423
473
  )
424
474
 
425
- print(f"✅ 成功!使用{manager.engine.__class__.__name__}完成数据处理")
475
+ print(f"✅ 成功!处理了4张表,生成了完整的特征数据集")
476
+ print("📂 数据已保存到 /nfsHome/aum_features/ 目录")
477
+ ```
478
+
479
+ ### 3. 自定义特征工程
480
+ ```python
481
+ # 如需更多控制,使用详细API
482
+ from staran import create_aum_example
483
+
484
+ example = create_aum_example("dwegdata03000")
485
+
486
+ # 查看会生成哪些特征
487
+ example.print_summary()
488
+
489
+ # 运行特征工程
490
+ results = example.run("202507")
491
+
492
+ # 查看结果
493
+ for table_type, result in results.items():
494
+ if 'table_name' in result:
495
+ print(f"{table_type}: {result['table_name']}")
426
496
  ```
427
497
 
428
498
  ## 📊 性能优势
@@ -437,10 +507,58 @@ print(f"✅ 成功!使用{manager.engine.__class__.__name__}完成数据处理
437
507
  - **批量处理**: 并行下载和增量处理
438
508
  - **错误恢复**: 自动重试和断点续传
439
509
 
510
+ ## 🎯 完整示例
511
+
512
+ ### AUM代发长尾模型 - 简化API
513
+ 位置:`staran.examples` 模块
514
+
515
+ 基于真实金融业务场景的完整特征工程示例,展示了新的引擎架构优势:
516
+
517
+ ```python
518
+ # 最简单的使用方式
519
+ from staran import run_aum_example
520
+
521
+ # 一键运行完整特征工程流程
522
+ results = run_aum_example(
523
+ feature_date="202507", # 可选,默认当前月
524
+ database="dwegdata03000",
525
+ output_path="file:///nfsHome/aum_longtail"
526
+ )
527
+
528
+ print(f"✅ 特征工程完成!处理了 {len(results)} 个表")
529
+ ```
530
+
531
+ **更多控制的方式:**
532
+ ```python
533
+ from staran import create_aum_example
534
+
535
+ # 创建示例实例
536
+ example = create_aum_example("dwegdata03000")
537
+
538
+ # 查看特征摘要
539
+ example.print_summary()
540
+
541
+ # 运行特征工程
542
+ results = example.run("202507")
543
+ ```
544
+
545
+ **示例特点:**
546
+ - 🏦 **真实业务场景** - 4张银行核心业务表的完整处理
547
+ - 🔧 **智能特征配置** - A表(源表+聚合),其他表(全特征:环比5个月+同比1年)
548
+ - 📊 **多维度特征** - 客户行为、资产配置、交易统计、境外交易等
549
+ - 🚀 **简化API** - 一行代码完成复杂特征工程
550
+ - 📋 **完整文档** - 每个字段都有详细的业务含义说明
551
+
552
+ **数据表说明:**
553
+ - **A表** (`bi_hlwj_dfcw_f1_f4_wy`): 客户行为特征 → 仅生成原始拷贝+聚合特征
554
+ - **B表** (`bi_hlwj_zi_chan_avg_wy`): 资产平均余额 → 生成全部特征(聚合+环比5个月+同比1年)
555
+ - **C表** (`bi_hlwj_zi_chang_month_total_zb`): 月度资产配置 → 生成全部特征
556
+ - **D表** (`bi_hlwj_realy_month_stat_wy`): 月度实际统计 → 生成全部特征
557
+
440
558
  ## 📄 许可证
441
559
 
442
560
  MIT License
443
561
 
444
562
  ---
445
563
 
446
- **Staran v0.2.4** - 模块化引擎架构,让机器学习特征工程变得前所未有的简单 🌟
564
+ **Staran v0.4.0** - 模块化引擎架构,让机器学习特征工程变得前所未有的简单 🌟
@@ -1,10 +1,22 @@
1
- # Staran - 智能特征工程工具包
1
+ # Star## v0.4.0 新特性
2
+
3
+ - 📋 **独立Schema模块** - 专门的表结构定义和管理模块
4
+ - 📄 **文档自动生成** - 支持Markdown/PDF/HTML格式的技术文档生成
5
+ - 🏢 **业务域支持** - AUM等业务领域的标准表结构定义
6
+ - 🔗 **无缝集成** - Schema与特征工程examples模块完美集成
7
+ - 🛠️ **模块化引擎架构** - 独立的引擎模块,支持Spark、Hive、图灵平台
8
+ - 🔧 **统一接口设计** - 所有引擎提供一致的SQL生成、执行和下载接口
9
+ - 🎯 **继承复用架构** - TuringEngine继承SparkEngine,复用SQL生成逻辑
10
+ - 📦 **清晰代码分离** - SQL生成与平台特定执行逻辑完全分离
11
+ - 🚀 **易于扩展** - 新增数据库支持只需实现BaseEngine接口
12
+ - 📁 **独立引擎存储** - engines/文件夹专门存放所有数据库引擎
13
+ - 🔄 **向后兼容** - 保持对原有API的完全兼容工程工具包
2
14
 
3
15
  ## � 专为机器学习设计的Python工具包
4
16
 
5
17
  Staran是一个强大的特征工程和数据处理工具包,提供从数据到模型的完整解决方案。特别针对工银图灵平台优化,让特征工程和模型训练变得前所未有的简单。
6
18
 
7
- ## ✨ v0.2.4 新特性
19
+ ## ✨ v0.4.0 新特性
8
20
 
9
21
  - �️ **模块化引擎架构** - 独立的引擎模块,支持Spark、Hive、图灵平台
10
22
  - 🔧 **统一接口设计** - 所有引擎提供一致的SQL生成、执行和下载接口
@@ -56,6 +68,40 @@ result = turing_engine.create_table('my_table', sql, execute=True)
56
68
  download = turing_engine.download_table_data('my_table', 'file:///nfsHome/data.parquet')
57
69
  ```
58
70
 
71
+ ### Schema模块 - 表结构管理与文档生成
72
+
73
+ ```python
74
+ from staran import get_aum_schemas, export_aum_docs, SchemaDocumentGenerator
75
+
76
+ # 1. 获取预定义业务表结构
77
+ schemas = get_aum_schemas() # 获取AUM业务域的所有表结构
78
+
79
+ for table_type, schema in schemas.items():
80
+ print(f"{table_type}: {schema.table_name} ({len(schema.fields)}个字段)")
81
+
82
+ # 2. 生成业务文档
83
+ docs = export_aum_docs('./docs', 'markdown') # 生成Markdown格式文档
84
+
85
+ # 3. 自定义文档生成
86
+ generator = SchemaDocumentGenerator()
87
+ doc_path = generator.export_schema_doc(
88
+ schema=schemas['behavior'],
89
+ business_domain="AUM",
90
+ table_type="behavior",
91
+ format_type="markdown"
92
+ )
93
+
94
+ # 4. 与特征工程集成
95
+ from staran import create_aum_example, run_aum_example
96
+
97
+ # 基于预定义schema创建特征工程示例
98
+ example = create_aum_example()
99
+ summary = example.get_summary() # 获取特征统计信息
100
+
101
+ # 一键运行完整流程
102
+ results = run_aum_example('202507') # 生成916个特征
103
+ ```
104
+
59
105
  ### 特征工程 - SQL自动生成
60
106
 
61
107
  ```python
@@ -289,7 +335,12 @@ tomorrow = date.add_days(1) # 202504 (智能处理)
289
335
 
290
336
  ```
291
337
  staran/
292
- ├── __init__.py # 主包入口,v0.2.4功能导出
338
+ ├── __init__.py # 主包入口,v0.4.0功能导出
339
+ ├── schemas/ # 🆕 表结构定义与文档生成模块
340
+ │ ├── __init__.py # Schema模块入口
341
+ │ ├── document_generator.py # 文档生成器 (MD/PDF/HTML)
342
+ │ └── aum/ # AUM业务域表结构
343
+ │ └── __init__.py # AUM表结构定义
293
344
  ├── engines/ # 🆕 模块化引擎架构
294
345
  │ ├── __init__.py # 引擎模块入口
295
346
  │ ├── base.py # BaseEngine抽象基类
@@ -301,11 +352,14 @@ staran/
301
352
  │ ├── manager.py # FeatureManager (使用引擎架构)
302
353
  │ ├── schema.py # 表结构定义
303
354
  │ └── generator.py # 特征生成器
355
+ ├── examples/ # 🆕 完整示例模块
356
+ │ ├── __init__.py # 示例模块入口
357
+ │ └── aum_longtail.py # AUM代发长尾模型示例
304
358
  ├── tools/
305
359
  │ ├── __init__.py # 工具模块
306
360
  │ └── date.py # Date类实现
307
361
  ├── setup.py # 安装配置
308
- ├── README.md # 本文档 v0.2.4
362
+ ├── README.md # 本文档 v0.4.0
309
363
  └── quick-upload.sh # 快速部署脚本
310
364
  ```
311
365
 
@@ -329,27 +383,26 @@ sql = turing.generate_sql("SELECT user_id, amount FROM users", {"table": "test"}
329
383
  print(f"SQL生成测试: {'success' if sql else 'failed'}")
330
384
  ```
331
385
 
332
- ### 特征工程测试
386
+ ### AUM示例测试
333
387
  ```python
334
- from staran import TableSchema, FeatureManager
388
+ from staran import create_aum_example
335
389
 
336
- # 定义表结构
337
- schema = TableSchema('user_stats')
338
- schema.add_primary_key('user_id', 'string')
339
- schema.add_date_field('date', 'date')
340
- schema.add_field('amount', 'decimal', aggregatable=True)
341
- schema.set_monthly_unique(True)
390
+ # 创建示例并查看摘要
391
+ example = create_aum_example("dwegdata03000")
392
+ example.print_summary()
342
393
 
343
- # 创建管理器(使用引擎架构)
344
- manager = FeatureManager(engine_type='spark', database='analytics_db')
394
+ # 快速运行(测试模式,不执行实际SQL)
395
+ print("🎯 AUM长尾模型示例已准备就绪")
396
+ print("📊 包含4张业务表的完整特征工程流程")
397
+ ```
345
398
 
346
- # 生成特征并查看摘要
347
- summary = manager.get_feature_summary(schema)
348
- print(f"生成特征数: {summary['total']}")
399
+ ### 一键运行示例
400
+ ```python
401
+ from staran import run_aum_example
349
402
 
350
- # 生成聚合特征SQL
351
- result = manager.generate_feature_by_type(schema, 'aggregation', 2025, 7)
352
- print("SQL长度:", len(result['sql']))
403
+ # 最简单的使用方式
404
+ results = run_aum_example("202507") # 指定特征月份
405
+ print(f" 处理完成: {len(results)} 个表")
353
406
  ```
354
407
 
355
408
  ### Date工具测试
@@ -382,21 +435,38 @@ print(f"✅ 继承关系: 继承自{turing.__class__.__bases__[0].__name__}")
382
435
  print("🚀 环境就绪!开始特征工程之旅")
383
436
  ```
384
437
 
385
- ### 2. 完整ML流程
438
+ ### 2. 运行AUM示例
386
439
  ```python
387
- # 使用新引擎架构进行特征工程
388
- from staran import FeatureManager
389
-
390
- # 创建基于Turing引擎的特征管理器
391
- manager = FeatureManager(engine_type='turing', database='production_analytics')
440
+ # 最简单的方式 - 一行代码完成复杂特征工程
441
+ from staran import run_aum_example
392
442
 
393
- # 执行SQL并下载结果
394
- result = manager.execute_and_download(
395
- sql="SELECT user_id, features FROM ml_features WHERE dt='2025-07-28'",
396
- output_path="file:///nfsHome/ml_pipeline/"
443
+ results = run_aum_example(
444
+ feature_date="202507", # 特征月份
445
+ database="dwegdata03000", # 数据库名
446
+ output_path="file:///nfsHome/aum_features" # 输出路径
397
447
  )
398
448
 
399
- print(f"✅ 成功!使用{manager.engine.__class__.__name__}完成数据处理")
449
+ print(f"✅ 成功!处理了4张表,生成了完整的特征数据集")
450
+ print("📂 数据已保存到 /nfsHome/aum_features/ 目录")
451
+ ```
452
+
453
+ ### 3. 自定义特征工程
454
+ ```python
455
+ # 如需更多控制,使用详细API
456
+ from staran import create_aum_example
457
+
458
+ example = create_aum_example("dwegdata03000")
459
+
460
+ # 查看会生成哪些特征
461
+ example.print_summary()
462
+
463
+ # 运行特征工程
464
+ results = example.run("202507")
465
+
466
+ # 查看结果
467
+ for table_type, result in results.items():
468
+ if 'table_name' in result:
469
+ print(f"{table_type}: {result['table_name']}")
400
470
  ```
401
471
 
402
472
  ## 📊 性能优势
@@ -411,10 +481,58 @@ print(f"✅ 成功!使用{manager.engine.__class__.__name__}完成数据处理
411
481
  - **批量处理**: 并行下载和增量处理
412
482
  - **错误恢复**: 自动重试和断点续传
413
483
 
484
+ ## 🎯 完整示例
485
+
486
+ ### AUM代发长尾模型 - 简化API
487
+ 位置:`staran.examples` 模块
488
+
489
+ 基于真实金融业务场景的完整特征工程示例,展示了新的引擎架构优势:
490
+
491
+ ```python
492
+ # 最简单的使用方式
493
+ from staran import run_aum_example
494
+
495
+ # 一键运行完整特征工程流程
496
+ results = run_aum_example(
497
+ feature_date="202507", # 可选,默认当前月
498
+ database="dwegdata03000",
499
+ output_path="file:///nfsHome/aum_longtail"
500
+ )
501
+
502
+ print(f"✅ 特征工程完成!处理了 {len(results)} 个表")
503
+ ```
504
+
505
+ **更多控制的方式:**
506
+ ```python
507
+ from staran import create_aum_example
508
+
509
+ # 创建示例实例
510
+ example = create_aum_example("dwegdata03000")
511
+
512
+ # 查看特征摘要
513
+ example.print_summary()
514
+
515
+ # 运行特征工程
516
+ results = example.run("202507")
517
+ ```
518
+
519
+ **示例特点:**
520
+ - 🏦 **真实业务场景** - 4张银行核心业务表的完整处理
521
+ - 🔧 **智能特征配置** - A表(源表+聚合),其他表(全特征:环比5个月+同比1年)
522
+ - 📊 **多维度特征** - 客户行为、资产配置、交易统计、境外交易等
523
+ - 🚀 **简化API** - 一行代码完成复杂特征工程
524
+ - 📋 **完整文档** - 每个字段都有详细的业务含义说明
525
+
526
+ **数据表说明:**
527
+ - **A表** (`bi_hlwj_dfcw_f1_f4_wy`): 客户行为特征 → 仅生成原始拷贝+聚合特征
528
+ - **B表** (`bi_hlwj_zi_chan_avg_wy`): 资产平均余额 → 生成全部特征(聚合+环比5个月+同比1年)
529
+ - **C表** (`bi_hlwj_zi_chang_month_total_zb`): 月度资产配置 → 生成全部特征
530
+ - **D表** (`bi_hlwj_realy_month_stat_wy`): 月度实际统计 → 生成全部特征
531
+
414
532
  ## 📄 许可证
415
533
 
416
534
  MIT License
417
535
 
418
536
  ---
419
537
 
420
- **Staran v0.2.4** - 模块化引擎架构,让机器学习特征工程变得前所未有的简单 🌟
538
+ **Staran v0.4.0** - 模块化引擎架构,让机器学习特征工程变得前所未有的简单 🌟
staran-0.4.0/setup.py ADDED
@@ -0,0 +1,31 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="staran",
5
+ version="0.4.0",
6
+ description="staran - 高性能Python工具库",
7
+ long_description=open("README.md", encoding="utf-8").read(),
8
+ long_description_content_type="text/markdown",
9
+ author="StarAn",
10
+ author_email="starlxa@icloud.com",
11
+ url="https://github.com/starlxa/staran",
12
+ packages=[
13
+ "staran",
14
+ "staran.tools",
15
+ "staran.features",
16
+ "staran.engines",
17
+ "staran.examples",
18
+ "staran.schemas",
19
+ "staran.schemas.aum",
20
+ ],
21
+ install_requires=[
22
+ "datetime",
23
+ "calendar",
24
+ "re",
25
+ ],
26
+ classifiers=[
27
+ "Programming Language :: Python :: 3",
28
+ "License :: OSI Approved :: MIT License",
29
+ ],
30
+ python_requires=">=3.7",
31
+ )
@@ -154,18 +154,22 @@ SQL工具:
154
154
  from .tools import Date
155
155
  from .features import (
156
156
  TableSchema, FeatureGenerator, FeatureManager, FeatureTableManager,
157
- FeatureConfig, DatabaseType
157
+ FeatureConfig, DatabaseType, FeatureType, Field, FieldType
158
158
  )
159
- from .engines import SparkEngine, HiveEngine, create_engine
159
+ from .engines import SparkEngine, HiveEngine, TuringEngine, BaseEngine, create_engine, create_turing_engine
160
+
161
+ # Examples模块 - 业务示例
162
+ from .examples import create_aum_example, run_aum_example
163
+
164
+ # Schemas模块 - 表结构定义与文档生成
165
+ from .schemas import SchemaDocumentGenerator
166
+ from .schemas.aum import get_aum_schemas, export_aum_docs
160
167
 
161
168
  # 图灵平台引擎 (可选导入,避免依赖问题)
162
169
  try:
163
- from .engines import TuringEngine, create_turing_engine
164
170
  from .features import quick_create_and_download
165
171
  _TURING_AVAILABLE = True
166
172
  except ImportError:
167
- TuringEngine = None
168
- create_turing_engine = None
169
173
  quick_create_and_download = None
170
174
  _TURING_AVAILABLE = False
171
175
 
@@ -179,12 +183,25 @@ __all__ = [
179
183
  'TableSchema',
180
184
  'FeatureGenerator',
181
185
  'FeatureConfig',
186
+ 'FeatureType',
187
+ 'Field',
188
+ 'FieldType',
182
189
  'FeatureManager',
183
190
  'FeatureTableManager',
184
191
  'DatabaseType',
192
+ 'BaseEngine',
185
193
  'SparkEngine',
186
194
  'HiveEngine',
195
+ 'TuringEngine',
187
196
  'create_engine',
197
+ 'create_turing_engine',
198
+ # 示例模块
199
+ 'create_aum_example',
200
+ 'run_aum_example',
201
+ # 表结构模块
202
+ 'SchemaDocumentGenerator',
203
+ 'get_aum_schemas',
204
+ 'export_aum_docs',
188
205
  # 向后兼容
189
206
  'SQLManager',
190
207
  'SparkSQLGenerator'
@@ -193,15 +210,13 @@ __all__ = [
193
210
  # 如果图灵引擎可用,添加到导出列表
194
211
  if _TURING_AVAILABLE:
195
212
  __all__.extend([
196
- 'TuringEngine',
197
- 'create_turing_engine',
198
213
  'quick_create_and_download'
199
214
  ])
200
215
 
201
216
  # 包信息
202
- __version__ = '2.0.0'
217
+ __version__ = '0.3.0'
203
218
  __author__ = 'Staran Team'
204
- __description__ = 'Smart feature engineering toolkit with modular engine architecture'
219
+ __description__ = 'Smart feature engineering toolkit with schema management, document generation and business examples'
205
220
  __license__ = 'MIT'
206
221
 
207
222
  # 便捷函数示例
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 数据库引擎模块
6
+ 提供统一的数据库引擎接口
7
+ """
8
+
9
+ # 基础组件
10
+ from .base import BaseEngine, DatabaseType
11
+
12
+ # 具体引擎实现
13
+ from .spark import SparkEngine
14
+ from .hive import HiveEngine
15
+
16
+ # 图灵平台引擎 (可选导入)
17
+ try:
18
+ from .turing import TuringEngine, create_turing_engine
19
+ _TURING_AVAILABLE = True
20
+ except ImportError:
21
+ TuringEngine = None
22
+ create_turing_engine = None
23
+ _TURING_AVAILABLE = False
24
+
25
+ # 便捷创建函数
26
+ def create_engine(engine_type: str, database_name: str, **kwargs) -> BaseEngine:
27
+ """
28
+ 创建数据库引擎的便捷函数
29
+
30
+ Args:
31
+ engine_type: 引擎类型 ('spark', 'hive', 'turing')
32
+ database_name: 数据库名称
33
+ **kwargs: 其他参数
34
+
35
+ Returns:
36
+ 数据库引擎实例
37
+ """
38
+ engine_type = engine_type.lower()
39
+
40
+ if engine_type == 'spark':
41
+ return SparkEngine(database_name, **kwargs)
42
+ elif engine_type == 'hive':
43
+ return HiveEngine(database_name, **kwargs)
44
+ elif engine_type == 'turing':
45
+ if not _TURING_AVAILABLE:
46
+ raise ImportError("TuringEngine不可用,请确保turingPythonLib已安装")
47
+ return TuringEngine(database_name, **kwargs)
48
+ else:
49
+ raise ValueError(f"不支持的引擎类型: {engine_type}")
50
+
51
+ # 主要导出
52
+ __all__ = [
53
+ 'BaseEngine',
54
+ 'DatabaseType',
55
+ 'SparkEngine',
56
+ 'HiveEngine',
57
+ 'create_engine'
58
+ ]
59
+
60
+ # 如果图灵引擎可用,添加到导出
61
+ if _TURING_AVAILABLE:
62
+ __all__.extend([
63
+ 'TuringEngine',
64
+ 'create_turing_engine'
65
+ ])