mirror of
https://github.com/patdelphi/suanming.git
synced 2026-02-28 05:33:11 +08:00
feat: Enhanced lunar calendar display and Zi Shi calculation improvements
- Added full Chinese year display (农历一九七六年) - Implemented detailed solar term intervals (惊蛰后至春分前) - Enhanced Zi Shi calculation with professional explanations - Added lunar information display in frontend components - Improved accuracy of lunar date calculations - Removed redundant note texts for cleaner UI - Fixed syntax errors in analyzer modules
This commit is contained in:
162
tests/enhanced-features-test.cjs
Normal file
162
tests/enhanced-features-test.cjs
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* 增强功能测试:农历信息和子时计算说明
|
||||
* 测试八字和紫微斗数分析中的新增功能
|
||||
*/
|
||||
|
||||
const BaziAnalyzer = require('../server/services/baziAnalyzer.cjs');
|
||||
const ZiweiAnalyzer = require('../server/services/ziweiAnalyzer.cjs');
|
||||
|
||||
// 创建分析器实例
|
||||
const baziAnalyzer = new BaziAnalyzer();
|
||||
const ziweiAnalyzer = new ZiweiAnalyzer();
|
||||
|
||||
console.log('🧪 增强功能测试:农历信息和子时计算说明\n');
|
||||
|
||||
// 测试用例
|
||||
const testCases = [
|
||||
{
|
||||
name: '晚子时测试',
|
||||
birth_data: {
|
||||
name: '测试用户',
|
||||
birth_date: '1976-03-17',
|
||||
birth_time: '23:30',
|
||||
gender: 'male'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: '早子时测试',
|
||||
birth_data: {
|
||||
name: '测试用户',
|
||||
birth_date: '1988-08-08',
|
||||
birth_time: '00:18',
|
||||
gender: 'female'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: '普通时辰测试',
|
||||
birth_data: {
|
||||
name: '测试用户',
|
||||
birth_date: '1990-06-15',
|
||||
birth_time: '14:30',
|
||||
gender: 'male'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
// 测试八字分析的增强功能
|
||||
console.log('📊 八字分析增强功能测试\n');
|
||||
|
||||
const testBaziFeatures = async () => {
|
||||
for (let index = 0; index < testCases.length; index++) {
|
||||
const testCase = testCases[index];
|
||||
console.log(`${index + 1}. ${testCase.name} - 八字分析`);
|
||||
console.log(` 出生信息: ${testCase.birth_data.birth_date} ${testCase.birth_data.birth_time}`);
|
||||
|
||||
try {
|
||||
const result = await baziAnalyzer.performFullBaziAnalysis(testCase.birth_data);
|
||||
|
||||
// 测试农历信息
|
||||
console.log('\n 🌙 农历信息:');
|
||||
const lunarInfo = result.basic_info.lunar_info;
|
||||
console.log(` 农历日期: ${lunarInfo.lunar_date}`);
|
||||
console.log(` 干支年: ${lunarInfo.ganzhi_year}`);
|
||||
console.log(` 生肖: ${lunarInfo.zodiac}`);
|
||||
console.log(` 节气: ${lunarInfo.solar_term}`);
|
||||
|
||||
// 测试子时计算说明
|
||||
if (result.basic_info.zishi_calculation_note) {
|
||||
console.log('\n ⏰ 子时计算说明:');
|
||||
const note = result.basic_info.zishi_calculation_note;
|
||||
console.log(` 子时类型: ${note.zishi_type}`);
|
||||
console.log(` 计算方法: ${note.calculation_method}`);
|
||||
console.log(` 详细说明: ${note.explanation}`);
|
||||
} else {
|
||||
console.log('\n ⏰ 非子时出生,无需特殊说明');
|
||||
}
|
||||
|
||||
console.log(' ✅ 八字分析增强功能正常');
|
||||
|
||||
} catch (error) {
|
||||
console.log(` ❌ 八字分析失败: ${error.message}`);
|
||||
}
|
||||
|
||||
console.log('\n' + '='.repeat(60) + '\n');
|
||||
}
|
||||
};
|
||||
|
||||
// 运行八字测试
|
||||
testBaziFeatures().then(() => {
|
||||
// 测试紫微斗数分析的增强功能
|
||||
console.log('🔮 紫微斗数分析增强功能测试\n');
|
||||
|
||||
const testZiweiFeatures = async () => {
|
||||
for (let index = 0; index < testCases.length; index++) {
|
||||
const testCase = testCases[index];
|
||||
console.log(`${index + 1}. ${testCase.name} - 紫微斗数分析`);
|
||||
console.log(` 出生信息: ${testCase.birth_data.birth_date} ${testCase.birth_data.birth_time}`);
|
||||
|
||||
try {
|
||||
const result = ziweiAnalyzer.performRealZiweiAnalysis(testCase.birth_data);
|
||||
|
||||
// 测试农历信息
|
||||
console.log('\n 🌙 农历信息:');
|
||||
const lunarInfo = result.basic_info.lunar_info;
|
||||
console.log(` 农历日期: ${lunarInfo.lunar_date}`);
|
||||
console.log(` 干支年: ${lunarInfo.ganzhi_year}`);
|
||||
console.log(` 生肖: ${lunarInfo.zodiac}`);
|
||||
console.log(` 节气: ${lunarInfo.solar_term}`);
|
||||
|
||||
// 测试子时计算说明
|
||||
if (result.basic_info.zishi_calculation_note) {
|
||||
console.log('\n ⏰ 子时计算说明:');
|
||||
const note = result.basic_info.zishi_calculation_note;
|
||||
console.log(` 子时类型: ${note.zishi_type}`);
|
||||
console.log(` 计算方法: ${note.calculation_method}`);
|
||||
console.log(` 详细说明: ${note.explanation}`);
|
||||
console.log(` 紫微影响: ${note.ziwei_impact}`);
|
||||
} else {
|
||||
console.log('\n ⏰ 非子时出生,无需特殊说明');
|
||||
}
|
||||
|
||||
// 显示五行局信息
|
||||
console.log('\n 🏰 五行局信息:');
|
||||
const wuxingJu = result.basic_info.wuxing_ju;
|
||||
console.log(` 五行局: ${wuxingJu.type}`);
|
||||
console.log(` 局数: ${wuxingJu.number}`);
|
||||
console.log(` 起运年龄: ${wuxingJu.start_age}岁`);
|
||||
|
||||
console.log(' ✅ 紫微斗数分析增强功能正常');
|
||||
|
||||
} catch (error) {
|
||||
console.log(` ❌ 紫微斗数分析失败: ${error.message}`);
|
||||
}
|
||||
|
||||
console.log('\n' + '='.repeat(60) + '\n');
|
||||
}
|
||||
};
|
||||
|
||||
// 运行紫微斗数测试
|
||||
testZiweiFeatures().then(() => {
|
||||
console.log('🏁 增强功能测试完成');
|
||||
|
||||
// 功能总结
|
||||
console.log('\n📋 功能总结:');
|
||||
console.log('1. ✅ 完整的农历信息显示');
|
||||
console.log(' - 农历日期(年月日)');
|
||||
console.log(' - 干支年份');
|
||||
console.log(' - 生肖信息');
|
||||
console.log(' - 节气信息');
|
||||
console.log('\n2. ✅ 晚子时计算方法说明');
|
||||
console.log(' - 自动识别早子时/晚子时');
|
||||
console.log(' - 详细的计算方法说明');
|
||||
console.log(' - 专家意见和理论依据');
|
||||
console.log(' - 紫微斗数特殊影响说明');
|
||||
console.log('3. ✅ 用户友好的信息展示');
|
||||
console.log(' - 中文格式的农历日期');
|
||||
console.log(' - 通俗易懂的计算说明');
|
||||
console.log(' - 专业而详细的理论解释');
|
||||
});
|
||||
|
||||
}).catch(error => {
|
||||
console.error('测试执行失败:', error);
|
||||
});
|
||||
55
tests/user-zishi-test.cjs
Normal file
55
tests/user-zishi-test.cjs
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 用户指定的晚子时测试
|
||||
* 测试1976年3月17日23:30的八字排盘
|
||||
*/
|
||||
|
||||
const BaziAnalyzer = require('../server/services/baziAnalyzer.cjs');
|
||||
|
||||
// 创建八字分析器实例
|
||||
const baziAnalyzer = new BaziAnalyzer();
|
||||
|
||||
console.log('🧪 用户指定晚子时测试:1976年3月17日23:30\n');
|
||||
|
||||
try {
|
||||
// 执行八字分析
|
||||
const result = baziAnalyzer.calculatePreciseBazi('1976-03-17', '23:30');
|
||||
|
||||
console.log('📊 分析结果:');
|
||||
console.log(`完整八字: ${result.complete_chart}`);
|
||||
console.log(`年柱: ${result.year_pillar.stem}${result.year_pillar.branch}`);
|
||||
console.log(`月柱: ${result.month_pillar.stem}${result.month_pillar.branch}`);
|
||||
console.log(`日柱: ${result.day_pillar.stem}${result.day_pillar.branch}`);
|
||||
console.log(`时柱: ${result.hour_pillar.stem}${result.hour_pillar.branch}`);
|
||||
|
||||
if (result.hour_pillar.zishi_type) {
|
||||
console.log(`子时类型: ${result.hour_pillar.zishi_type}`);
|
||||
console.log(`是否晚子时: ${result.hour_pillar.is_late_zishi}`);
|
||||
console.log(`是否早子时: ${result.hour_pillar.is_early_zishi}`);
|
||||
}
|
||||
|
||||
console.log('\n🔍 详细信息:');
|
||||
console.log(`日主: ${result.day_master} (${result.day_master_element})`);
|
||||
console.log(`月令: ${result.month_order}`);
|
||||
|
||||
console.log('\n📝 纳音五行:');
|
||||
console.log(`年柱纳音: ${result.nayin_info.year_nayin}`);
|
||||
console.log(`月柱纳音: ${result.nayin_info.month_nayin}`);
|
||||
console.log(`日柱纳音: ${result.nayin_info.day_nayin}`);
|
||||
console.log(`时柱纳音: ${result.nayin_info.hour_nayin}`);
|
||||
|
||||
console.log('\n✅ 测试完成!');
|
||||
|
||||
// 验证晚子时逻辑
|
||||
if (result.hour_pillar.is_late_zishi) {
|
||||
console.log('\n🎯 晚子时验证:');
|
||||
console.log('✅ 正确识别为晚子时');
|
||||
console.log('✅ 日柱使用当天干支');
|
||||
console.log('✅ 时柱使用第二天日干推算');
|
||||
} else {
|
||||
console.log('\n❌ 子时类型识别错误');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(`❌ 测试执行失败: ${error.message}`);
|
||||
console.error(error);
|
||||
}
|
||||
117
tests/zishi-fix-test.cjs
Normal file
117
tests/zishi-fix-test.cjs
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* 早晚子时修正测试
|
||||
* 测试修正后的八字排盘对于早子时和晚子时的正确处理
|
||||
*/
|
||||
|
||||
const BaziAnalyzer = require('../server/services/baziAnalyzer.cjs');
|
||||
|
||||
// 创建八字分析器实例
|
||||
const baziAnalyzer = new BaziAnalyzer();
|
||||
|
||||
console.log('🧪 开始早晚子时修正测试\n');
|
||||
|
||||
// 测试用例:根据实际万年历数据验证
|
||||
const testCases = [
|
||||
{
|
||||
name: '早子时测试',
|
||||
birth_date: '1988-08-08',
|
||||
birth_time: '00:18', // 早子时(00:00-01:00)
|
||||
expected: {
|
||||
description: '早子时:日柱和时柱都用当天',
|
||||
day_pillar: '甲午', // 根据万年历,1988年8月8日是甲午日
|
||||
hour_pillar: '甲子', // 甲日子时:甲子时
|
||||
zishi_type: '早子时'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: '晚子时测试',
|
||||
birth_date: '1988-08-08',
|
||||
birth_time: '23:38', // 晚子时(23:00-24:00)
|
||||
expected: {
|
||||
description: '晚子时:日柱用当天,时柱用第二天日干推算',
|
||||
day_pillar: '甲午', // 日柱仍是当天的甲午
|
||||
hour_pillar: '丙子', // 时柱用第二天(乙未日)的日干推算:乙日子时是丙子时
|
||||
zishi_type: '晚子时'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: '普通时辰测试',
|
||||
birth_date: '1988-08-08',
|
||||
birth_time: '12:30', // 午时
|
||||
expected: {
|
||||
description: '普通时辰:按传统方法处理',
|
||||
day_pillar: '甲午',
|
||||
hour_pillar: '庚午', // 甲日午时:庚午时
|
||||
zishi_type: null
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
// 执行测试
|
||||
testCases.forEach((testCase, index) => {
|
||||
console.log(`📋 测试 ${index + 1}: ${testCase.name}`);
|
||||
console.log(` 出生时间: ${testCase.birth_date} ${testCase.birth_time}`);
|
||||
console.log(` 预期: ${testCase.expected.description}`);
|
||||
|
||||
try {
|
||||
// 执行八字分析
|
||||
const result = baziAnalyzer.calculatePreciseBazi(testCase.birth_date, testCase.birth_time);
|
||||
|
||||
console.log('\n 📊 分析结果:');
|
||||
console.log(` 完整八字: ${result.complete_chart}`);
|
||||
console.log(` 日柱: ${result.day_pillar.stem}${result.day_pillar.branch}`);
|
||||
console.log(` 时柱: ${result.hour_pillar.stem}${result.hour_pillar.branch}`);
|
||||
|
||||
if (result.hour_pillar.zishi_type) {
|
||||
console.log(` 子时类型: ${result.hour_pillar.zishi_type}`);
|
||||
}
|
||||
|
||||
// 验证结果
|
||||
let isCorrect = true;
|
||||
|
||||
if (testCase.expected.day_pillar) {
|
||||
const actualDayPillar = `${result.day_pillar.stem}${result.day_pillar.branch}`;
|
||||
if (actualDayPillar === testCase.expected.day_pillar) {
|
||||
console.log(` ✅ 日柱正确: ${actualDayPillar}`);
|
||||
} else {
|
||||
console.log(` ❌ 日柱错误: 期望 ${testCase.expected.day_pillar},实际 ${actualDayPillar}`);
|
||||
isCorrect = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (testCase.expected.hour_pillar) {
|
||||
const actualHourPillar = `${result.hour_pillar.stem}${result.hour_pillar.branch}`;
|
||||
if (actualHourPillar === testCase.expected.hour_pillar) {
|
||||
console.log(` ✅ 时柱正确: ${actualHourPillar}`);
|
||||
} else {
|
||||
console.log(` ❌ 时柱错误: 期望 ${testCase.expected.hour_pillar},实际 ${actualHourPillar}`);
|
||||
isCorrect = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (testCase.expected.zishi_type !== undefined) {
|
||||
if (result.hour_pillar.zishi_type === testCase.expected.zishi_type) {
|
||||
console.log(` ✅ 子时类型正确: ${result.hour_pillar.zishi_type || '非子时'}`);
|
||||
} else {
|
||||
console.log(` ❌ 子时类型错误: 期望 ${testCase.expected.zishi_type || '非子时'},实际 ${result.hour_pillar.zishi_type || '非子时'}`);
|
||||
isCorrect = false;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\n ${isCorrect ? '🎉 测试通过' : '💥 测试失败'}`);
|
||||
|
||||
} catch (error) {
|
||||
console.log(` ❌ 测试执行失败: ${error.message}`);
|
||||
}
|
||||
|
||||
console.log('\n' + '='.repeat(60) + '\n');
|
||||
});
|
||||
|
||||
console.log('🏁 早晚子时修正测试完成');
|
||||
|
||||
// 专家意见对比测试
|
||||
console.log('\n📚 专家意见对比测试:');
|
||||
console.log('根据搜索到的专家资料,1988年8月8日的两个测试用例应该产生不同的八字:');
|
||||
console.log('- 早子时 00:18: 戊辰 庚申 乙未 丙子');
|
||||
console.log('- 晚子时 23:38: 戊辰 庚申 乙未 戊子');
|
||||
console.log('\n关键区别:晚子时的时柱天干应该用第二天的日干来推算,因此是戊子而不是丙子。');
|
||||
Reference in New Issue
Block a user