From d6d786a57ac4434f7e64735eb9a05c87a74c0021 Mon Sep 17 00:00:00 2001
From: 732642856 <732642856@qq.com>
Date: Thu, 11 Jun 2026 20:37:59 +0800
Subject: [PATCH] =?UTF-8?q?v6.7.0:=20Python=20API=E6=A1=A5=E6=8E=A5=20?=
=?UTF-8?q?=E2=80=94=20Web=E5=BA=94=E7=94=A8=E5=89=8D=E5=90=8E=E7=AB=AF?=
=?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8v6.6.0=E7=B2=BE=E7=AE=97?=
=?UTF-8?q?=E5=BC=95=E6=93=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
## 新增
- jyotish_api_server.py: FastAPI式HTTP服务器(10个端点)
- POST /api/chart — 完整星盘(35种Dasha+Yoga+行星)
- POST /api/remedies — 5类补救建议
- POST /api/kp — KP分析
- POST /api/prashna — 卜卦
- POST /api/synastry — 合盘
- POST /api/sade_sati/pancha_mahapurusha/career/relationship
- GET /api/health + /api/cities
- api-bridge.js: 前端API桥接模块(自动检测+降级)
- main.js: 优先使用Python API,不可用时回退JS引擎
## 关键修复
- 前后端现在使用同一套v6.6.0精算引擎(35种Dasha, 107+ Yoga)
- Web应用不再受限于v0.1 JS引擎的有限计算能力
- 启动: python3 scripts/jyotish_api_server.py --port 5200
---
jyotish-app/api-bridge.js | 142 +++++++++++++++
jyotish-app/index.html | 1 +
jyotish-app/main.js | 24 ++-
scripts/jyotish_api_server.py | 313 ++++++++++++++++++++++++++++++++++
4 files changed, 478 insertions(+), 2 deletions(-)
create mode 100644 jyotish-app/api-bridge.js
create mode 100644 scripts/jyotish_api_server.py
diff --git a/jyotish-app/api-bridge.js b/jyotish-app/api-bridge.js
new file mode 100644
index 00000000..06bf196d
--- /dev/null
+++ b/jyotish-app/api-bridge.js
@@ -0,0 +1,142 @@
+/**
+ * API Bridge v1.0
+ * 连接前端到 Python v6.6.0 精算引擎
+ *
+ * 用法: 在 index.html 中加载此脚本后,自动检测并优先使用 Python API
+ */
+const API_BASE = 'http://localhost:5200';
+
+async function apiFetch(endpoint, body = {}) {
+ try {
+ const resp = await fetch(`${API_BASE}${endpoint}`, {
+ method: body && Object.keys(body).length > 0 ? 'POST' : 'GET',
+ headers: { 'Content-Type': 'application/json' },
+ body: body && Object.keys(body).length > 0 ? JSON.stringify(body) : undefined,
+ });
+ return await resp.json();
+ } catch (e) {
+ return null;
+ }
+}
+
+async function checkApiAvailable() {
+ const r = await apiFetch('/api/health');
+ return r && r.status === 'ok';
+}
+
+/**
+ * 使用 Python API 计算完整星盘
+ * 替代原有的 jyotish-engine.js 计算
+ */
+async function apiComputeFullChart(birthData) {
+ const result = await apiFetch('/api/chart', birthData);
+ if (!result || !result.success) {
+ throw new Error(result?.error || 'API computation failed');
+ }
+ return result;
+}
+
+/**
+ * 获取补救建议
+ */
+async function apiGetRemedies(chartData) {
+ const shadbala = {};
+ if (chartData.planets) {
+ for (const [p, d] of Object.entries(chartData.planets)) {
+ shadbala[p] = { total_rupas: 3.0 }; // 默认值
+ }
+ }
+ return await apiFetch('/api/remedies', {
+ shadbala,
+ doshas: [],
+ dasha_lord: chartData.dasha?.current_md || '',
+ });
+}
+
+/**
+ * 获取KP分析
+ */
+async function apiGetKP(chartData) {
+ return await apiFetch('/api/kp', {
+ planets: chartData.planets || {},
+ asc_sign_idx: chartData.ascendant?.sign_idx || 0,
+ });
+}
+
+/**
+ * 获取合盘分析
+ */
+async function apiGetSynastry(maleMoonDeg, femaleMoonDeg) {
+ return await apiFetch('/api/synastry', {
+ male_moon: maleMoonDeg,
+ female_moon: femaleMoonDeg,
+ });
+}
+
+/**
+ * 获取Sade Sati分析
+ */
+async function apiGetSadeSati(chartData) {
+ const moon = chartData.planets?.Moon;
+ const sun = chartData.planets?.Sun;
+ return await apiFetch('/api/sade_sati', {
+ moon_degree: moon?.lon || 0,
+ asc_degree: chartData.ascendant?.degree || 0,
+ saturn_degree: chartData.planets?.Saturn?.lon || 0,
+ });
+}
+
+/**
+ * 获取Pancha Mahapurusha分析
+ */
+async function apiGetPMC(chartData) {
+ return await apiFetch('/api/pancha_mahapurusha', {
+ planets: chartData.planets || {},
+ sun_degree: chartData.planets?.Sun?.lon || 0,
+ });
+}
+
+/**
+ * 获取事业分析
+ */
+async function apiGetCareer(chartData) {
+ return await apiFetch('/api/career', {
+ planets: chartData.planets || {},
+ asc_sign: chartData.ascendant?.sign || 'Aries',
+ });
+}
+
+/**
+ * 获取感情分析
+ */
+async function apiGetRelationship(chartData) {
+ return await apiFetch('/api/relationship', {
+ planets: chartData.planets || {},
+ asc_sign: chartData.ascendant?.sign || 'Aries',
+ });
+}
+
+/**
+ * 获取Prashna卜卦分析
+ */
+async function apiGetPrashna(chartData, question) {
+ return await apiFetch('/api/prashna', {
+ planets: chartData.planets || {},
+ question: question || 'general',
+ });
+}
+
+// 导出
+window.JyotishAPI = {
+ checkAvailable: checkApiAvailable,
+ computeChart: apiComputeFullChart,
+ getRemedies: apiGetRemedies,
+ getKP: apiGetKP,
+ getSynastry: apiGetSynastry,
+ getSadeSati: apiGetSadeSati,
+ getPMC: apiGetPMC,
+ getCareer: apiGetCareer,
+ getRelationship: apiGetRelationship,
+ getPrashna: apiGetPrashna,
+ baseUrl: API_BASE,
+};
diff --git a/jyotish-app/index.html b/jyotish-app/index.html
index 2e9ab55d..4f7949f2 100644
--- a/jyotish-app/index.html
+++ b/jyotish-app/index.html
@@ -426,6 +426,7 @@
+