oltc-selector 2.0.0 → 2.2.0

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.
Files changed (3) hide show
  1. package/README.md +3 -2
  2. package/bin/oltc.js +172 -25
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  填工况,给出 2025 目录里**最低满足**的型号。网页和 `oltc` CLI 共用同一份 `selectOltc` 引擎。
4
4
 
5
- **CLI:** `npx -y oltc-selector@2.0.0`,命令是 `oltc`。Agent 技能包另放,不在这个仓库里。
5
+ **CLI:** `npx -y oltc-selector@2.2.0`,命令是 `oltc`。Agent 技能包另放,不在这个仓库里。
6
6
  **网页:** [oltc-selector.vercel.app](https://oltc-selector.vercel.app/) · [GitHub Pages](https://erict16.github.io/oltc-selector/)
7
7
 
8
8
  私人辅助,不是厂家官网。型号是起点,出 OS 前要工程确认。
@@ -52,6 +52,7 @@ oltc --mva 125 --kind auto --hv 225 --mv 115 --tap junction
52
52
  | `--oil` / `--vacuum` | Switching medium | vacuum (on-load) |
53
53
  | `--contact` | OCTC contact e.g. `6x5` | |
54
54
  | `--json` | Machine output | |
55
+ | `--no-update-check` | Skip the daily npm check. A newer version only prints a notice on stderr; nothing is installed. `OLTC_NO_UPDATE_CHECK=1` or `CI=1` also skip it. | check on |
55
56
 
56
57
  `--structure auto` and omitting `--octc` match the web first paint: on-load, in-tank vacuum, minimum-adequate ranking.
57
58
 
@@ -69,7 +70,7 @@ oltc --mva 125 --kind auto --hv 225 --mv 115 --tap junction
69
70
 
70
71
  ## Web app
71
72
 
72
- 预选 66 / 110 / 220 kV 带常用工况。默认真变压器容量,星/角推出 Imax(最低分接和安全系数)。调压侧电压推出 Um。点「选型」之后才出型号。
73
+ 预选 66 / 110 / 220 kV 带常用工况。默认真变压器容量,星/角推出 Imax(最低分接和安全系数)。调压侧电压推出 Um。型号随参数实时更新,结果卡把工况和型号额定并排列出(电流、级电压、级容量、开关绝缘)。开关一组默认折叠,折叠时一行显示当前取值。手机上型号固定在底栏,点箭头跳到完整结果。
73
74
 
74
75
  ```bash
75
76
  npm install
package/bin/oltc.js CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // lib/appVersion.ts
4
+ var APP_VERSION = "2.2.0";
5
+
3
6
  // lib/decimal.ts
4
7
  var GROUPED = /^\d{1,3}([,,]\d{3})+$/;
5
8
  var PLAIN = /^\d*\.?\d*$/;
@@ -202,7 +205,7 @@ function resolveTapFields(input) {
202
205
  return row != null && row.pitch === pitch2;
203
206
  };
204
207
  if (reg === "linear") {
205
- const positions2 = input.positions ?? 9;
208
+ const positions2 = input.positions ?? (input.plusMinusSteps != null && input.plusMinusSteps > 0 ? 2 * input.plusMinusSteps + 1 : 9);
206
209
  const pitch2 = input.pitch ?? defaultPitch(positions2, reg);
207
210
  const mid2 = 0;
208
211
  return {
@@ -2092,17 +2095,17 @@ function deriveDuty(spec) {
2092
2095
  umKv = catalogueUmFromRatedKv(spec.tapKv);
2093
2096
  umRule = "line";
2094
2097
  }
2098
+ if (spec.earthUmKv != null && spec.earthUmKv > 0) {
2099
+ umKv = spec.earthUmKv;
2100
+ umRule = "explicit";
2101
+ umAssumed = false;
2102
+ }
2095
2103
  if (!Number.isFinite(umKv) || umKv > 363) {
2096
2104
  return fail(
2097
2105
  "\u7535\u538B\u8D85\u51FA\u76EE\u5F55\uFF1A\u5F00\u5173\u6700\u9AD8 Um 363 kV\u3002",
2098
2106
  "Voltage above the catalogue: the highest switch class is Um 363 kV."
2099
2107
  );
2100
2108
  }
2101
- if (spec.earthUmKv != null && spec.earthUmKv > 0) {
2102
- umKv = spec.earthUmKv;
2103
- umRule = "explicit";
2104
- umAssumed = false;
2105
- }
2106
2109
  if (umRule === "neutral_full" && umAssumed) {
2107
2110
  cautionsZh.push("35 kV \u7EA7\u4E2D\u6027\u70B9\u5148\u6309 Um 40.5 \u9009\uFF1B\u4E0D\u5C11\u8BA2\u5355\uFF08\u4FC4\u7F57\u65AF\u3001\u571F\u8033\u5176\uFF09\u6309 72.5 \u4E70\uFF0C\u4EE5 OS \u4E3A\u51C6\u3002");
2108
2111
  cautionsEn.push("35 kV-class neutral sized at Um 40.5; many orders (Russia, Turkey) bought 72.5. The OS decides.");
@@ -2159,7 +2162,7 @@ function num(raw, flag) {
2159
2162
  }
2160
2163
  throw new CliError(`Invalid number for ${flag}: ${raw}`);
2161
2164
  }
2162
- function parseCliArgs(argv) {
2165
+ function parseCliArgs(argv2) {
2163
2166
  const out = {
2164
2167
  conn: "Y",
2165
2168
  kind: "two_winding",
@@ -2176,14 +2179,14 @@ function parseCliArgs(argv) {
2176
2179
  given: /* @__PURE__ */ new Set()
2177
2180
  };
2178
2181
  const take = (i, flag) => {
2179
- const v = argv[i + 1];
2182
+ const v = argv2[i + 1];
2180
2183
  if (v == null || v.startsWith("-")) {
2181
2184
  throw new CliError(`Missing value for ${flag}`);
2182
2185
  }
2183
2186
  return [v, i + 1];
2184
2187
  };
2185
- for (let i = 0; i < argv.length; i++) {
2186
- const a = argv[i];
2188
+ for (let i = 0; i < argv2.length; i++) {
2189
+ const a = argv2[i];
2187
2190
  if (a === "-h" || a === "--help") {
2188
2191
  out.help = true;
2189
2192
  continue;
@@ -2192,6 +2195,9 @@ function parseCliArgs(argv) {
2192
2195
  out.json = true;
2193
2196
  continue;
2194
2197
  }
2198
+ if (a === "--no-update-check") {
2199
+ continue;
2200
+ }
2195
2201
  if (a === "--octc") {
2196
2202
  out.given.add("octc");
2197
2203
  out.octc = true;
@@ -2462,11 +2468,54 @@ Flags:
2462
2468
  --contact OCTC contact e.g. 6x5.
2463
2469
  --phases I|II|III. Default III.
2464
2470
  --json Machine-readable result (still no prices).
2471
+ --no-update-check Skip the daily check for a newer version. The check only
2472
+ prints a notice on stderr; it never installs anything.
2473
+ OLTC_NO_UPDATE_CHECK=1 or CI=1 also turn it off.
2465
2474
  -h, --help This text.
2466
2475
 
2467
2476
  Defaults match the web first paint: on-load, in-tank vacuum, structure auto,
2468
2477
  \xB18 mid-3 reversing. Omitting --octc and --structure auto is minimum-adequate.
2469
2478
  `;
2479
+ function cliTapPoint(args) {
2480
+ if (args.tap) return args.tap;
2481
+ if (args.kind === "auto") return "auto_junction";
2482
+ return args.conn === "D" || args.winding === "delta" ? "line_end" : "neutral";
2483
+ }
2484
+ function tapSetsConnection(args) {
2485
+ return args.mva != null || args.tap != null || args.kind === "auto" || args.winding === "delta";
2486
+ }
2487
+ function cliConnection(args) {
2488
+ if (!tapSetsConnection(args)) return args.conn;
2489
+ return cliTapPoint(args) === "neutral" ? "Y" : "D";
2490
+ }
2491
+ var pmGiven = (args) => args.given.has("pm") && args.pm != null && args.pm > 0;
2492
+ function cliPlusMinus(args) {
2493
+ if (pmGiven(args)) return { n: args.pm, mid: 3 };
2494
+ if (args.positions != null) {
2495
+ const n = plusMinusFromPositions(args.positions, args.reg);
2496
+ if (n == null) return null;
2497
+ const mid = lookupByPositions(args.positions, 3, args.reg) ? 3 : 1;
2498
+ return { n, mid };
2499
+ }
2500
+ if (args.given.has("pm")) return null;
2501
+ return args.pm != null && args.pm > 0 ? { n: args.pm, mid: 3 } : null;
2502
+ }
2503
+ function cliMinusSteps(args) {
2504
+ const fromPositions = args.positions != null && args.positions > 1 ? Math.ceil((args.positions - 1) / 2) : null;
2505
+ if (args.octc || args.reg === "linear") {
2506
+ if (fromPositions != null) return fromPositions;
2507
+ if (pmGiven(args)) return args.pm;
2508
+ return 8;
2509
+ }
2510
+ const pm = cliPlusMinus(args);
2511
+ if (pm) return pm.n;
2512
+ return fromPositions ?? 8;
2513
+ }
2514
+ function cliLinearPositions(args) {
2515
+ if (args.positions != null) return args.positions;
2516
+ if (pmGiven(args)) return Math.round(2 * args.pm + 1);
2517
+ return void 0;
2518
+ }
2470
2519
  function cliDuty(args) {
2471
2520
  if (args.mva == null) return null;
2472
2521
  const auto = args.kind === "auto";
@@ -2477,7 +2526,7 @@ function cliDuty(args) {
2477
2526
  } else if (!(args.kv != null && args.kv > 0)) {
2478
2527
  throw new CliError("--mva requires --kv (tap-side rated voltage)");
2479
2528
  }
2480
- const tap = args.tap ?? (auto ? "auto_junction" : args.conn === "D" ? "line_end" : "neutral");
2529
+ const tap = cliTapPoint(args);
2481
2530
  const winding = args.winding ?? (tap === "neutral" || args.conn === "Y" ? "star" : "delta");
2482
2531
  const pct = args.stepPct != null && args.stepPct > 0 ? args.stepPct / 100 : 0.0125;
2483
2532
  const earth = args.earthUm != null && args.earthUm > 0 ? args.earthUm : args.um != null && args.um > 0 ? args.um : void 0;
@@ -2489,7 +2538,7 @@ function cliDuty(args) {
2489
2538
  tapKv: args.kv ?? 0,
2490
2539
  hvKv: args.hv ?? 0,
2491
2540
  mvKv: args.mv ?? 0,
2492
- minusSteps: args.pm != null && args.pm > 0 ? args.pm : 8,
2541
+ minusSteps: cliMinusSteps(args),
2493
2542
  stepFraction: pct,
2494
2543
  // 与网页版首屏一致:容量路径默认不额外加安全系数
2495
2544
  safetyK: args.k != null && args.k > 0 ? args.k : 1,
@@ -2523,8 +2572,8 @@ function cliToSelectInput(args) {
2523
2572
  if (um == null || !(um > 0)) um = duty.umKv;
2524
2573
  if (!(ust > 0) && duty.stepV != null) ust = duty.stepV;
2525
2574
  conn = duty.connection;
2526
- } else if (args.tap) {
2527
- conn = args.tap === "neutral" ? "Y" : "D";
2575
+ } else {
2576
+ conn = cliConnection(args);
2528
2577
  }
2529
2578
  if (iu == null || !(iu > 0)) {
2530
2579
  throw new CliError("Need --iu (Imax) or --mva plus --kv");
@@ -2556,11 +2605,13 @@ function cliToSelectInput(args) {
2556
2605
  input.positions = Math.round(2 * args.pm + 1);
2557
2606
  }
2558
2607
  } else if (args.reg === "linear") {
2559
- if (args.positions != null) input.positions = args.positions;
2608
+ const pos = cliLinearPositions(args);
2609
+ if (pos != null) input.positions = pos;
2560
2610
  } else {
2561
- if (args.pm != null && args.pm > 0) {
2562
- input.plusMinusSteps = args.pm;
2563
- input.midPositions = 3;
2611
+ const pm = cliPlusMinus(args);
2612
+ if (pm) {
2613
+ input.plusMinusSteps = pm.n;
2614
+ input.midPositions = pm.mid;
2564
2615
  }
2565
2616
  if (args.positions != null) input.positions = args.positions;
2566
2617
  }
@@ -2583,21 +2634,29 @@ function assumptionsFromArgs(args, family) {
2583
2634
  auto_junction: "\u4E32\u8054/\u516C\u5171\u7ED5\u7EC4\u8FDE\u63A5\u70B9",
2584
2635
  auto_mv_line: "\u4E2D\u538B\u51FA\u7EBF"
2585
2636
  };
2637
+ const tapGiven = args.given.has("tap") || args.given.has("conn") || args.winding === "delta";
2586
2638
  if (args.mva != null) {
2587
2639
  const duty = cliDuty(args);
2588
- const tap = args.tap ?? (args.kind === "auto" ? "auto_junction" : args.conn === "D" ? "line_end" : "neutral");
2640
+ const tap = cliTapPoint(args);
2589
2641
  items.push(`${args.kind === "auto" ? "\u81EA\u8026\u53D8" : "\u53CC\u7ED5\u7EC4"}${mark("kind")}`);
2590
- items.push(`\u5F00\u5173\u5728${tapZh[tap]}${args.given.has("tap") || args.given.has("conn") ? "" : "\uFF08\u9ED8\u8BA4\uFF09"}`);
2642
+ items.push(`\u5F00\u5173\u5728${tapZh[tap]}${tapGiven ? "" : "\uFF08\u9ED8\u8BA4\uFF09"}`);
2591
2643
  if (args.kind !== "auto") {
2592
2644
  const w = args.winding ?? (tap === "neutral" || args.conn === "Y" ? "star" : "delta");
2593
2645
  items.push(`${w === "star" ? "\u661F\u5F62" : "\u89D2\u5F62"}\u7ED5\u7EC4${args.given.has("winding") ? "" : "\uFF08\u9ED8\u8BA4\uFF09"}`);
2594
2646
  }
2595
2647
  if (duty?.umAssumed) items.push(`\u5BF9\u5730 Um ${duty.umKv}\uFF08\u672A\u6307\u5B9A\uFF09`);
2596
2648
  } else {
2649
+ const conn = cliConnection(args);
2650
+ const derived = tapSetsConnection(args);
2597
2651
  items.push(
2598
- `conn=${args.conn} ${args.conn === "Y" ? "\u661F\u70B9" : "\u7EBF\u7AEF"}${mark("conn")}`
2652
+ `conn=${conn} ${conn === "Y" ? "\u661F\u70B9" : "\u7EBF\u7AEF"}${derived ? "" : mark("conn")}`
2599
2653
  );
2600
2654
  if (args.kind === "auto") items.push("\u81EA\u8026\u53D8");
2655
+ if (derived) {
2656
+ items.push(
2657
+ `\u5F00\u5173\u5728${tapZh[cliTapPoint(args)]}${tapGiven ? "" : "\uFF08\u9ED8\u8BA4\uFF09"}`
2658
+ );
2659
+ }
2601
2660
  }
2602
2661
  if (args.mva != null) {
2603
2662
  items.push(args.given.has("k") ? `k=${args.k}` : "k=1.0\uFF08\u9ED8\u8BA4\uFF09");
@@ -2627,8 +2686,11 @@ function assumptionsFromArgs(args, family) {
2627
2686
  );
2628
2687
  if (args.reg === "linear") {
2629
2688
  items.push(
2630
- args.positions != null ? `${args.positions} \u6863${mark("positions")}` : "\u6863\u6570\u672A\u6307\u5B9A"
2689
+ args.positions != null ? `${args.positions} \u6863${mark("positions")}` : pmGiven(args) ? `${cliLinearPositions(args)} \u6863\uFF08\u7531 \xB1${args.pm} \u63A8\uFF09` : "\u6863\u6570\u672A\u6307\u5B9A"
2631
2690
  );
2691
+ } else if (args.positions != null && !args.given.has("pm")) {
2692
+ const pm = cliPlusMinus(args);
2693
+ items.push(pm ? `${args.positions} \u6863\uFF08\xB1${pm.n}\uFF09` : `${args.positions} \u6863`);
2632
2694
  } else {
2633
2695
  items.push(`\xB1${args.pm ?? 8} \u6863${mark("pm")}`);
2634
2696
  }
@@ -2740,12 +2802,12 @@ function formatCliJson(input, args) {
2740
2802
  };
2741
2803
  return JSON.stringify(payload, null, 2) + "\n";
2742
2804
  }
2743
- function runCli(argv, io = {
2805
+ function runCli(argv2, io = {
2744
2806
  stdout: (s) => process.stdout.write(s),
2745
2807
  stderr: (s) => process.stderr.write(s)
2746
2808
  }) {
2747
2809
  try {
2748
- const args = parseCliArgs(argv);
2810
+ const args = parseCliArgs(argv2);
2749
2811
  if (args.help) {
2750
2812
  io.stdout(CLI_HELP);
2751
2813
  return 0;
@@ -2760,6 +2822,91 @@ function runCli(argv, io = {
2760
2822
  }
2761
2823
  }
2762
2824
 
2825
+ // lib/updateCheck.ts
2826
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
2827
+ import { homedir } from "node:os";
2828
+ import path from "node:path";
2829
+ var UPDATE_TTL_MS = 24 * 60 * 60 * 1e3;
2830
+ var REGISTRY_LATEST = "https://registry.npmjs.org/oltc-selector/latest";
2831
+ function isNewer(latest, current) {
2832
+ const parse = (v) => {
2833
+ const m = /^(\d+)\.(\d+)\.(\d+)$/.exec(v.trim());
2834
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
2835
+ };
2836
+ const a = parse(latest);
2837
+ const b = parse(current);
2838
+ if (!a || !b) return false;
2839
+ for (let i = 0; i < 3; i++) {
2840
+ if (a[i] !== b[i]) return a[i] > b[i];
2841
+ }
2842
+ return false;
2843
+ }
2844
+ function updateNotice(latest, current) {
2845
+ return `
2846
+ \u6709\u65B0\u7248\u672C oltc-selector ${latest}\uFF08\u5F53\u524D ${current}\uFF09\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u66F4\u65B0\u3002
2847
+ \u9700\u8981\u65F6\u8FD0\u884C\uFF1Anpm i -g oltc-selector@latest\uFF0C\u6216\u7528 npx -y oltc-selector@latest\u3002
2848
+ `;
2849
+ }
2850
+ function updateCheckEnabled(argv2, env) {
2851
+ if (argv2.includes("--no-update-check")) return false;
2852
+ if (env.OLTC_NO_UPDATE_CHECK || env.NO_UPDATE_NOTIFIER || env.CI) return false;
2853
+ return true;
2854
+ }
2855
+ function defaultCacheFile(env) {
2856
+ const base = env.XDG_CACHE_HOME || path.join(homedir(), ".cache");
2857
+ return path.join(base, "oltc-selector", "update-check.json");
2858
+ }
2859
+ async function fetchLatest(timeoutMs) {
2860
+ const res = await fetch(REGISTRY_LATEST, {
2861
+ signal: AbortSignal.timeout(timeoutMs),
2862
+ headers: { accept: "application/json" }
2863
+ });
2864
+ if (!res.ok) return null;
2865
+ const body = await res.json();
2866
+ return typeof body.version === "string" ? body.version : null;
2867
+ }
2868
+ function readCache(file2) {
2869
+ try {
2870
+ const c = JSON.parse(readFileSync(file2, "utf8"));
2871
+ return typeof c.checkedAt === "number" ? c : null;
2872
+ } catch {
2873
+ return null;
2874
+ }
2875
+ }
2876
+ function writeCache(file2, c) {
2877
+ try {
2878
+ mkdirSync(path.dirname(file2), { recursive: true });
2879
+ writeFileSync(file2, JSON.stringify(c) + "\n");
2880
+ } catch {
2881
+ }
2882
+ }
2883
+ async function checkForUpdate(opts) {
2884
+ const now = opts.now ?? Date.now();
2885
+ try {
2886
+ let latest;
2887
+ const cached = readCache(opts.cacheFile);
2888
+ if (cached && now - cached.checkedAt < UPDATE_TTL_MS) {
2889
+ latest = cached.latest;
2890
+ } else {
2891
+ latest = await (opts.fetchLatest ?? fetchLatest)(opts.timeoutMs ?? 1500).catch(
2892
+ () => cached?.latest ?? null
2893
+ );
2894
+ writeCache(opts.cacheFile, { checkedAt: now, latest });
2895
+ }
2896
+ return latest && isNewer(latest, opts.current) ? updateNotice(latest, opts.current) : null;
2897
+ } catch {
2898
+ return null;
2899
+ }
2900
+ }
2901
+
2763
2902
  // scripts/oltc.ts
2764
- var code = runCli(process.argv.slice(2));
2903
+ var argv = process.argv.slice(2);
2904
+ var code = runCli(argv);
2905
+ if (updateCheckEnabled(argv, process.env)) {
2906
+ const notice = await checkForUpdate({
2907
+ current: APP_VERSION,
2908
+ cacheFile: defaultCacheFile(process.env)
2909
+ });
2910
+ if (notice) process.stderr.write(notice);
2911
+ }
2765
2912
  process.exit(code);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oltc-selector",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Huaming OLTC/OCTC type selection CLI. No prices. Same engine as the web app.",
5
5
  "bin": {
6
6
  "oltc": "bin/oltc.js"