Skip to content

Commit f951266

Browse files
committed
feat: integrate Eclipse Solar Analysis Plugin and update related calculations
1 parent 492614b commit f951266

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

src/app/analysis/sat-math.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* /////////////////////////////////////////////////////////////////////////////
2222
*/
2323

24+
import { ServiceLocator } from '@app/engine/core/service-locator';
2425
import { CelestialBody } from '@app/engine/rendering/draw-manager/celestial-bodies/celestial-body';
2526
import { Earth } from '@app/engine/rendering/draw-manager/earth';
2627
import {
@@ -59,7 +60,6 @@ import { DISTANCE_TO_SUN, RADIUS_OF_EARTH, RADIUS_OF_SUN } from '../../engine/ut
5960
import { errorManagerInstance } from '../../engine/utils/errorManager';
6061
import { jday, lon2yaw } from '../../engine/utils/transforms';
6162
import { CoordinateTransforms } from './coordinate-transforms';
62-
import { ServiceLocator } from '@app/engine/core/service-locator';
6363

6464
if (!global) {
6565
window._numeric = numeric; // numeric will break if it is not available globally
@@ -190,7 +190,7 @@ export abstract class SatMath {
190190
}
191191

192192

193-
if (obj instanceof BaseObject) {
193+
if (obj instanceof BaseObject || !(obj.position instanceof Boolean)) {
194194
if (!obj?.position) {
195195
return SunStatus.UNKNOWN;
196196
}
@@ -215,9 +215,9 @@ export abstract class SatMath {
215215
typeof obj.velocity.z === 'number'
216216
)) && typeof obj.position !== 'boolean') {
217217

218-
x = obj.position.x as Kilometers;
219-
y = obj.position.y as Kilometers;
220-
z = obj.position.z as Kilometers;
218+
x = obj.position.x;
219+
y = obj.position.y;
220+
z = obj.position.z;
221221
} else {
222222
return SunStatus.UNKNOWN;
223223
}

src/plugins/eclipse-solar-analysis/eclipse-calculations.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import { SatMath, SunStatus } from '@app/app/analysis/sat-math';
2424
import { ServiceLocator } from '@app/engine/core/service-locator';
25-
import { Degrees, DetailedSatellite, EciVec3, Kilometers, Milliseconds, RAD2DEG, Sgp4 } from '@ootk/src/main';
25+
import { Degrees, DetailedSatellite, EciVec3, Kilometers, Milliseconds, RAD2DEG, StateVectorSgp4 } from '@ootk/src/main';
2626
import { vec3 } from 'gl-matrix';
2727
import {
2828
BetaAngleDataPoint,
@@ -69,7 +69,7 @@ export class EclipseCalculations {
6969
// Get satellite position at this time
7070
const posvel = SatMath.getEci(satellite, currentTime);
7171

72-
if (!posvel || !posvel.position) {
72+
if (!posvel?.position) {
7373
continue;
7474
}
7575

@@ -82,7 +82,7 @@ export class EclipseCalculations {
8282
};
8383

8484
// Check eclipse status
85-
const status = SatMath.calculateIsInSun({ position: posvel.position }, sunEciVec);
85+
const status = SatMath.calculateIsInSun({ position: posvel.position } as StateVectorSgp4, sunEciVec);
8686

8787
// Detect transitions
8888
if (previousStatus !== SunStatus.UNKNOWN && status !== previousStatus) {
@@ -137,7 +137,7 @@ export class EclipseCalculations {
137137
time: currentTime,
138138
orbitNumber,
139139
});
140-
if (currentPeriod && currentPeriod.isUmbral) {
140+
if (currentPeriod?.isUmbral) {
141141
periods.push({
142142
startTime: currentPeriod.startTime!,
143143
endTime: currentTime,
@@ -173,7 +173,7 @@ export class EclipseCalculations {
173173
time: currentTime,
174174
orbitNumber,
175175
});
176-
if (currentPeriod && currentPeriod.isUmbral) {
176+
if (currentPeriod?.isUmbral) {
177177
periods.push({
178178
startTime: currentPeriod.startTime!,
179179
endTime: currentTime,
@@ -191,10 +191,10 @@ export class EclipseCalculations {
191191
}
192192

193193
// Close any open period at the end
194-
if (currentPeriod && currentPeriod.startTime) {
194+
if (currentPeriod?.startTime) {
195195
periods.push({
196196
startTime: currentPeriod.startTime,
197-
endTime: endTime,
197+
endTime,
198198
duration: (endTime.getTime() - currentPeriod.startTime.getTime()) as Milliseconds,
199199
orbitNumber: currentPeriod.orbitNumber!,
200200
isUmbral: currentPeriod.isUmbral!,
@@ -212,7 +212,7 @@ export class EclipseCalculations {
212212
// Get satellite position and velocity
213213
const posvel = SatMath.getEci(satellite, time);
214214

215-
if (!posvel || !posvel.position || !posvel.velocity) {
215+
if (!posvel?.position || !posvel.velocity) {
216216
return 0 as Degrees;
217217
}
218218

@@ -272,7 +272,7 @@ export class EclipseCalculations {
272272
// Get satellite position
273273
const posvel = SatMath.getEci(satellite, time);
274274

275-
if (!posvel || !posvel.position) {
275+
if (!posvel?.position) {
276276
return {
277277
phaseAngle: 0 as Degrees,
278278
sunElevation: 0 as Degrees,
@@ -331,8 +331,8 @@ export class EclipseCalculations {
331331
z: sunEci[2] as Kilometers,
332332
};
333333

334-
const isSatelliteIlluminated = SatMath.calculateIsInSun({ position: posvel.position }, sunEciVec) === SunStatus.SUN;
335-
const isTargetIlluminated = SatMath.calculateIsInSun({ position: targetPosition }, sunEciVec) === SunStatus.SUN;
334+
const isSatelliteIlluminated = SatMath.calculateIsInSun({ position: posvel.position } as StateVectorSgp4, sunEciVec) === SunStatus.SUN;
335+
const isTargetIlluminated = SatMath.calculateIsInSun({ position: targetPosition } as StateVectorSgp4, sunEciVec) === SunStatus.SUN;
336336

337337
return {
338338
phaseAngle,
@@ -418,7 +418,7 @@ export class EclipseCalculations {
418418
static getCurrentEclipseStatus(satellite: DetailedSatellite, time: Date): SunStatus {
419419
const posvel = SatMath.getEci(satellite, time);
420420

421-
if (!posvel || !posvel.position) {
421+
if (!posvel?.position) {
422422
return SunStatus.UNKNOWN;
423423
}
424424

@@ -429,7 +429,7 @@ export class EclipseCalculations {
429429
z: sunEci[2] as Kilometers,
430430
};
431431

432-
return SatMath.calculateIsInSun({ position: posvel.position }, sunEciVec);
432+
return SatMath.calculateIsInSun({ position: posvel.position } as StateVectorSgp4, sunEciVec);
433433
}
434434

435435
/**

src/plugins/eclipse-solar-analysis/eclipse-solar-analysis.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,22 @@
2121
*/
2222

2323
import { SunStatus } from '@app/app/analysis/sat-math';
24-
import { PluginRegistry } from '@app/engine/core/plugin-registry';
24+
import { MenuMode } from '@app/engine/core/interfaces';
2525
import { ServiceLocator } from '@app/engine/core/service-locator';
2626
import { EventBus } from '@app/engine/events/event-bus';
2727
import { EventBusEvent } from '@app/engine/events/event-bus-events';
28-
import { MenuMode } from '@app/engine/core/interfaces';
2928
import { html } from '@app/engine/utils/development/formatter';
3029
import { getEl } from '@app/engine/utils/get-el';
3130
import { BaseObject, DetailedSatellite, Milliseconds } from '@ootk/src/main';
3231
import dayNightPng from '@public/img/icons/day-night.png';
3332
import { KeepTrackPlugin } from '../../engine/plugins/base-plugin';
3433
import { SelectSatManager } from '../select-sat-manager/select-sat-manager';
3534
import { EclipseCalculations } from './eclipse-calculations';
36-
import { EclipseEventType, EclipsePeriod, EclipsePredictionConfig } from './eclipse-types';
35+
import { EclipseEvent, EclipseEventType, EclipsePeriod, EclipsePredictionConfig } from './eclipse-types';
3736

3837
export class EclipseSolarAnalysis extends KeepTrackPlugin {
3938
readonly id = 'EclipseSolarAnalysis';
4039
dependencies_: string[] = [SelectSatManager.name];
41-
private readonly selectSatManager_: SelectSatManager;
4240

4341
isRequireSatelliteSelected = true;
4442
isIconDisabled = true;
@@ -151,14 +149,9 @@ export class EclipseSolarAnalysis extends KeepTrackPlugin {
151149
private currentSatellite_: DetailedSatellite | null = null;
152150
private currentEclipsePeriods_: EclipsePeriod[] = [];
153151
private updateInterval_: NodeJS.Timeout | null = null;
154-
private stateStartTime_: Date | null = null;
152+
private stateStartTime_: number | null = null;
155153
private currentStatus_: SunStatus = SunStatus.UNKNOWN;
156154

157-
constructor() {
158-
super();
159-
this.selectSatManager_ = PluginRegistry.getPlugin(SelectSatManager) as unknown as SelectSatManager;
160-
}
161-
162155
bottomIconCallback = () => {
163156
if (this.isMenuButtonActive) {
164157
// Menu opened - start updates
@@ -188,7 +181,7 @@ export class EclipseSolarAnalysis extends KeepTrackPlugin {
188181
});
189182

190183
// Listen for time changes
191-
EventBus.getInstance().on(EventBusEvent.timeManagerTick, () => {
184+
EventBus.getInstance().on(EventBusEvent.update, () => {
192185
if (this.isMenuButtonActive && this.currentSatellite_) {
193186
this.updateRealTimeStatus_();
194187
}
@@ -251,12 +244,12 @@ export class EclipseSolarAnalysis extends KeepTrackPlugin {
251244
break;
252245
case SunStatus.PENUMBRAL:
253246
statusText = 'Penumbral Shadow';
254-
statusColor = '#888';
255247
break;
256248
case SunStatus.UMBRAL:
257249
statusText = 'Umbral Shadow (Full Eclipse)';
258250
statusColor = '#444';
259251
break;
252+
default:
260253
}
261254

262255
(<HTMLInputElement>statusEl).value = statusText;
@@ -266,13 +259,13 @@ export class EclipseSolarAnalysis extends KeepTrackPlugin {
266259

267260
// Track state changes to calculate time in current state
268261
if (status !== this.currentStatus_) {
269-
this.stateStartTime_ = currentTime;
262+
this.stateStartTime_ = currentTime.getTime();
270263
this.currentStatus_ = status;
271264
}
272265

273266
// Update time in current state
274267
if (this.stateStartTime_) {
275-
const timeInState = currentTime.getTime() - this.stateStartTime_.getTime();
268+
const timeInState = currentTime.getTime() - this.stateStartTime_;
276269
const hours = Math.floor(timeInState / 3600000);
277270
const minutes = Math.floor((timeInState % 3600000) / 60000);
278271
const seconds = Math.floor((timeInState % 60000) / 1000);
@@ -344,7 +337,7 @@ export class EclipseSolarAnalysis extends KeepTrackPlugin {
344337

345338
// Display results
346339
this.displayEclipseEvents_(events);
347-
this.displayEclipseStatistics_(periods, config.predictionDurationHours * 3600 * 1000);
340+
this.displayEclipseStatistics_(periods, config.predictionDurationHours * 3600 * 1000 as Milliseconds);
348341

349342
// Enable export button
350343
const exportBtn = getEl('export-eclipse-data-btn');
@@ -357,7 +350,7 @@ export class EclipseSolarAnalysis extends KeepTrackPlugin {
357350
/**
358351
* Display eclipse events in the UI
359352
*/
360-
private displayEclipseEvents_(events: any[]): void {
353+
private displayEclipseEvents_(events: EclipseEvent[]): void {
361354
const container = getEl('eclipse-events-container');
362355

363356
if (!container) {
@@ -392,6 +385,8 @@ export class EclipseSolarAnalysis extends KeepTrackPlugin {
392385
case EclipseEventType.EXIT_PENUMBRA:
393386
eventStr = '← Exit Penumbra';
394387
break;
388+
default:
389+
eventStr = 'Unknown Event';
395390
}
396391

397392
html += `<tr><td>${timeStr}</td><td>${eventStr}</td><td>${event.orbitNumber}</td></tr>`;

src/settings/default-plugins.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ export const defaultPlugins = <KeepTrackPluginsConfiguration>{
120120
enabled: true,
121121
order: 92,
122122
},
123+
EclipseSolarAnalysis: {
124+
enabled: true,
125+
order: 93,
126+
},
123127
StereoMap: {
124128
enabled: true,
125129
order: 150,

0 commit comments

Comments
 (0)