3 次代碼提交 612f4b3e2f ... 09c1c44b82

作者 SHA1 備註 提交日期
  raylu 09c1c44b82 plan: estimate STL travel time 2 周之前
  raylu 93119e64ca cloudflare worker 2 周之前
  raylu 612f4b3e2f cloudflare worker 2 周之前
共有 2 個文件被更改,包括 18 次插入10 次删除
  1. 1 1
      cf-worker/wrangler.toml
  2. 17 9
      ts/plan.ts

+ 1 - 1
cf-worker/wrangler.toml

@@ -4,7 +4,7 @@ main = 'src/entry.py'
 compatibility_date = '2026-07-12'
 compatibility_flags = ['python_workers']
 routes = [
-  {zone_name = 'raylu.net', pattern = 'prun.raylu.net/gy-694c'}
+	{zone_name = 'raylu.net', pattern = 'prun.raylu.net/gy-694c'}
 ]
 
 [secrets]

+ 17 - 9
ts/plan.ts

@@ -62,7 +62,7 @@ async function _render(shareUUID: string, cx: string) {
 		cachedFetchJSON('https://api.prunplanner.org/data/materials/'),
 		cachedFetchJSON('/graph_data.json'),
 	]);
-	const planet: Planet = await cachedFetchJSON(`https://api.prunplanner.org/data/planet/${plan.plan_details.planet_natural_id}/`);
+	const planet: PPPlanet = await cachedFetchJSON(`https://api.prunplanner.org/data/planet/${plan.plan_details.planet_natural_id}/`);
 	const planExperts = new Map<Expertise, number>(plan.plan_details.plan_data.experts.map(
 			e => [e.type.toUpperCase() as Expertise, e.amount]));
 	const buildingExpertise = new Map<string, Expertise>(buildings.map(b => [b.building_ticker, b.expertise]));
@@ -71,7 +71,7 @@ async function _render(shareUUID: string, cx: string) {
 			.map((ex) => [ex.ticker, ex.sum_traded_7d / 7]));
 	const materials = new Map<string, Material>(materialList.map(m => [m.ticker, m]));
 
-	const oneWayHours = travel(graph.edges, planet.system_id, cx);
+	const oneWayHours = await travel(graph.edges, planet.system_id, planet.planet_natural_id, cx);
 
 	const planInput = new Counter();
 	const planOutput = new Counter();
@@ -132,12 +132,16 @@ async function _render(shareUUID: string, cx: string) {
 	}
 }
 
-function travel(edges: Edge[], system: string, cx: string): number | null {
+async function travel(edges: Edge[], system: string, planet_name: string, cx: string): Promise<number> {
 	const {parsecs, jumps} = ftlDistance(edges, system, cx);
-	if (jumps === 0)
-		return null;
-	// SCB JMPs at 4pc/hr. RCT CHRGs in 7m30s. 30m DEP, 1.5hr APP+(TO/LAND)
-	return Math.round(parsecs / 4 + (jumps - 1) * 0.125 + 2);
+	if (jumps === 0) { // STL
+		const planet: FIOPlanet = await cachedFetchJSON('https://api.fnar.net/planet/' + planet_name);
+		const km =  planet.SemiMajorAxis / 1000;
+		// ENG at 750 SF usage (50% of an SSL) TRAs at ~300,000,000 km/h
+		return Math.ceil(km / 300_000_000);
+	} else // FTL
+		// SCB JMPs at 4pc/hr. RCT CHRGs in 7m30s. 30m DEP, 1.5hr APP+(TO/LAND)
+		return Math.ceil(parsecs / 4 + (jumps - 1) * 0.125 + 2);
 }
 
 /** dijkstra to find the shortest FTL route from system to CX */
@@ -188,7 +192,7 @@ function ftlDistance(edges: Edge[], system: string, cx: string): {parsecs: numbe
 }
 
 function calcBuilding(recipes: Map<string, Recipe>, building: PlanBuilding, cogc: boolean, experts: number,
-		planet: Planet): {input: Counter, output: Counter} {
+		planet: PPPlanet): {input: Counter, output: Counter} {
 	let efficiency = expertBonus[experts];
 	if (cogc)
 		efficiency *= 1.25;
@@ -321,7 +325,7 @@ interface Edge {
 	distance: number
 }
 
-interface Planet {
+interface PPPlanet {
 	planet_natural_id: string
 	system_id: string
 	fertility: number
@@ -330,3 +334,7 @@ interface Planet {
 		daily_extraction: number
 	}>
 }
+
+interface FIOPlanet {
+	SemiMajorAxis: number
+}