-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathmulti-site-look-angles-plugin.ts
353 lines (294 loc) · 12.4 KB
/
multi-site-look-angles-plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import { KeepTrackApiEvents } from '@app/interfaces';
import { keepTrackApi } from '@app/keepTrackApi';
import { dateFormat } from '@app/lib/dateFormat';
import { getEl } from '@app/lib/get-el';
import { saveCsv } from '@app/lib/saveVariable';
import { showLoading } from '@app/lib/showLoading';
import { errorManagerInstance } from '@app/singletons/errorManager';
import { SatMath } from '@app/static/sat-math';
import { TearrData } from '@app/static/sensor-math';
import multiSitePng from '@public/img/icons/multi-site.png';
import { BaseObject, Degrees, DetailedSatellite, DetailedSensor, Kilometers, MINUTES_PER_DAY, SatelliteRecord, Seconds, TAU } from 'ootk';
import { KeepTrackPlugin, SideMenuSettingsOptions, clickDragOptions } from '../KeepTrackPlugin';
import { SelectSatManager } from '../select-sat-manager/select-sat-manager';
import { SoundNames } from '../sounds/SoundNames';
import { SensorManager } from './sensorManager';
export class MultiSiteLookAnglesPlugin extends KeepTrackPlugin {
dependencies_ = [SelectSatManager.name];
private selectSatManager_: SelectSatManager;
// combine sensorListSsn, sesnorListLeoLabs, and SensorListRus
private sensorList_ = keepTrackApi.getSensorManager().sensorListSsn.concat(
keepTrackApi.getSensorManager().sensorListMw,
keepTrackApi.getSensorManager().sensorListMda,
keepTrackApi.getSensorManager().sensorListLeoLabs,
keepTrackApi.getSensorManager().sensorListEsoc,
keepTrackApi.getSensorManager().sensorListRus,
keepTrackApi.getSensorManager().sensorListPrc,
keepTrackApi.getSensorManager().sensorListOther,
);
isRequireSatelliteSelected = true;
isRequireSensorSelected = false;
// Settings
private lengthOfLookAngles_ = 1; // Days
private angleCalculationInterval_ = <Seconds>30;
private disabledSensors_: DetailedSensor[] = this.sensorList_.filter((s) =>
!keepTrackApi.getSensorManager().sensorListMw.includes(s),
);
constructor() {
super();
this.selectSatManager_ = keepTrackApi.getPlugin(SelectSatManager);
// remove duplicates in sensorList
this.sensorList_ = this.sensorList_.filter(
(sensor, index, self) => index === self.findIndex((t) => t.uiName === sensor.uiName),
);
}
bottomIconCallback: () => void = () => {
const sat = this.selectSatManager_.getSelectedSat();
if (!sat?.isSatellite()) {
return;
}
this.refreshSideMenuData(sat as DetailedSatellite);
};
bottomIconElementName = 'multi-site-look-angles-icon';
bottomIconLabel = 'Multi-Site Looks';
bottomIconImg = multiSitePng;
isIconDisabledOnLoad = true;
isIconDisabled = true;
dragOptions: clickDragOptions = {
isDraggable: true,
minWidth: 500,
maxWidth: 750,
};
helpTitle = 'Multi-Site Look Angles Menu';
helpBody = keepTrackApi.html`
The Multi-Site Look Angles menu allows you to calculate the range, azimuth, and elevation angles between a satellite and multiple sensors.
A satellite must first be selected before the menu can be used.
<br><br>
By default the menu will calculate the look angles for all sensors in the Space Surveillance Netowrk.
If you would like to calculate the look angles for additional sensors, you can export a csv file at the bottom of the menu.
The csv file will contain look angles for all sensors.
<br><br>
Clicking on a row in the table will select the sensor and change the simulation time to the time of the look angle.`;
sideMenuElementName: string = 'multi-site-look-angles-menu';
sideMenuTitle: string = 'Multi-Sensor Look Angles';
sideMenuElementHtml: string = keepTrackApi.html`
<div class="row"></div>
<div class="row">
<table id="multi-site-look-angles-table" class="center-align striped-light centered"></table>
</div>`;
sideMenuSettingsHtml: string = keepTrackApi.html`
<div class="row" style="margin: 0 10px;">
<div id="multi-site-look-angles-sensor-list">
</div>
</div>`;
sideMenuSettingsWidth: number = 350;
downloadIconCb = () => {
keepTrackApi.getSoundManager().play(SoundNames.EXPORT);
const exportData = keepTrackApi.getSensorManager().lastMultiSiteArray.map((look) => ({
time: look.time,
sensor: look.objName,
az: look.az.toFixed(2),
el: look.el.toFixed(2),
rng: look.rng.toFixed(2),
}));
saveCsv(exportData, `multisite-${(this.selectSatManager_.getSelectedSat() as DetailedSatellite).sccNum6}-look-angles`);
};
sideMenuSettingsOptions: SideMenuSettingsOptions = {
width: 300,
leftOffset: null,
zIndex: 3,
};
addHtml(): void {
super.addHtml();
keepTrackApi.register({
event: KeepTrackApiEvents.selectSatData,
cbName: this.constructor.name,
cb: (obj: BaseObject) => {
this.checkIfCanBeEnabled_(obj);
},
});
}
private checkIfCanBeEnabled_(obj: BaseObject) {
if (obj?.isSatellite() && keepTrackApi.getSensorManager().isSensorSelected()) {
this.setBottomIconToEnabled();
if (this.isMenuButtonActive && obj) {
this.refreshSideMenuData(obj as DetailedSatellite);
}
} else {
if (this.isMenuButtonActive) {
this.closeSideMenu();
}
this.setBottomIconToDisabled();
}
}
addJs(): void {
super.addJs();
keepTrackApi.register({
event: KeepTrackApiEvents.staticOffsetChange,
cbName: this.constructor.name,
cb: () => {
const sat = this.selectSatManager_.getSelectedSat();
if (!sat?.isSatellite()) {
return;
}
this.refreshSideMenuData(sat as DetailedSatellite);
},
});
}
private refreshSideMenuData(sat: DetailedSatellite) {
if (this.isMenuButtonActive) {
if (sat) {
showLoading(() => {
// TODO: This should be a class property that persists between refreshes
const sensorListDom = getEl('multi-site-look-angles-sensor-list');
if (!sensorListDom) {
errorManagerInstance.warn('Could not find sensor list dom');
return;
}
sensorListDom.innerHTML = '';
const allSensors: DetailedSensor[] = [];
for (const sensor of this.sensorList_) {
if (!sensor.objName) {
continue;
}
const sensorButton = document.createElement('button');
sensorButton.classList.add('btn', 'btn-ui', 'waves-effect', 'waves-light');
if (this.disabledSensors_.includes(sensor)) {
sensorButton.classList.add('btn-red');
}
allSensors.push(sensor);
sensorButton.innerText = sensor.uiName ?? sensor.shortName ?? sensor.objName;
sensorButton.addEventListener('click', () => {
if (sensorButton.classList.contains('btn-red')) {
sensorButton.classList.remove('btn-red');
this.disabledSensors_.splice(this.disabledSensors_.indexOf(sensor), 1);
keepTrackApi.getSoundManager().play(SoundNames.TOGGLE_ON);
} else {
sensorButton.classList.add('btn-red');
this.disabledSensors_.push(sensor);
keepTrackApi.getSoundManager().play(SoundNames.TOGGLE_OFF);
}
this.getlookanglesMultiSite_(
sat,
allSensors.filter((s) => !this.disabledSensors_.includes(s)),
);
});
sensorListDom.appendChild(sensorButton);
sensorListDom.appendChild(document.createTextNode(' '));
}
this.getlookanglesMultiSite_(
sat,
allSensors.filter((s) => !this.disabledSensors_.includes(s)),
);
});
}
}
}
private getlookanglesMultiSite_(sat: DetailedSatellite, sensors?: DetailedSensor[]): void {
const timeManagerInstance = keepTrackApi.getTimeManager();
const sensorManagerInstance = keepTrackApi.getSensorManager();
const staticSet = keepTrackApi.getCatalogManager().staticSet;
if (!sensors) {
sensors = [];
for (const sensorName in staticSet) {
const sensor = staticSet[sensorName];
sensors.push(sensor);
}
}
const isResetToDefault = !sensorManagerInstance.isSensorSelected();
// Save Current Sensor as a new array
const tempSensor = [...sensorManagerInstance.currentSensors];
const orbitalPeriod = MINUTES_PER_DAY / ((sat.satrec.no * MINUTES_PER_DAY) / TAU); // Seconds in a day divided by mean motion
const multiSiteArray = <TearrData[]>[];
for (const sensor of sensors) {
// Skip if satellite is above the max range of the sensor
if (sensor.maxRng < sat.perigee && (!sensor.maxRng2 || sensor.maxRng2 < sat.perigee)) {
continue;
}
SensorManager.updateSensorUiStyling([sensor]);
let offset = 0;
for (let i = 0; i < this.lengthOfLookAngles_ * 24 * 60 * 60; i += this.angleCalculationInterval_) {
// 5second Looks
offset = i * 1000; // Offset in seconds (msec * 1000)
const now = timeManagerInstance.getOffsetTimeObj(offset);
const multiSitePass = MultiSiteLookAnglesPlugin.propagateMultiSite_(now, sat.satrec, sensor);
if (multiSitePass.time !== '') {
multiSiteArray.push(multiSitePass); // Update the table with looks for this 5 second chunk and then increase table counter by 1
// Jump 3/4th to the next orbit
i += orbitalPeriod * 60 * 0.75; // NOSONAR
}
}
}
multiSiteArray.sort((a, b) => new Date(a.time).getTime() - new Date(b.time).getTime());
sensorManagerInstance.lastMultiSiteArray = multiSiteArray;
// eslint-disable-next-line no-unused-expressions
isResetToDefault ? sensorManagerInstance.setCurrentSensor(null) : sensorManagerInstance.setCurrentSensor(tempSensor);
MultiSiteLookAnglesPlugin.populateMultiSiteTable_(multiSiteArray);
}
private static propagateMultiSite_(now: Date, satrec: SatelliteRecord, sensor: DetailedSensor): TearrData {
// Setup Realtime and Offset Time
const aer = SatMath.getRae(now, satrec, sensor);
if (SatMath.checkIsInView(sensor, aer)) {
return {
time: now.toISOString(),
el: aer.el,
az: aer.az,
rng: aer.rng,
objName: sensor.objName,
};
}
return {
time: '',
el: <Degrees>0,
az: <Degrees>0,
rng: <Kilometers>0,
objName: '',
};
}
private static populateMultiSiteTable_(multiSiteArray: TearrData[]) {
const sensorManagerInstance = keepTrackApi.getSensorManager();
const staticSet = keepTrackApi.getCatalogManager().staticSet;
const tbl = <HTMLTableElement>getEl('multi-site-look-angles-table'); // Identify the table to update
tbl.innerHTML = ''; // Clear the table from old object data
let tr = tbl.insertRow();
let tdT = tr.insertCell();
tdT.appendChild(document.createTextNode('Time'));
tdT.setAttribute('style', 'text-decoration: underline');
let tdE = tr.insertCell();
tdE.appendChild(document.createTextNode('El'));
tdE.setAttribute('style', 'text-decoration: underline');
let tdA = tr.insertCell();
tdA.appendChild(document.createTextNode('Az'));
tdA.setAttribute('style', 'text-decoration: underline');
let tdR = tr.insertCell();
tdR.appendChild(document.createTextNode('Rng'));
tdR.setAttribute('style', 'text-decoration: underline');
let tdS = tr.insertCell();
tdS.appendChild(document.createTextNode('Sensor'));
tdS.setAttribute('style', 'text-decoration: underline');
const timeManagerInstance = keepTrackApi.getTimeManager();
for (const entry of multiSiteArray) {
const sensor = staticSet.find((s) => s.objName === entry.objName);
if (!sensor) {
continue;
}
tr = tbl.insertRow();
tr.setAttribute('class', 'link');
tdT = tr.insertCell();
tdT.appendChild(document.createTextNode(dateFormat(entry.time, 'isoDateTime', true)));
tdE = tr.insertCell();
tdE.appendChild(document.createTextNode(entry.el.toFixed(1)));
tdA = tr.insertCell();
tdA.appendChild(document.createTextNode(entry.az.toFixed(0)));
tdR = tr.insertCell();
tdR.appendChild(document.createTextNode(entry.rng.toFixed(0)));
tdS = tr.insertCell();
tdS.appendChild(document.createTextNode(sensor.uiName ?? sensor.shortName ?? sensor.objName ?? ''));
// TODO: Future feature
tr.addEventListener('click', () => {
timeManagerInstance.changeStaticOffset(new Date(entry.time).getTime() - new Date().getTime());
sensorManagerInstance.setSensor(sensor, sensor.sensorId);
});
}
}
}