staran 1.0.9__py3-none-any.whl → 1.0.10__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.
@@ -0,0 +1,376 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ Staran v1.0.10 新功能演示
6
+ ========================
7
+
8
+ 演示v1.0.10版本的所有新功能:
9
+ - 完整时区支持
10
+ - 日期表达式解析
11
+ - 二十四节气扩展
12
+ - 数据可视化集成
13
+ - REST API接口
14
+ """
15
+
16
+ import sys
17
+ import os
18
+ import datetime
19
+
20
+ # 添加项目根目录到路径
21
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..'))
22
+
23
+ from staran.date import (
24
+ Date, get_version_info, get_feature_status, parse_expression,
25
+ create_timeline_chart, start_api_server
26
+ )
27
+
28
+ def demo_version_info():
29
+ """演示版本信息和功能状态"""
30
+ print("🚀 Staran v1.0.10 版本信息")
31
+ print("=" * 50)
32
+
33
+ version_info = get_version_info()
34
+ print(f"版本: {version_info['version']}")
35
+ print(f"v1.0.10功能可用: {version_info['v1010_features_available']}")
36
+
37
+ print("\n可用模块:")
38
+ for module, available in version_info['modules'].items():
39
+ status = "✅" if available else "❌"
40
+ print(f" {status} {module}")
41
+
42
+ if version_info.get('new_features'):
43
+ print(f"\n新功能: {', '.join(version_info['new_features'])}")
44
+
45
+ # Date对象的功能状态
46
+ date_obj = Date.today()
47
+ feature_status = date_obj.get_feature_status()
48
+
49
+ print(f"\nDate对象功能状态:")
50
+ for feature, available in feature_status.items():
51
+ status = "✅" if available else "❌"
52
+ print(f" {status} {feature}")
53
+
54
+ def demo_timezone_support():
55
+ """演示时区支持功能"""
56
+ print("\n\n🌍 时区支持功能演示")
57
+ print("=" * 50)
58
+
59
+ date = Date("2025-07-29")
60
+
61
+ try:
62
+ # 列出支持的时区
63
+ timezones = Date.get_supported_timezones()
64
+ print(f"支持的时区数量: {len(timezones)}")
65
+ print(f"主要时区: {timezones[:10]}")
66
+
67
+ # 时区信息查询
68
+ print(f"\n时区信息查询:")
69
+ for tz in ['UTC+8', 'EST', 'JST', 'GMT']:
70
+ try:
71
+ tz_info = date.get_timezone_info(tz)
72
+ print(f" {tz}: {tz_info['name']} ({tz_info['description']})")
73
+ print(f" 当前偏移: {tz_info['offset_string']}")
74
+ print(f" 夏令时: {'是' if tz_info['is_dst_active'] else '否'}")
75
+ except Exception as e:
76
+ print(f" {tz}: 获取信息失败 - {e}")
77
+
78
+ # 时区转换演示
79
+ print(f"\n时区转换演示:")
80
+ try:
81
+ import datetime as dt
82
+ base_time = dt.time(12, 0, 0) # 中午12点
83
+
84
+ beijing_dt = date.to_timezone('UTC+8', base_time)
85
+ print(f" 北京时间: {beijing_dt}")
86
+
87
+ # 创建其他时区的时间
88
+ utc_dt = date.to_timezone('UTC', base_time)
89
+ print(f" UTC时间: {utc_dt}")
90
+
91
+ except Exception as e:
92
+ print(f" 时区转换演示失败: {e}")
93
+
94
+ except Exception as e:
95
+ print(f"时区功能不可用: {e}")
96
+
97
+ def demo_expression_parsing():
98
+ """演示日期表达式解析功能"""
99
+ print("\n\n📝 日期表达式解析演示")
100
+ print("=" * 50)
101
+
102
+ expressions = [
103
+ "今天", "明天", "后天", "昨天", "前天",
104
+ "下周一", "上周五", "这周三",
105
+ "下个月", "上个月", "明年",
106
+ "3天后", "5天前", "2周后", "1个月前",
107
+ "2025年春节", "2025-12-25", "12月15日"
108
+ ]
109
+
110
+ print("表达式解析测试:")
111
+ for expr in expressions:
112
+ try:
113
+ result = parse_expression(expr)
114
+ if result:
115
+ print(f" '{expr}' → {result.format_iso()} ({result.format_chinese()})")
116
+
117
+ # 获取详细解析信息
118
+ detailed = Date.parse_expression_detailed(expr)
119
+ if detailed['success']:
120
+ print(f" 置信度: {detailed['confidence']:.2f}")
121
+ print(f" 匹配模式: {detailed['matched_pattern']}")
122
+ else:
123
+ print(f" '{expr}' → 解析失败")
124
+ except Exception as e:
125
+ print(f" '{expr}' → 错误: {e}")
126
+
127
+ def demo_solar_terms():
128
+ """演示二十四节气功能"""
129
+ print("\n\n🌸 二十四节气功能演示")
130
+ print("=" * 50)
131
+
132
+ try:
133
+ current_year = 2025
134
+
135
+ # 获取全年节气
136
+ solar_terms = Date.get_year_solar_terms(current_year)
137
+ print(f"{current_year}年二十四节气:")
138
+
139
+ for i, term in enumerate(solar_terms):
140
+ print(f" {i+1:2d}. {term.name:4s} - {term.date.strftime('%m月%d日')} ({term.season})")
141
+ if i == 5: # 只显示前6个,节省空间
142
+ print(f" ... (共{len(solar_terms)}个节气)")
143
+ break
144
+
145
+ # 当前日期的节气信息
146
+ today = Date.today()
147
+ print(f"\n当前日期节气信息:")
148
+ print(f" 日期: {today.format_chinese()}")
149
+
150
+ try:
151
+ current_term = today.get_solar_term()
152
+ if current_term:
153
+ print(f" 最近节气: {current_term.name}")
154
+ print(f" 节气日期: {current_term.date.strftime('%Y年%m月%d日')}")
155
+ print(f" 节气描述: {current_term.description}")
156
+ print(f" 气候特征: {current_term.climate_features}")
157
+
158
+ # 下一个节气
159
+ next_term = today.get_next_solar_term()
160
+ print(f" 下一节气: {next_term.name}")
161
+ print(f" 节气日期: {next_term.date.strftime('%Y年%m月%d日')}")
162
+ print(f" 距离天数: {today.days_to_next_solar_term()}天")
163
+
164
+ # 判断是否节气日
165
+ is_term_day = today.is_solar_term()
166
+ print(f" 今天是节气日: {'是' if is_term_day else '否'}")
167
+
168
+ except Exception as e:
169
+ print(f" 节气信息获取失败: {e}")
170
+
171
+ except Exception as e:
172
+ print(f"节气功能不可用: {e}")
173
+
174
+ def demo_visualization():
175
+ """演示数据可视化功能"""
176
+ print("\n\n📊 数据可视化功能演示")
177
+ print("=" * 50)
178
+
179
+ try:
180
+ # 创建示例数据
181
+ dates = [Date("2025-07-29"), Date("2025-08-01"), Date("2025-08-15")]
182
+ events = ["项目开始", "里程碑1", "项目完成"]
183
+
184
+ # 创建时间轴图表
185
+ chart_data = create_timeline_chart(dates, events, 'echarts')
186
+
187
+ print("时间轴图表数据:")
188
+ print(f" 图表类型: {chart_data.chart_type}")
189
+ print(f" 标题: {chart_data.title}")
190
+ print(f" 图表库: {chart_data.library}")
191
+ print(f" 数据点数量: {len(chart_data.data)}")
192
+
193
+ # 显示部分数据
194
+ print(f" 示例数据:")
195
+ for i, data_point in enumerate(chart_data.data[:3]):
196
+ print(f" {i+1}. {data_point}")
197
+
198
+ # 日历热力图示例
199
+ print(f"\n日历热力图数据生成:")
200
+ date_values = {
201
+ Date("2025-07-29"): 85,
202
+ Date("2025-07-30"): 92,
203
+ Date("2025-07-31"): 78
204
+ }
205
+
206
+ try:
207
+ heatmap_data = Date.create_calendar_heatmap(date_values, 2025, 'echarts')
208
+ print(f" 热力图标题: {heatmap_data.title}")
209
+ print(f" 数据点数量: {len(heatmap_data.data)}")
210
+ except Exception as e:
211
+ print(f" 热力图生成失败: {e}")
212
+
213
+ # 时间序列图表
214
+ print(f"\n时间序列图表:")
215
+ time_series_data = [
216
+ (Date("2025-07-29"), 100),
217
+ (Date("2025-07-30"), 120),
218
+ (Date("2025-07-31"), 95)
219
+ ]
220
+
221
+ try:
222
+ series_chart = Date.create_time_series_chart(time_series_data, 'echarts')
223
+ print(f" 系列图标题: {series_chart.title}")
224
+ print(f" 配置类型: {series_chart.config.get('type')}")
225
+ except Exception as e:
226
+ print(f" 时间序列图生成失败: {e}")
227
+
228
+ except Exception as e:
229
+ print(f"可视化功能不可用: {e}")
230
+
231
+ def demo_enhanced_date_ranges():
232
+ """演示增强的日期范围功能"""
233
+ print("\n\n📅 增强日期范围功能演示")
234
+ print("=" * 50)
235
+
236
+ start_date = Date("2025-07-29")
237
+ end_date = Date("2025-08-15")
238
+
239
+ # 创建日期范围
240
+ date_range = start_date.create_range_to(end_date)
241
+ print(f"日期范围: {start_date.format_iso()} 到 {end_date.format_iso()}")
242
+ print(f"范围天数: {date_range.days_count()}天")
243
+
244
+ # 检查日期是否在范围内
245
+ test_date = Date("2025-08-01")
246
+ in_range = test_date.in_range(start_date, end_date)
247
+ print(f"{test_date.format_iso()} 在范围内: {'是' if in_range else '否'}")
248
+
249
+ # 创建日期序列
250
+ sequence = Date.create_date_sequence(start_date, start_date.add_days(6), 2)
251
+ print(f"日期序列 (步长2天): {[d.format_iso() for d in sequence]}")
252
+
253
+ # 范围操作
254
+ range1 = start_date.create_range_with_days(10)
255
+ range2 = start_date.add_days(5).create_range_with_days(10)
256
+
257
+ print(f"范围1: {range1.start.format_iso()} - {range1.end.format_iso()}")
258
+ print(f"范围2: {range2.start.format_iso()} - {range2.end.format_iso()}")
259
+
260
+ # 交集
261
+ intersection = range1.intersect(range2)
262
+ if intersection:
263
+ print(f"交集: {intersection.start.format_iso()} - {intersection.end.format_iso()}")
264
+ else:
265
+ print("无交集")
266
+
267
+ # 并集
268
+ union = range1.union(range2)
269
+ print(f"并集: {union.start.format_iso()} - {union.end.format_iso()}")
270
+
271
+ def demo_api_server():
272
+ """演示REST API服务器功能"""
273
+ print("\n\n🌐 REST API服务器演示")
274
+ print("=" * 50)
275
+
276
+ try:
277
+ from staran.date import start_api_server
278
+
279
+ print("API服务器功能演示:")
280
+ print(" 注意: 这里只演示服务器创建,不实际启动")
281
+ print(" 实际使用时可以启动完整的HTTP服务")
282
+
283
+ # 实际使用时的示例
284
+ print("\n启动API服务器的方法:")
285
+ print(" server = start_api_server('localhost', 8000, background=True)")
286
+ print(" # 服务器将在 http://localhost:8000 运行")
287
+ print("")
288
+ print("主要API端点:")
289
+ endpoints = [
290
+ "GET /api/health - 健康检查",
291
+ "GET /api/date/create?date=2025-07-29 - 创建日期",
292
+ "GET /api/date/format?date=2025-07-29&format=chinese - 格式化日期",
293
+ "GET /api/lunar/convert?date=2025-07-29&direction=solar_to_lunar - 农历转换",
294
+ "GET /api/solar-terms?year=2025 - 查询节气",
295
+ "GET /api/timezone/convert?date=2025-07-29&from_tz=UTC+8&to_tz=EST - 时区转换",
296
+ "GET /api/expression/parse?expression=明天 - 表达式解析",
297
+ "GET /api/visualization/data?type=calendar_heatmap&year=2025 - 可视化数据"
298
+ ]
299
+
300
+ for endpoint in endpoints:
301
+ print(f" {endpoint}")
302
+
303
+ print(f"\n文档地址: GET /api/docs")
304
+
305
+ except Exception as e:
306
+ print(f"API服务器功能不可用: {e}")
307
+
308
+ def demo_help_system():
309
+ """演示帮助系统"""
310
+ print("\n\n❓ 帮助系统演示")
311
+ print("=" * 50)
312
+
313
+ date = Date.today()
314
+
315
+ # 获取创建方法帮助
316
+ help_creation = date.help('creation')
317
+ print("创建方法帮助:")
318
+ print(help_creation)
319
+
320
+ # 获取时区功能帮助
321
+ try:
322
+ help_timezone = date.help('timezone')
323
+ print(f"\n时区功能帮助:")
324
+ print(help_timezone)
325
+ except:
326
+ print(f"\n时区功能帮助不可用")
327
+
328
+ # 获取节气功能帮助
329
+ try:
330
+ help_solar_terms = date.help('solar_terms')
331
+ print(f"\n节气功能帮助:")
332
+ print(help_solar_terms)
333
+ except:
334
+ print(f"\n节气功能帮助不可用")
335
+
336
+ def main():
337
+ """主演示函数"""
338
+ print("🚀 Staran v1.0.10 完整功能演示")
339
+ print("=" * 60)
340
+
341
+ try:
342
+ # 基础信息
343
+ demo_version_info()
344
+
345
+ # 新功能演示
346
+ demo_timezone_support()
347
+ demo_expression_parsing()
348
+ demo_solar_terms()
349
+ demo_visualization()
350
+ demo_enhanced_date_ranges()
351
+ demo_api_server()
352
+ demo_help_system()
353
+
354
+ print("\n\n✅ v1.0.10 功能演示完成!")
355
+ print("=" * 60)
356
+ print("🌟 主要新增功能:")
357
+ print(" • 完整时区支持 - 全球时区转换和处理")
358
+ print(" • 日期表达式解析 - 自然语言日期解析")
359
+ print(" • 二十四节气扩展 - 完整节气计算和查询")
360
+ print(" • 数据可视化集成 - 多种图表库支持")
361
+ print(" • REST API接口 - HTTP API服务")
362
+ print(" • 增强日期范围操作 - 更丰富的范围功能")
363
+ print(" • 智能帮助系统 - 分类帮助信息")
364
+ print("")
365
+ print("📚 更多信息:")
366
+ print(" • API文档: 调用 Date().help() 查看")
367
+ print(" • 版本信息: 调用 get_version_info() 查看")
368
+ print(" • 功能状态: 调用 Date().get_feature_status() 查看")
369
+
370
+ except Exception as e:
371
+ print(f"\n❌ 演示过程中出现错误: {e}")
372
+ import traceback
373
+ traceback.print_exc()
374
+
375
+ if __name__ == "__main__":
376
+ main()
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ Staran 扩展功能模块
6
+ ==================
7
+
8
+ 包含v1.0.10新增的扩展功能:
9
+ - 时区支持
10
+ - 日期表达式解析
11
+ - 二十四节气计算
12
+ """
13
+
14
+ try:
15
+ from .timezone import Timezone, TimezoneInfo
16
+ TIMEZONE_AVAILABLE = True
17
+ except ImportError:
18
+ TIMEZONE_AVAILABLE = False
19
+ Timezone = None
20
+ TimezoneInfo = None
21
+
22
+ try:
23
+ from .expressions import DateExpressionParser, ParseResult
24
+ EXPRESSIONS_AVAILABLE = True
25
+ except ImportError:
26
+ EXPRESSIONS_AVAILABLE = False
27
+ DateExpressionParser = None
28
+ ParseResult = None
29
+
30
+ try:
31
+ from .solar_terms import SolarTerms, SolarTerm
32
+ SOLAR_TERMS_AVAILABLE = True
33
+ except ImportError:
34
+ SOLAR_TERMS_AVAILABLE = False
35
+ SolarTerms = None
36
+ SolarTerm = None
37
+
38
+ __all__ = [
39
+ 'Timezone',
40
+ 'TimezoneInfo',
41
+ 'DateExpressionParser',
42
+ 'ParseResult',
43
+ 'SolarTerms',
44
+ 'SolarTerm',
45
+ 'TIMEZONE_AVAILABLE',
46
+ 'EXPRESSIONS_AVAILABLE',
47
+ 'SOLAR_TERMS_AVAILABLE'
48
+ ]