railwise-ai 1.2.32 → 1.2.34
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.
- package/agent-pack/README.md +16 -0
- package/agent-pack/assets/agent/chief_manager.md +69 -0
- package/agent-pack/assets/agent/commercial_specialist.md +47 -0
- package/agent-pack/assets/agent/data_analyst.md +54 -0
- package/agent-pack/assets/agent/docs.md +38 -0
- package/agent-pack/assets/agent/duplicate-pr.md +25 -0
- package/agent-pack/assets/agent/qa_inspector.md +58 -0
- package/agent-pack/assets/agent/qa_reviewer.md +57 -0
- package/agent-pack/assets/agent/solution_architect.md +53 -0
- package/agent-pack/assets/agent/technical_writer.md +61 -0
- package/agent-pack/assets/agent/translator.md +34 -0
- package/agent-pack/assets/agent/triage.md +139 -0
- package/agent-pack/assets/command/ai-deps.md +24 -0
- package/agent-pack/assets/command/bid-intel.md +29 -0
- package/agent-pack/assets/command/bid-prepare.md +24 -0
- package/agent-pack/assets/command/commit.md +37 -0
- package/agent-pack/assets/command/daily-report.md +26 -0
- package/agent-pack/assets/command/data-check.md +22 -0
- package/agent-pack/assets/command/emergency-response.md +66 -0
- package/agent-pack/assets/command/issues.md +23 -0
- package/agent-pack/assets/command/learn.md +42 -0
- package/agent-pack/assets/command/monthly-report.md +35 -0
- package/agent-pack/assets/command/payment-reminder.md +27 -0
- package/agent-pack/assets/command/plan-draft.md +28 -0
- package/agent-pack/assets/command/review-response.md +23 -0
- package/agent-pack/assets/command/rmslop.md +15 -0
- package/agent-pack/assets/command/safety-check.md +20 -0
- package/agent-pack/assets/command/spellcheck.md +5 -0
- package/agent-pack/assets/command/trend-analysis.md +38 -0
- package/agent-pack/assets/command/weekly-report.md +28 -0
- package/agent-pack/assets/lib/os_api.ts +100 -0
- package/agent-pack/assets/skill/adjustment-report/SKILL.md +88 -0
- package/agent-pack/assets/skill/approval-flow-intelligence/SKILL.md +123 -0
- package/agent-pack/assets/skill/bidding-knowledge/SKILL.md +98 -0
- package/agent-pack/assets/skill/bun-file-io/SKILL.md +42 -0
- package/agent-pack/assets/skill/business-finance/SKILL.md +91 -0
- package/agent-pack/assets/skill/business-operations-analytics/SKILL.md +120 -0
- package/agent-pack/assets/skill/cad-bim-review/SKILL.md +84 -0
- package/agent-pack/assets/skill/canvas-design/SKILL.md +141 -0
- package/agent-pack/assets/skill/construction-monitoring/SKILL.md +89 -0
- package/agent-pack/assets/skill/customer-portal-brief/SKILL.md +121 -0
- package/agent-pack/assets/skill/data-analysis/SKILL.md +79 -0
- package/agent-pack/assets/skill/di-bao-monitoring/SKILL.md +680 -0
- package/agent-pack/assets/skill/di-bao-monitoring/agents/openai.yaml +4 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/crossing-static-level-input-template.csv +2 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/crossing-total-station-input-template.csv +2 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/crossing-total-station-report-template.md +59 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/daily-report-template.md +90 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/data-input-template.csv +2 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/initial-value-report-template.md +92 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/monthly-report-template.md +103 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/plan-template.md +673 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/point-alias-map-template.json +25 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/project-brief-template.md +59 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/project-summary-template.md +154 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/warning-notice-template.md +58 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets/weekly-report-template.md +49 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets//345/256/214/346/225/264/346/212/245/350/241/250/346/250/241/346/235/277.xlsx +0 -0
- package/agent-pack/assets/skill/di-bao-monitoring/assets//345/277/253/346/212/245/346/250/241/346/235/277.xlsx +0 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/crossing-static-level-report.md +115 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/crossing-total-station-report.md +206 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/data-processing.md +170 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/elevated-line.md +319 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/initial-and-summary-workflow.md +222 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/key-difficulties.md +216 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/monitoring-catalog.md +80 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/phase0-intake.md +169 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/phase1-drafting.md +185 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/phase2-internal-review.md +166 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/report-workflow.md +181 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/review-checklist.md +140 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/review-response-template.md +87 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/scoping-and-pricing.md +214 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/source-analysis.md +137 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/technical-standards.md +188 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/toc-template-A.md +142 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/toc-template-B.md +100 -0
- package/agent-pack/assets/skill/di-bao-monitoring/references/warning-workflow.md +63 -0
- package/agent-pack/assets/skill/di-bao-monitoring/scripts/build_crossing_total_station_xlsx.py +2438 -0
- package/agent-pack/assets/skill/di-bao-monitoring/scripts/evaluate_alarms.py +215 -0
- package/agent-pack/assets/skill/di-bao-monitoring/scripts/fetch_adjusted_total_station.py +946 -0
- package/agent-pack/assets/skill/di-bao-monitoring/scripts/fetch_shhh_static_level.py +556 -0
- package/agent-pack/assets/skill/di-bao-monitoring/scripts/run_crossing_4h_report.sh +141 -0
- package/agent-pack/assets/skill/di-bao-monitoring/scripts/summarize_crossing_total_station.py +303 -0
- package/agent-pack/assets/skill/docx-generation/SKILL.md +141 -0
- package/agent-pack/assets/skill/excel-operations/SKILL.md +121 -0
- package/agent-pack/assets/skill/frontend-design/SKILL.md +151 -0
- package/agent-pack/assets/skill/humanizer/SKILL.md +90 -0
- package/agent-pack/assets/skill/monitoring-design/SKILL.md +100 -0
- package/agent-pack/assets/skill/operational-monitoring/SKILL.md +135 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/checklists/archive-self-check.md +54 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/schemas/convergence-result-table.csv +5 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/schemas/horizontal-result-table.csv +3 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/schemas/settlement-result-table.csv +7 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/scripts/init-archive-tree.sh +65 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/templates/control-network-report.md +102 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/templates/daily-log.md +47 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/templates/i-angle-check.md +38 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/templates/monitoring-scheme.md +234 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/templates/period-report.md +95 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/templates/point-acceptance-record.md +51 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/templates/point-installation-record.md +38 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/templates/summary-report.md +89 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/templates/warning-bulletin.md +61 -0
- package/agent-pack/assets/skill/operational-monitoring/assets/templates/weekly-monthly-report.md +46 -0
- package/agent-pack/assets/skill/operational-monitoring/references/archive-and-delivery.md +146 -0
- package/agent-pack/assets/skill/operational-monitoring/references/baseline-network.md +131 -0
- package/agent-pack/assets/skill/operational-monitoring/references/convergence-monitoring.md +134 -0
- package/agent-pack/assets/skill/operational-monitoring/references/data-processing.md +178 -0
- package/agent-pack/assets/skill/operational-monitoring/references/horizontal-displacement.md +128 -0
- package/agent-pack/assets/skill/operational-monitoring/references/monitoring-points.md +132 -0
- package/agent-pack/assets/skill/operational-monitoring/references/monitoring-scheme.md +178 -0
- package/agent-pack/assets/skill/operational-monitoring/references/period-report.md +108 -0
- package/agent-pack/assets/skill/operational-monitoring/references/regulations-and-frequency.md +127 -0
- package/agent-pack/assets/skill/operational-monitoring/references/settlement-monitoring.md +116 -0
- package/agent-pack/assets/skill/operational-monitoring/references/summary-report.md +128 -0
- package/agent-pack/assets/skill/operational-monitoring/references/warning-and-disposal.md +118 -0
- package/agent-pack/assets/skill/ops-monitoring/SKILL.md +93 -0
- package/agent-pack/assets/skill/railwise-knowledge-curation/SKILL.md +92 -0
- package/agent-pack/assets/skill/report-dibao/SKILL.md +60 -0
- package/agent-pack/assets/skill/report-writing/SKILL.md +103 -0
- package/agent-pack/assets/skill/resource-dispatch-intelligence/SKILL.md +125 -0
- package/agent-pack/assets/skill/standard-reference/SKILL.md +101 -0
- package/agent-pack/assets/skill/weekly-work-intelligence/SKILL.md +123 -0
- package/agent-pack/assets/template/adjustment-trend.json +53 -0
- package/agent-pack/assets/template/bid-technical-proposal.json +42 -0
- package/agent-pack/assets/template/compliance-review.json +35 -0
- package/agent-pack/assets/template/daily-monitor-report.json +34 -0
- package/agent-pack/assets/template/field-data-qa.json +47 -0
- package/agent-pack/assets/template/monitoring-plan.json +28 -0
- package/agent-pack/assets/template/monthly-monitor-report.json +47 -0
- package/agent-pack/assets/template/project-ppt.json +47 -0
- package/agent-pack/assets/template/review-response.json +28 -0
- package/agent-pack/assets/template/schema.json +72 -0
- package/agent-pack/assets/template/weekly-monitor-report.json +33 -0
- package/agent-pack/assets/theme/mytheme.json +223 -0
- package/agent-pack/assets/tool/angle_convert.ts +151 -0
- package/agent-pack/assets/tool/axial_force.ts +186 -0
- package/agent-pack/assets/tool/chart_generator.ts +185 -0
- package/agent-pack/assets/tool/control_network.ts +413 -0
- package/agent-pack/assets/tool/coord_transform.ts +333 -0
- package/agent-pack/assets/tool/cpiii_adjustment.ts +446 -0
- package/agent-pack/assets/tool/cross_section.ts +356 -0
- package/agent-pack/assets/tool/deformation_rate.ts +234 -0
- package/agent-pack/assets/tool/distance_calculator.ts +239 -0
- package/agent-pack/assets/tool/excel_export.ts +494 -0
- package/agent-pack/assets/tool/format_parser.ts +181 -0
- package/agent-pack/assets/tool/github-pr-search.ts +57 -0
- package/agent-pack/assets/tool/github-pr-search.txt +10 -0
- package/agent-pack/assets/tool/github-triage.ts +113 -0
- package/agent-pack/assets/tool/github-triage.txt +6 -0
- package/agent-pack/assets/tool/inclinometer.ts +248 -0
- package/agent-pack/assets/tool/monitoring_csv.ts +120 -0
- package/agent-pack/assets/tool/os_contract_query.ts +63 -0
- package/agent-pack/assets/tool/os_dibao_project_files.ts +75 -0
- package/agent-pack/assets/tool/os_file_download_ref.ts +48 -0
- package/agent-pack/assets/tool/os_file_preview.ts +46 -0
- package/agent-pack/assets/tool/os_gbrain_think.ts +31 -0
- package/agent-pack/assets/tool/os_ppt_generate.ts +37 -0
- package/agent-pack/assets/tool/os_project_context.ts +24 -0
- package/agent-pack/assets/tool/os_report_publish.ts +28 -0
- package/agent-pack/assets/tool/os_wiki_ingest.ts +38 -0
- package/agent-pack/assets/tool/os_wiki_query.ts +26 -0
- package/agent-pack/assets/tool/pile_stakeout.ts +299 -0
- package/agent-pack/assets/tool/report_export.ts +279 -0
- package/agent-pack/assets/tool/shield_guidance.ts +311 -0
- package/agent-pack/assets/tool/standard_query.ts +391 -0
- package/agent-pack/assets/tool/survey_calculator.ts +415 -0
- package/agent-pack/assets/tool/water_level.ts +209 -0
- package/agent-pack/bin/install.js +183 -0
- package/agent-pack/package.json +695 -0
- package/package.json +14 -8
- package/postinstall.mjs +53 -22
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
/// <reference path="../env.d.ts" />
|
|
2
|
+
import { tool } from "nb-railwise/tool"
|
|
3
|
+
|
|
4
|
+
type Matrix = number[][]
|
|
5
|
+
|
|
6
|
+
const mat = {
|
|
7
|
+
zeros: (r: number, c: number): Matrix => Array.from({ length: r }, () => Array(c).fill(0) as number[]),
|
|
8
|
+
|
|
9
|
+
transpose: (a: Matrix): Matrix => a[0]!.map((_, j) => a.map((row) => row[j]!)),
|
|
10
|
+
|
|
11
|
+
mul: (a: Matrix, b: Matrix): Matrix =>
|
|
12
|
+
a.map((row) => b[0]!.map((_, j) => row.reduce((sum, val, k) => sum + val * b[k]![j]!, 0))),
|
|
13
|
+
|
|
14
|
+
mulVec: (a: Matrix, v: number[]): number[] => a.map((row) => row.reduce((sum, val, k) => sum + val * v[k]!, 0)),
|
|
15
|
+
|
|
16
|
+
add: (a: Matrix, b: Matrix): Matrix => a.map((row, i) => row.map((v, j) => v + b[i]![j]!)),
|
|
17
|
+
|
|
18
|
+
scale: (a: Matrix, s: number): Matrix => a.map((row) => row.map((v) => v * s)),
|
|
19
|
+
|
|
20
|
+
invert: (src: Matrix): Matrix | null => {
|
|
21
|
+
const n = src.length
|
|
22
|
+
const aug = src.map((row, i) => [...row, ...Array.from({ length: n }, (_, j) => (i === j ? 1 : 0))])
|
|
23
|
+
for (let col = 0; col < n; col++) {
|
|
24
|
+
let pivotRow = col
|
|
25
|
+
for (let row = col + 1; row < n; row++) {
|
|
26
|
+
if (Math.abs(aug[row]![col]!) > Math.abs(aug[pivotRow]![col]!)) pivotRow = row
|
|
27
|
+
}
|
|
28
|
+
if (Math.abs(aug[pivotRow]![col]!) < 1e-15) return null
|
|
29
|
+
;[aug[col], aug[pivotRow]] = [aug[pivotRow]!, aug[col]!]
|
|
30
|
+
const pivot = aug[col]![col]!
|
|
31
|
+
for (let j = col; j < 2 * n; j++) aug[col]![j]! /= pivot
|
|
32
|
+
for (let row = 0; row < n; row++) {
|
|
33
|
+
if (row === col) continue
|
|
34
|
+
const factor = aug[row]![col]!
|
|
35
|
+
for (let j = col; j < 2 * n; j++) aug[row]![j]! -= factor * aug[col]![j]!
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return aug.map((row) => row.slice(n))
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const deg2rad = (d: number) => (d * Math.PI) / 180
|
|
43
|
+
const rad2deg = (r: number) => (r * 180) / Math.PI
|
|
44
|
+
|
|
45
|
+
export const free_station_resection = tool({
|
|
46
|
+
description:
|
|
47
|
+
"自由测站后方交会计算。根据全站仪对多个已知CPIII点的观测(方向+距离),解算自由测站的坐标和方位角定向,并进行精度评定。CPIII测量中每个测站设站计算的基础工具。data_analyst 处理CPIII自由测站数据时必须调用此工具。",
|
|
48
|
+
args: {
|
|
49
|
+
stationId: tool.schema.string().describe("测站编号"),
|
|
50
|
+
approximatePosition: tool.schema
|
|
51
|
+
.object({
|
|
52
|
+
x: tool.schema.number().describe("测站近似X坐标(m)"),
|
|
53
|
+
y: tool.schema.number().describe("测站近似Y坐标(m)"),
|
|
54
|
+
z: tool.schema.number().describe("测站近似高程(m)"),
|
|
55
|
+
})
|
|
56
|
+
.optional()
|
|
57
|
+
.describe("测站近似坐标(不提供则自动计算初始值)"),
|
|
58
|
+
instrumentHeight: tool.schema.number().positive().describe("仪器高(m)"),
|
|
59
|
+
targets: tool.schema
|
|
60
|
+
.array(
|
|
61
|
+
tool.schema.object({
|
|
62
|
+
id: tool.schema.string().describe("CPIII目标点编号"),
|
|
63
|
+
x: tool.schema.number().describe("已知X坐标(m)"),
|
|
64
|
+
y: tool.schema.number().describe("已知Y坐标(m)"),
|
|
65
|
+
z: tool.schema.number().describe("已知高程(m)"),
|
|
66
|
+
prismHeight: tool.schema.number().describe("棱镜高(m)"),
|
|
67
|
+
horizDirection: tool.schema.number().describe("水平方向观测值(度,十进制)"),
|
|
68
|
+
vertAngle: tool.schema.number().describe("竖直角(度,天顶距)"),
|
|
69
|
+
slopeDist: tool.schema.number().positive().describe("斜距(m)"),
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
.min(3)
|
|
73
|
+
.describe("观测目标点(至少3个CPIII点)"),
|
|
74
|
+
distanceSigma: tool.schema.number().positive().default(0.001).describe("测距先验中误差(m),默认1mm"),
|
|
75
|
+
directionSigma: tool.schema.number().positive().default(1).describe("方向先验中误差(秒),默认1″"),
|
|
76
|
+
maxIterations: tool.schema.number().int().positive().default(10).describe("最大迭代次数"),
|
|
77
|
+
},
|
|
78
|
+
async execute(args) {
|
|
79
|
+
const rho = 206264.806
|
|
80
|
+
const targets = args.targets
|
|
81
|
+
|
|
82
|
+
// Compute horizontal distance and height difference from slope distance and vertical angle
|
|
83
|
+
const processed = targets.map((t) => {
|
|
84
|
+
const zenith = deg2rad(t.vertAngle)
|
|
85
|
+
const hDist = t.slopeDist * Math.sin(zenith)
|
|
86
|
+
const vDiff = t.slopeDist * Math.cos(zenith) + args.instrumentHeight - t.prismHeight
|
|
87
|
+
return { ...t, hDist, heightToTarget: t.z + t.prismHeight }
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// Initial approximation: centroid of intersection from first two targets
|
|
91
|
+
let sx: number, sy: number, sz: number
|
|
92
|
+
if (args.approximatePosition) {
|
|
93
|
+
sx = args.approximatePosition.x
|
|
94
|
+
sy = args.approximatePosition.y
|
|
95
|
+
sz = args.approximatePosition.z
|
|
96
|
+
} else {
|
|
97
|
+
sx = targets.reduce((s, t) => s + t.x, 0) / targets.length
|
|
98
|
+
sy = targets.reduce((s, t) => s + t.y, 0) / targets.length
|
|
99
|
+
sz = targets.reduce((s, t) => s + t.z, 0) / targets.length
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Unknowns: [dx, dy, dz, dOrientation] (4 parameters)
|
|
103
|
+
let orientation = 0
|
|
104
|
+
const nObs = processed.length * 2 // direction + distance per target
|
|
105
|
+
const nUnknowns = 4
|
|
106
|
+
|
|
107
|
+
let sigma0 = 0
|
|
108
|
+
let Qxx: Matrix | null = null
|
|
109
|
+
|
|
110
|
+
for (let iter = 0; iter < args.maxIterations; iter++) {
|
|
111
|
+
const A: number[][] = []
|
|
112
|
+
const L: number[] = []
|
|
113
|
+
const P: number[][] = mat.zeros(nObs, nObs)
|
|
114
|
+
|
|
115
|
+
for (let i = 0; i < processed.length; i++) {
|
|
116
|
+
const t = processed[i]!
|
|
117
|
+
const dx = t.x - sx
|
|
118
|
+
const dy = t.y - sy
|
|
119
|
+
const dist0 = Math.sqrt(dx * dx + dy * dy)
|
|
120
|
+
const az0 = ((Math.atan2(dx, dy) * 180) / Math.PI + 360) % 360
|
|
121
|
+
|
|
122
|
+
// Direction observation equation
|
|
123
|
+
let dirDiff = t.horizDirection + orientation - az0
|
|
124
|
+
if (dirDiff > 180) dirDiff -= 360
|
|
125
|
+
if (dirDiff < -180) dirDiff += 360
|
|
126
|
+
const dirDiffRad = (dirDiff * Math.PI) / 180
|
|
127
|
+
|
|
128
|
+
// A matrix row for direction: partial derivatives w.r.t. [sx, sy, sz, orientation]
|
|
129
|
+
// dAz/dsx = dy / (dist^2), dAz/dsy = -dx / (dist^2), dAz/dsz = 0, dAz/dOri = 1
|
|
130
|
+
const dirRow = [dy / (dist0 * dist0), -dx / (dist0 * dist0), 0, 1]
|
|
131
|
+
A.push(dirRow)
|
|
132
|
+
L.push(dirDiffRad)
|
|
133
|
+
P[i * 2]![i * 2] = 1 / (args.directionSigma / rho) ** 2
|
|
134
|
+
|
|
135
|
+
// Distance observation equation
|
|
136
|
+
const distDiff = t.hDist - dist0
|
|
137
|
+
// dDist/dsx = -dx/dist, dDist/dsy = -dy/dist, dDist/dsz = 0, dDist/dOri = 0
|
|
138
|
+
const distRow = [-dx / dist0, -dy / dist0, 0, 0]
|
|
139
|
+
A.push(distRow)
|
|
140
|
+
L.push(distDiff)
|
|
141
|
+
P[i * 2 + 1]![i * 2 + 1] = 1 / args.distanceSigma ** 2
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const AT = mat.transpose(A)
|
|
145
|
+
const ATP = mat.mul(AT, P)
|
|
146
|
+
const N = mat.mul(ATP, A)
|
|
147
|
+
const b = mat.mulVec(ATP, L)
|
|
148
|
+
|
|
149
|
+
Qxx = mat.invert(N)
|
|
150
|
+
if (!Qxx) return JSON.stringify({ error: "法方程奇异,检查观测数据和CPIII点分布。" })
|
|
151
|
+
|
|
152
|
+
const X = mat.mulVec(Qxx, b)
|
|
153
|
+
|
|
154
|
+
sx += X[0]!
|
|
155
|
+
sy += X[1]!
|
|
156
|
+
sz += X[2]!
|
|
157
|
+
orientation += (X[3]! * 180) / Math.PI
|
|
158
|
+
|
|
159
|
+
const V = mat.mulVec(A, X).map((v, i) => v - L[i]!)
|
|
160
|
+
const VTPV = V.reduce((sum, v, i) => sum + v * P[i]![i]! * v, 0)
|
|
161
|
+
const redundancy = nObs - nUnknowns
|
|
162
|
+
sigma0 = redundancy > 0 ? Math.sqrt(VTPV / redundancy) : 0
|
|
163
|
+
|
|
164
|
+
if (Math.abs(X[0]!) < 0.00001 && Math.abs(X[1]!) < 0.00001) break
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Height from vertical observations
|
|
168
|
+
const heights = processed.map((t) => {
|
|
169
|
+
const zenith = deg2rad(t.vertAngle)
|
|
170
|
+
return t.z + t.prismHeight - (t.slopeDist * Math.cos(zenith) + args.instrumentHeight)
|
|
171
|
+
})
|
|
172
|
+
const avgHeight = heights.reduce((s, h) => s + h, 0) / heights.length
|
|
173
|
+
const heightRmse = Math.sqrt(
|
|
174
|
+
heights.reduce((s, h) => s + (h - avgHeight) ** 2, 0) / Math.max(heights.length - 1, 1),
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
const sigmaX = Qxx ? sigma0 * Math.sqrt(Math.abs(Qxx[0]![0]!)) : 0
|
|
178
|
+
const sigmaY = Qxx ? sigma0 * Math.sqrt(Math.abs(Qxx[1]![1]!)) : 0
|
|
179
|
+
const sigmaP = Math.sqrt(sigmaX * sigmaX + sigmaY * sigmaY)
|
|
180
|
+
const sigmaOri = Qxx ? sigma0 * Math.sqrt(Math.abs(Qxx[3]![3]!)) * rho : 0
|
|
181
|
+
|
|
182
|
+
// Target residuals
|
|
183
|
+
const targetResiduals = processed.map((t) => {
|
|
184
|
+
const dx = t.x - sx
|
|
185
|
+
const dy = t.y - sy
|
|
186
|
+
const dist0 = Math.sqrt(dx * dx + dy * dy)
|
|
187
|
+
const az0 = ((Math.atan2(dx, dy) * 180) / Math.PI + 360) % 360
|
|
188
|
+
let dirRes = t.horizDirection + orientation - az0
|
|
189
|
+
if (dirRes > 180) dirRes -= 360
|
|
190
|
+
if (dirRes < -180) dirRes += 360
|
|
191
|
+
return {
|
|
192
|
+
id: t.id,
|
|
193
|
+
direction_residual_arcsec: Number((dirRes * 3600).toFixed(2)),
|
|
194
|
+
distance_residual_mm: Number(((t.hDist - dist0) * 1000).toFixed(2)),
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
orientation = ((orientation % 360) + 360) % 360
|
|
199
|
+
|
|
200
|
+
return JSON.stringify({
|
|
201
|
+
station_id: args.stationId,
|
|
202
|
+
position: {
|
|
203
|
+
x: Number(sx.toFixed(4)),
|
|
204
|
+
y: Number(sy.toFixed(4)),
|
|
205
|
+
z: Number(avgHeight.toFixed(4)),
|
|
206
|
+
},
|
|
207
|
+
orientation_deg: Number(orientation.toFixed(6)),
|
|
208
|
+
instrument_height_m: args.instrumentHeight,
|
|
209
|
+
precision: {
|
|
210
|
+
sigma_x_mm: Number((sigmaX * 1000).toFixed(3)),
|
|
211
|
+
sigma_y_mm: Number((sigmaY * 1000).toFixed(3)),
|
|
212
|
+
sigma_point_mm: Number((sigmaP * 1000).toFixed(3)),
|
|
213
|
+
sigma_height_mm: Number((heightRmse * 1000).toFixed(3)),
|
|
214
|
+
sigma_orientation_arcsec: Number(sigmaOri.toFixed(2)),
|
|
215
|
+
unit_weight_rmse: Number(sigma0.toFixed(6)),
|
|
216
|
+
},
|
|
217
|
+
target_count: targets.length,
|
|
218
|
+
target_residuals: targetResiduals,
|
|
219
|
+
message: `✅ ${args.stationId} 自由测站解算:(${sx.toFixed(4)}, ${sy.toFixed(4)}, ${avgHeight.toFixed(4)}),点位σ=${(sigmaP * 1000).toFixed(3)}mm,定向σ=${sigmaOri.toFixed(2)}″`,
|
|
220
|
+
})
|
|
221
|
+
},
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
export const cpiii_network_adjustment = tool({
|
|
225
|
+
description:
|
|
226
|
+
"CPIII轨道控制网平差计算。根据多个自由测站的解算结果和CPIII点的约束条件,进行整网平差,输出所有CPIII点的最终坐标和精度。用于轨道铺设前的CPIII网复测和精度评估。data_analyst 处理CPIII整网数据时必须调用此工具。",
|
|
227
|
+
args: {
|
|
228
|
+
knownPoints: tool.schema
|
|
229
|
+
.array(
|
|
230
|
+
tool.schema.object({
|
|
231
|
+
id: tool.schema.string().describe("点号"),
|
|
232
|
+
x: tool.schema.number().describe("X坐标(m)"),
|
|
233
|
+
y: tool.schema.number().describe("Y坐标(m)"),
|
|
234
|
+
z: tool.schema.number().describe("高程(m)"),
|
|
235
|
+
}),
|
|
236
|
+
)
|
|
237
|
+
.min(2)
|
|
238
|
+
.describe("约束点(高等级控制点,如CPII或线路控制点)"),
|
|
239
|
+
cpiii_points: tool.schema
|
|
240
|
+
.array(
|
|
241
|
+
tool.schema.object({
|
|
242
|
+
id: tool.schema.string().describe("CPIII点号"),
|
|
243
|
+
x0: tool.schema.number().describe("近似X坐标(m)"),
|
|
244
|
+
y0: tool.schema.number().describe("近似Y坐标(m)"),
|
|
245
|
+
z0: tool.schema.number().describe("近似高程(m)"),
|
|
246
|
+
}),
|
|
247
|
+
)
|
|
248
|
+
.min(4)
|
|
249
|
+
.describe("待求CPIII点及近似坐标"),
|
|
250
|
+
distanceObs: tool.schema
|
|
251
|
+
.array(
|
|
252
|
+
tool.schema.object({
|
|
253
|
+
from: tool.schema.string().describe("起点(测站或CPIII点)"),
|
|
254
|
+
to: tool.schema.string().describe("终点(CPIII点)"),
|
|
255
|
+
distance: tool.schema.number().positive().describe("观测边长(m)"),
|
|
256
|
+
sigma: tool.schema.number().positive().default(0.001).describe("中误差(m)"),
|
|
257
|
+
}),
|
|
258
|
+
)
|
|
259
|
+
.describe("边长观测值"),
|
|
260
|
+
directionObs: tool.schema
|
|
261
|
+
.array(
|
|
262
|
+
tool.schema.object({
|
|
263
|
+
station: tool.schema.string().describe("测站"),
|
|
264
|
+
target: tool.schema.string().describe("目标"),
|
|
265
|
+
direction: tool.schema.number().describe("方向值(度)"),
|
|
266
|
+
sigma: tool.schema.number().positive().default(1).describe("中误差(秒)"),
|
|
267
|
+
}),
|
|
268
|
+
)
|
|
269
|
+
.optional()
|
|
270
|
+
.describe("方向观测值"),
|
|
271
|
+
heightObs: tool.schema
|
|
272
|
+
.array(
|
|
273
|
+
tool.schema.object({
|
|
274
|
+
from: tool.schema.string(),
|
|
275
|
+
to: tool.schema.string(),
|
|
276
|
+
heightDiff: tool.schema.number().describe("高差(m)"),
|
|
277
|
+
sigma: tool.schema.number().positive().default(0.0005).describe("中误差(m)"),
|
|
278
|
+
}),
|
|
279
|
+
)
|
|
280
|
+
.optional()
|
|
281
|
+
.describe("高差观测值"),
|
|
282
|
+
requiredAccuracy: tool.schema
|
|
283
|
+
.object({
|
|
284
|
+
plane_mm: tool.schema.number().positive().default(1).describe("平面精度要求(mm),CPIII规范通常1mm"),
|
|
285
|
+
height_mm: tool.schema.number().positive().default(1).describe("高程精度要求(mm),CPIII规范通常1mm"),
|
|
286
|
+
})
|
|
287
|
+
.optional()
|
|
288
|
+
.describe("精度指标"),
|
|
289
|
+
},
|
|
290
|
+
async execute(args) {
|
|
291
|
+
const accuracy = args.requiredAccuracy ?? { plane_mm: 1, height_mm: 1 }
|
|
292
|
+
const coordMap = new Map<string, { x: number; y: number; z: number; known: boolean }>()
|
|
293
|
+
for (const p of args.knownPoints) coordMap.set(p.id, { x: p.x, y: p.y, z: p.z, known: true })
|
|
294
|
+
for (const p of args.cpiii_points) coordMap.set(p.id, { x: p.x0, y: p.y0, z: p.z0, known: false })
|
|
295
|
+
|
|
296
|
+
const unknownIds = args.cpiii_points.map((p) => p.id)
|
|
297
|
+
const u = unknownIds.length * 2
|
|
298
|
+
|
|
299
|
+
// Plane adjustment (same algorithm as control_network but tailored for CPIII)
|
|
300
|
+
const maxIter = 10
|
|
301
|
+
let sigma0 = 0
|
|
302
|
+
let Qxx: Matrix | null = null
|
|
303
|
+
|
|
304
|
+
for (let iter = 0; iter < maxIter; iter++) {
|
|
305
|
+
const rows: Array<{ Arow: number[]; l: number; weight: number }> = []
|
|
306
|
+
|
|
307
|
+
for (const obs of args.distanceObs) {
|
|
308
|
+
const pF = coordMap.get(obs.from)
|
|
309
|
+
const pT = coordMap.get(obs.to)
|
|
310
|
+
if (!pF || !pT) continue
|
|
311
|
+
|
|
312
|
+
const dx = pT.x - pF.x
|
|
313
|
+
const dy = pT.y - pF.y
|
|
314
|
+
const s0 = Math.sqrt(dx * dx + dy * dy)
|
|
315
|
+
if (s0 < 0.001) continue
|
|
316
|
+
|
|
317
|
+
const Arow = new Array(u).fill(0)
|
|
318
|
+
const fIdx = unknownIds.indexOf(obs.from)
|
|
319
|
+
const tIdx = unknownIds.indexOf(obs.to)
|
|
320
|
+
|
|
321
|
+
if (fIdx >= 0) {
|
|
322
|
+
Arow[fIdx * 2] = -dx / s0
|
|
323
|
+
Arow[fIdx * 2 + 1] = -dy / s0
|
|
324
|
+
}
|
|
325
|
+
if (tIdx >= 0) {
|
|
326
|
+
Arow[tIdx * 2] = dx / s0
|
|
327
|
+
Arow[tIdx * 2 + 1] = dy / s0
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
rows.push({ Arow, l: obs.distance - s0, weight: 1 / obs.sigma ** 2 })
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const n = rows.length
|
|
334
|
+
if (n < u / 2) return JSON.stringify({ error: `观测数不足,需至少 ${Math.ceil(u / 2)} 个。` })
|
|
335
|
+
|
|
336
|
+
const A = rows.map((r) => r.Arow)
|
|
337
|
+
const P = mat.zeros(n, n)
|
|
338
|
+
rows.forEach((r, i) => {
|
|
339
|
+
P[i]![i] = r.weight
|
|
340
|
+
})
|
|
341
|
+
const L = rows.map((r) => r.l)
|
|
342
|
+
|
|
343
|
+
const AT = mat.transpose(A)
|
|
344
|
+
const N = mat.mul(mat.mul(AT, P), A)
|
|
345
|
+
const b = mat.mulVec(mat.mul(AT, P), L)
|
|
346
|
+
|
|
347
|
+
Qxx = mat.invert(N)
|
|
348
|
+
if (!Qxx) return JSON.stringify({ error: "法方程奇异。" })
|
|
349
|
+
|
|
350
|
+
const X = mat.mulVec(Qxx, b)
|
|
351
|
+
|
|
352
|
+
let maxCorr = 0
|
|
353
|
+
for (let i = 0; i < unknownIds.length; i++) {
|
|
354
|
+
const p = coordMap.get(unknownIds[i]!)!
|
|
355
|
+
p.x += X[i * 2]!
|
|
356
|
+
p.y += X[i * 2 + 1]!
|
|
357
|
+
maxCorr = Math.max(maxCorr, Math.abs(X[i * 2]!), Math.abs(X[i * 2 + 1]!))
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const V = mat.mulVec(A, X).map((v, i) => v - L[i]!)
|
|
361
|
+
const VTPV = V.reduce((sum, v, i) => sum + v * P[i]![i]! * v, 0)
|
|
362
|
+
sigma0 = n - u / 2 > 0 ? Math.sqrt(VTPV / (n - u / 2)) : 0
|
|
363
|
+
|
|
364
|
+
if (maxCorr < 0.00001) break
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Height adjustment (simple leveling if height observations provided)
|
|
368
|
+
if (args.heightObs && args.heightObs.length > 0) {
|
|
369
|
+
const hKnown = new Map(args.knownPoints.map((p) => [p.id, p.z]))
|
|
370
|
+
const hUnknown = unknownIds.filter((id) => !hKnown.has(id))
|
|
371
|
+
const hU = hUnknown.length
|
|
372
|
+
|
|
373
|
+
if (args.heightObs.length >= hU) {
|
|
374
|
+
const A = mat.zeros(args.heightObs.length, hU)
|
|
375
|
+
const P = mat.zeros(args.heightObs.length, args.heightObs.length)
|
|
376
|
+
const L: number[] = []
|
|
377
|
+
|
|
378
|
+
args.heightObs.forEach((obs, i) => {
|
|
379
|
+
const fIdx = hUnknown.indexOf(obs.from)
|
|
380
|
+
const tIdx = hUnknown.indexOf(obs.to)
|
|
381
|
+
if (fIdx >= 0) A[i]![fIdx] = -1
|
|
382
|
+
if (tIdx >= 0) A[i]![tIdx] = 1
|
|
383
|
+
P[i]![i] = 1 / obs.sigma ** 2
|
|
384
|
+
|
|
385
|
+
const fH = hKnown.get(obs.from) ?? coordMap.get(obs.from)?.z ?? 0
|
|
386
|
+
const tH = hKnown.get(obs.to) ?? coordMap.get(obs.to)?.z ?? 0
|
|
387
|
+
L.push(obs.heightDiff - (tH - fH))
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
const AT = mat.transpose(A)
|
|
391
|
+
const N = mat.mul(mat.mul(AT, P), A)
|
|
392
|
+
const QH = mat.invert(N)
|
|
393
|
+
if (QH) {
|
|
394
|
+
const X = mat.mulVec(QH, mat.mulVec(mat.mul(AT, P), L))
|
|
395
|
+
hUnknown.forEach((id, i) => {
|
|
396
|
+
const p = coordMap.get(id)!
|
|
397
|
+
p.z += X[i]!
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// Results
|
|
404
|
+
const results = unknownIds.map((id, i) => {
|
|
405
|
+
const p = coordMap.get(id)!
|
|
406
|
+
const qx = Qxx ? Math.abs(Qxx[i * 2]![i * 2]!) : 0
|
|
407
|
+
const qy = Qxx ? Math.abs(Qxx[i * 2 + 1]![i * 2 + 1]!) : 0
|
|
408
|
+
const sigmaX = sigma0 * Math.sqrt(qx) * 1000
|
|
409
|
+
const sigmaY = sigma0 * Math.sqrt(qy) * 1000
|
|
410
|
+
const sigmaP = Math.sqrt(sigmaX ** 2 + sigmaY ** 2)
|
|
411
|
+
|
|
412
|
+
return {
|
|
413
|
+
id,
|
|
414
|
+
x: Number(p.x.toFixed(4)),
|
|
415
|
+
y: Number(p.y.toFixed(4)),
|
|
416
|
+
z: Number(p.z.toFixed(4)),
|
|
417
|
+
sigma_x_mm: Number(sigmaX.toFixed(3)),
|
|
418
|
+
sigma_y_mm: Number(sigmaY.toFixed(3)),
|
|
419
|
+
sigma_point_mm: Number(sigmaP.toFixed(3)),
|
|
420
|
+
plane_pass: sigmaP <= accuracy.plane_mm,
|
|
421
|
+
}
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
const maxSigma = Math.max(...results.map((r) => r.sigma_point_mm))
|
|
425
|
+
const passCount = results.filter((r) => r.plane_pass).length
|
|
426
|
+
|
|
427
|
+
return JSON.stringify({
|
|
428
|
+
method: "CPIII轨道控制网整网平差",
|
|
429
|
+
constraint_points: args.knownPoints.length,
|
|
430
|
+
cpiii_points: unknownIds.length,
|
|
431
|
+
total_distance_obs: args.distanceObs.length,
|
|
432
|
+
total_height_obs: args.heightObs?.length ?? 0,
|
|
433
|
+
unit_weight_rmse: Number(sigma0.toFixed(6)),
|
|
434
|
+
max_point_rmse_mm: maxSigma,
|
|
435
|
+
accuracy_requirement: accuracy,
|
|
436
|
+
pass_rate: `${passCount}/${results.length}`,
|
|
437
|
+
all_pass: passCount === results.length,
|
|
438
|
+
adjusted_points: results,
|
|
439
|
+
assessment:
|
|
440
|
+
passCount === results.length
|
|
441
|
+
? `✅ CPIII网平差合格:所有点位中误差 ≤ ${accuracy.plane_mm}mm,最大 ${maxSigma.toFixed(3)}mm`
|
|
442
|
+
: `⚠️ ${results.length - passCount}个CPIII点精度不满足 ${accuracy.plane_mm}mm 要求,最大 ${maxSigma.toFixed(3)}mm,建议补测`,
|
|
443
|
+
message: `✅ CPIII平差完成:${unknownIds.length}点,σ₀=${sigma0.toFixed(4)},最大点位σ=${maxSigma.toFixed(3)}mm,合格率 ${passCount}/${results.length}`,
|
|
444
|
+
})
|
|
445
|
+
},
|
|
446
|
+
})
|