@enerlence/suntropy-cli 0.11.0 → 0.11.1

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.
@@ -2149,6 +2149,32 @@ function getGlobalOpts7(cmd) {
2149
2149
  function resolveFile(opts) {
2150
2150
  return opts.file || process.env.SUNTROPY_STUDY || "./study.json";
2151
2151
  }
2152
+ function resolveSurfaceCoordinates(surface, study) {
2153
+ const isValid = (c) => {
2154
+ const p = c;
2155
+ return !!p && Number.isFinite(p.lat) && Number.isFinite(p.lng);
2156
+ };
2157
+ const center = surface.center;
2158
+ if (isValid(center)) return { lat: center.lat, lng: center.lng };
2159
+ const studyLocation = study.location;
2160
+ if (isValid(studyLocation)) return { lat: studyLocation.lat, lng: studyLocation.lng };
2161
+ const path = surface.polygonPath;
2162
+ if (Array.isArray(path) && path.length > 0) {
2163
+ const points = path.filter(
2164
+ (p) => Number.isFinite(p?.lat) && Number.isFinite(p?.lng)
2165
+ );
2166
+ if (points.length > 0) {
2167
+ const sum = points.reduce(
2168
+ (acc, p) => ({ lat: acc.lat + p.lat, lng: acc.lng + p.lng }),
2169
+ { lat: 0, lng: 0 }
2170
+ );
2171
+ const centroid = { lat: sum.lat / points.length, lng: sum.lng / points.length };
2172
+ if (isValid(centroid)) return centroid;
2173
+ return { lat: points[0].lat, lng: points[0].lng };
2174
+ }
2175
+ }
2176
+ return null;
2177
+ }
2152
2178
  function registerStudyBuilderCommands(studies) {
2153
2179
  studies.command("init").description(
2154
2180
  'Create a new study workspace (local JSON file with defaults).\nExample: suntropy studies init --file /tmp/study.json --name "Residencial 5kW"'
@@ -2694,14 +2720,12 @@ Example: suntropy studies set data --file study.json --data '{"referenceId":"REF
2694
2720
  for (const idx of indicesToCalc) {
2695
2721
  const surface = surfaces[idx];
2696
2722
  if (!surface) continue;
2697
- const center = surface.center;
2698
- const studyLocation = study.location;
2699
- const lat = center?.lat || studyLocation?.lat;
2700
- const lng = center?.lng || studyLocation?.lng;
2701
- if (!lat || !lng) {
2723
+ const coords = resolveSurfaceCoordinates(surface, study);
2724
+ if (!coords) {
2702
2725
  outputError(new Error(`Surface ${idx} has no coordinates. Use: studies add surface --lat N --lon N`));
2703
2726
  continue;
2704
2727
  }
2728
+ const { lat, lng } = coords;
2705
2729
  const body = {
2706
2730
  lat,
2707
2731
  long: lng,
@@ -2959,7 +2983,7 @@ Example: suntropy studies set data --file study.json --data '{"referenceId":"REF
2959
2983
  surface.panelInclination || 0,
2960
2984
  surface.inclination || 0,
2961
2985
  surface.panelPosition || "vertical",
2962
- surface.polygonPath?.[0]?.lat || 37
2986
+ resolveSurfaceCoordinates(surface, study)?.lat ?? 37
2963
2987
  );
2964
2988
  } else {
2965
2989
  maxPanels = remainingPanels;
@@ -3071,7 +3095,7 @@ Example: suntropy studies set data --file study.json --data '{"referenceId":"REF
3071
3095
  surface.panelInclination || 0,
3072
3096
  surface.inclination || 0,
3073
3097
  surface.panelPosition || "vertical",
3074
- surface.polygonPath?.[0]?.lat || 37
3098
+ resolveSurfaceCoordinates(surface, study)?.lat ?? 37
3075
3099
  );
3076
3100
  surfacesMaxPeakPower[sid] = maxPanels * panelPeakPower / 1e3;
3077
3101
  } else {
@@ -4553,7 +4577,7 @@ function registerCommandProfileCommand(program2) {
4553
4577
  }
4554
4578
 
4555
4579
  // src/index.ts
4556
- var CLI_VERSION = true ? "0.11.0" : "0.0.0-dev";
4580
+ var CLI_VERSION = true ? "0.11.1" : "0.0.0-dev";
4557
4581
  function createProgram() {
4558
4582
  const program2 = new Command3();
4559
4583
  program2.name("suntropy").description("Agent-first CLI for Suntropy solar platform. Optimized for programmatic data manipulation and progressive exploration.").version(CLI_VERSION).option("--format <format>", "Output format: json (default), human, csv", "json").option("--fields <fields>", "Comma-separated fields to include in output").option("--server <url>", "Override API server URL").option("--token <jwt>", "Override authentication token").option("--profile <name>", "Use a specific config profile").option("--verbose", "Show HTTP request/response details on stderr").option("--quiet", "Suppress non-data output").option("--save <file>", "Save output to file (also writes to stdout)");