staran 0.5.0__py3-none-any.whl → 0.6.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 +0 -261
- staran/banks/__init__.py +30 -0
- staran/banks/xinjiang_icbc/__init__.py +90 -0
- staran/models/__init__.py +59 -68
- staran/models/daifa_models.py +361 -0
- staran/schemas/__init__.py +14 -15
- staran/schemas/aum/__init__.py +103 -199
- {staran-0.5.0.dist-info → staran-0.6.1.dist-info}/METADATA +42 -20
- {staran-0.5.0.dist-info → staran-0.6.1.dist-info}/RECORD +13 -14
- staran/examples/__init__.py +0 -8
- staran/examples/aum_longtail.py +0 -250
- staran/examples/aum_longtail_old.py +0 -487
- staran/models/bank_configs.py +0 -269
- /staran/{schemas → tools}/document_generator.py +0 -0
- {staran-0.5.0.dist-info → staran-0.6.1.dist-info}/WHEEL +0 -0
- {staran-0.5.0.dist-info → staran-0.6.1.dist-info}/licenses/LICENSE +0 -0
- {staran-0.5.0.dist-info → staran-0.6.1.dist-info}/top_level.txt +0 -0
staran/models/bank_configs.py
DELETED
@@ -1,269 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
银行特定配置模块
|
3
|
-
|
4
|
-
为不同银行提供定制化的配置和业务规则
|
5
|
-
"""
|
6
|
-
|
7
|
-
from enum import Enum
|
8
|
-
from typing import Dict, Any, List, Optional
|
9
|
-
from dataclasses import dataclass, field
|
10
|
-
|
11
|
-
|
12
|
-
class BankCode(Enum):
|
13
|
-
"""银行代码枚举"""
|
14
|
-
ICBC = "icbc" # 工商银行
|
15
|
-
CCB = "ccb" # 建设银行
|
16
|
-
BOC = "boc" # 中国银行
|
17
|
-
ABC = "abc" # 农业银行
|
18
|
-
CMB = "cmb" # 招商银行
|
19
|
-
GENERIC = "generic" # 通用配置
|
20
|
-
|
21
|
-
|
22
|
-
@dataclass
|
23
|
-
class BankConfig:
|
24
|
-
"""银行配置类"""
|
25
|
-
# 基本信息
|
26
|
-
bank_code: str # 银行代码
|
27
|
-
bank_name: str # 银行名称
|
28
|
-
region: str = "cn" # 地区代码
|
29
|
-
|
30
|
-
# 数据库配置
|
31
|
-
database_config: Dict[str, Any] = field(default_factory=dict)
|
32
|
-
|
33
|
-
# 表名映射 (不同银行的表名可能不同)
|
34
|
-
table_mappings: Dict[str, str] = field(default_factory=dict)
|
35
|
-
|
36
|
-
# 字段映射 (不同银行的字段名可能不同)
|
37
|
-
field_mappings: Dict[str, Dict[str, str]] = field(default_factory=dict)
|
38
|
-
|
39
|
-
# 业务规则
|
40
|
-
business_rules: Dict[str, Any] = field(default_factory=dict)
|
41
|
-
|
42
|
-
# 合规要求
|
43
|
-
compliance_rules: Dict[str, Any] = field(default_factory=dict)
|
44
|
-
|
45
|
-
# 数据处理规则
|
46
|
-
data_processing_rules: Dict[str, Any] = field(default_factory=dict)
|
47
|
-
|
48
|
-
# 模型部署配置
|
49
|
-
deployment_config: Dict[str, Any] = field(default_factory=dict)
|
50
|
-
|
51
|
-
# 特征工程配置
|
52
|
-
feature_engineering_config: Dict[str, Any] = field(default_factory=dict)
|
53
|
-
|
54
|
-
def get_table_name(self, standard_table: str) -> str:
|
55
|
-
"""获取银行特定的表名"""
|
56
|
-
return self.table_mappings.get(standard_table, standard_table)
|
57
|
-
|
58
|
-
def get_field_name(self, table: str, standard_field: str) -> str:
|
59
|
-
"""获取银行特定的字段名"""
|
60
|
-
table_fields = self.field_mappings.get(table, {})
|
61
|
-
return table_fields.get(standard_field, standard_field)
|
62
|
-
|
63
|
-
def get_business_rule(self, rule_name: str, default=None):
|
64
|
-
"""获取业务规则"""
|
65
|
-
return self.business_rules.get(rule_name, default)
|
66
|
-
|
67
|
-
def validate_compliance(self, operation: str) -> bool:
|
68
|
-
"""验证操作是否符合合规要求"""
|
69
|
-
compliance_checks = self.compliance_rules.get(operation, {})
|
70
|
-
# 这里可以实现具体的合规检查逻辑
|
71
|
-
return compliance_checks.get('enabled', True)
|
72
|
-
|
73
|
-
|
74
|
-
# 银行配置注册表
|
75
|
-
_BANK_CONFIGS: Dict[str, BankConfig] = {}
|
76
|
-
|
77
|
-
|
78
|
-
def register_bank_config(config: BankConfig):
|
79
|
-
"""注册银行配置"""
|
80
|
-
_BANK_CONFIGS[config.bank_code] = config
|
81
|
-
print(f"✅ 银行配置 {config.bank_code} ({config.bank_name}) 注册成功")
|
82
|
-
|
83
|
-
|
84
|
-
def get_bank_config(bank_code: str) -> Optional[BankConfig]:
|
85
|
-
"""获取银行配置"""
|
86
|
-
return _BANK_CONFIGS.get(bank_code)
|
87
|
-
|
88
|
-
|
89
|
-
def list_bank_configs() -> List[Dict[str, str]]:
|
90
|
-
"""列出所有银行配置"""
|
91
|
-
return [
|
92
|
-
{
|
93
|
-
'bank_code': config.bank_code,
|
94
|
-
'bank_name': config.bank_name,
|
95
|
-
'region': config.region
|
96
|
-
}
|
97
|
-
for config in _BANK_CONFIGS.values()
|
98
|
-
]
|
99
|
-
|
100
|
-
|
101
|
-
# 预定义银行配置
|
102
|
-
def create_icbc_config() -> BankConfig:
|
103
|
-
"""创建工商银行配置"""
|
104
|
-
return BankConfig(
|
105
|
-
bank_code="icbc",
|
106
|
-
bank_name="中国工商银行",
|
107
|
-
region="cn",
|
108
|
-
|
109
|
-
database_config={
|
110
|
-
"default_database": "dwegdata03000",
|
111
|
-
"connection_pool_size": 10,
|
112
|
-
"query_timeout": 300
|
113
|
-
},
|
114
|
-
|
115
|
-
table_mappings={
|
116
|
-
"behavior_table": "bi_hlwj_dfcw_f1_f4_wy",
|
117
|
-
"asset_avg_table": "bi_hlwj_zi_chan_avg_wy",
|
118
|
-
"asset_config_table": "bi_hlwj_zi_chang_month_total_zb",
|
119
|
-
"monthly_stat_table": "bi_hlwj_realy_month_stat_wy"
|
120
|
-
},
|
121
|
-
|
122
|
-
field_mappings={
|
123
|
-
"behavior_table": {
|
124
|
-
"customer_id": "party_id",
|
125
|
-
"date_field": "data_dt"
|
126
|
-
}
|
127
|
-
},
|
128
|
-
|
129
|
-
business_rules={
|
130
|
-
"data_retention_days": 90,
|
131
|
-
"min_sample_size": 1000,
|
132
|
-
"max_features": 500,
|
133
|
-
"risk_threshold": 0.8,
|
134
|
-
"aum_threshold": 100000,
|
135
|
-
"longtail_definition": {
|
136
|
-
"asset_threshold": 50000,
|
137
|
-
"activity_threshold": 0.3
|
138
|
-
}
|
139
|
-
},
|
140
|
-
|
141
|
-
compliance_rules={
|
142
|
-
"data_export": {
|
143
|
-
"enabled": True,
|
144
|
-
"approval_required": True,
|
145
|
-
"encryption_required": True
|
146
|
-
},
|
147
|
-
"model_deployment": {
|
148
|
-
"enabled": True,
|
149
|
-
"testing_required": True,
|
150
|
-
"documentation_required": True
|
151
|
-
},
|
152
|
-
"feature_selection": {
|
153
|
-
"enabled": True,
|
154
|
-
"sensitive_data_allowed": False,
|
155
|
-
"audit_trail_required": True
|
156
|
-
}
|
157
|
-
},
|
158
|
-
|
159
|
-
data_processing_rules={
|
160
|
-
"missing_value_strategy": "median",
|
161
|
-
"outlier_detection": True,
|
162
|
-
"outlier_threshold": 3.0,
|
163
|
-
"feature_scaling": "standard",
|
164
|
-
"categorical_encoding": "one_hot"
|
165
|
-
},
|
166
|
-
|
167
|
-
deployment_config={
|
168
|
-
"platform": "turing",
|
169
|
-
"environment": "production",
|
170
|
-
"monitoring_enabled": True,
|
171
|
-
"auto_scaling": True,
|
172
|
-
"backup_required": True
|
173
|
-
},
|
174
|
-
|
175
|
-
feature_engineering_config={
|
176
|
-
"time_windows": ["1_month", "3_months", "6_months", "1_year"],
|
177
|
-
"aggregation_functions": ["sum", "avg", "max", "min", "std"],
|
178
|
-
"interaction_features": True,
|
179
|
-
"polynomial_features": False,
|
180
|
-
"target_encoding": True
|
181
|
-
}
|
182
|
-
)
|
183
|
-
|
184
|
-
|
185
|
-
def create_generic_config() -> BankConfig:
|
186
|
-
"""创建通用银行配置"""
|
187
|
-
return BankConfig(
|
188
|
-
bank_code="generic",
|
189
|
-
bank_name="通用银行配置",
|
190
|
-
region="generic",
|
191
|
-
|
192
|
-
database_config={
|
193
|
-
"default_database": "default_db",
|
194
|
-
"connection_pool_size": 5,
|
195
|
-
"query_timeout": 180
|
196
|
-
},
|
197
|
-
|
198
|
-
table_mappings={
|
199
|
-
"behavior_table": "customer_behavior",
|
200
|
-
"asset_avg_table": "customer_assets",
|
201
|
-
"asset_config_table": "asset_config",
|
202
|
-
"monthly_stat_table": "monthly_stats"
|
203
|
-
},
|
204
|
-
|
205
|
-
business_rules={
|
206
|
-
"data_retention_days": 30,
|
207
|
-
"min_sample_size": 100,
|
208
|
-
"max_features": 100
|
209
|
-
},
|
210
|
-
|
211
|
-
compliance_rules={
|
212
|
-
"data_export": {"enabled": True},
|
213
|
-
"model_deployment": {"enabled": True}
|
214
|
-
},
|
215
|
-
|
216
|
-
data_processing_rules={
|
217
|
-
"missing_value_strategy": "mean",
|
218
|
-
"outlier_detection": False,
|
219
|
-
"feature_scaling": "none"
|
220
|
-
}
|
221
|
-
)
|
222
|
-
|
223
|
-
|
224
|
-
# 初始化默认银行配置
|
225
|
-
def initialize_default_configs():
|
226
|
-
"""初始化默认银行配置"""
|
227
|
-
# 注册工商银行配置
|
228
|
-
register_bank_config(create_icbc_config())
|
229
|
-
|
230
|
-
# 注册通用配置
|
231
|
-
register_bank_config(create_generic_config())
|
232
|
-
|
233
|
-
|
234
|
-
# 自动初始化
|
235
|
-
initialize_default_configs()
|
236
|
-
|
237
|
-
|
238
|
-
# 新疆工行特定配置
|
239
|
-
def create_xinjiang_icbc_config() -> BankConfig:
|
240
|
-
"""创建新疆工商银行配置"""
|
241
|
-
base_config = create_icbc_config()
|
242
|
-
|
243
|
-
# 基于基础工行配置进行定制
|
244
|
-
base_config.bank_code = "xinjiang_icbc"
|
245
|
-
base_config.bank_name = "新疆工商银行"
|
246
|
-
base_config.region = "xinjiang"
|
247
|
-
|
248
|
-
# 新疆特定的业务规则
|
249
|
-
base_config.business_rules.update({
|
250
|
-
"regional_compliance": True,
|
251
|
-
"minority_customer_support": True,
|
252
|
-
"language_support": ["zh", "ug"], # 中文和维吾尔语
|
253
|
-
"timezone": "Asia/Urumqi",
|
254
|
-
"currency_support": ["CNY"],
|
255
|
-
"cross_border_transaction": True
|
256
|
-
})
|
257
|
-
|
258
|
-
# 新疆特定的数据处理规则
|
259
|
-
base_config.data_processing_rules.update({
|
260
|
-
"character_encoding": "utf-8",
|
261
|
-
"regional_holidays": True,
|
262
|
-
"time_zone_conversion": True
|
263
|
-
})
|
264
|
-
|
265
|
-
return base_config
|
266
|
-
|
267
|
-
|
268
|
-
# 注册新疆工行配置
|
269
|
-
register_bank_config(create_xinjiang_icbc_config())
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|