-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathtracking-impact-predict.ts
230 lines (186 loc) · 7.7 KB
/
tracking-impact-predict.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
import { errorManagerInstance } from '@app/singletons/errorManager';
import sputnickPng from '@public/img/icons/sputnick.png';
import './tracking-impact-predict.css';
import { KeepTrackApiEvents, ToastMsgType } from '@app/interfaces';
import { getEl } from '@app/lib/get-el';
import { showLoading } from '@app/lib/showLoading';
import { keepTrackApi } from '../../keepTrackApi';
import { clickDragOptions, KeepTrackPlugin } from '../KeepTrackPlugin';
import { SelectSatManager } from '../select-sat-manager/select-sat-manager';
export interface TipMsg {
'NORAD_CAT_ID': string,
'MSG_EPOCH': string,
'INSERT_EPOCH': string,
'DECAY_EPOCH': string,
'WINDOW': string,
'REV': string,
'DIRECTION': string,
'LAT': string,
'LON': string,
'INCL': string,
'NEXT_REPORT': string,
'ID': string,
'HIGH_INTEREST': string,
'OBJECT_NUMBER': string,
}
export class TrackingImpactPredict extends KeepTrackPlugin {
protected dependencies_: string[];
private readonly tipDataSrc = './data/tip.json';
private selectSatIdOnCruncher_: number | null = null;
private tipList_ = <TipMsg[]>[];
bottomIconElementName: string = 'menu-satellite-tip';
bottomIconImg = sputnickPng;
bottomIconLabel: string = 'Reentry Prediction';
sideMenuElementName: string = 'tip-menu';
sideMenuElementHtml = keepTrackApi.html`
<div id="tip-menu" class="side-menu-parent start-hidden text-select">
<div id="tip-content" class="side-menu">
<div class="row">
<h5 class="center-align">Tracking and Impact Messages</h5>
<table id="tip-table" class="center-align"></table>
</div>
</div>
</div>`;
helpTitle = 'Tracking and Impact Prediction';
helpBody = keepTrackApi.html`The Tracking and Impact Prediction (tip) menu displays the latest tracking and impact prediction messages for satellites.
The table shows the following columns:<br><br>
<b>NORAD</b>: The NORAD catalog ID of the satellite.<br><br>
<b>Decay Date</b>: The date of the predicted decay of the satellite.<br><br>
<b>Latitude</b>: The latitude of the satellite.<br><br>
<b>Longitude</b>: The longitude of the satellite.<br><br>
<b>Window (min)</b>: The time window in minutes for the prediction.<br><br>
<b>Next Report</b>: The date of the next report.<br><br>
<b>High Interest?</b>: Whether the satellite is of high interest.<br><br>
All data for reentries is sourced from the Tracking and Impact Prediction (TIP) messages provided by the US Space Command (USSPACECOM).
`;
dragOptions: clickDragOptions = {
isDraggable: true,
minWidth: 700,
maxWidth: 850,
};
bottomIconCallback: () => void = () => {
if (this.isMenuButtonActive) {
this.parsetipData_();
}
};
addJs(): void {
super.addJs();
keepTrackApi.register({
event: KeepTrackApiEvents.uiManagerFinal,
cbName: this.constructor.name,
cb: this.uiManagerFinal_.bind(this),
});
keepTrackApi.register({
event: KeepTrackApiEvents.onCruncherMessage,
cbName: this.constructor.name,
cb: () => {
if (this.selectSatIdOnCruncher_ !== null) {
// If selectedSatManager is loaded, set the selected sat to the one that was just added
keepTrackApi.getPlugin(SelectSatManager)?.selectSat(this.selectSatIdOnCruncher_);
this.selectSatIdOnCruncher_ = null;
}
},
});
}
private uiManagerFinal_() {
getEl(this.sideMenuElementName).addEventListener('click', (evt: any) => {
showLoading(() => {
const el = <HTMLElement>evt.target.parentElement;
if (!el.classList.contains('tip-object')) {
return;
}
// Might be better code for this.
const hiddenRow = el.dataset?.row;
if (hiddenRow !== null) {
this.eventClicked_(parseInt(hiddenRow));
}
});
});
}
private parsetipData_() {
if (this.tipList_.length === 0) {
// Only generate the table if receiving the -1 argument for the first time
fetch(this.tipDataSrc).then((response) => {
response.json().then((tipList: TipMsg[]) => {
this.setTipList_(tipList);
this.createTable_();
if (this.tipList_.length === 0) {
errorManagerInstance.warn('No tip data found!');
}
});
});
}
}
// sort by MSG_EPOCH and then keep only the newest for each NORAD_CAT_ID
private setTipList_(tipList: TipMsg[]) {
this.tipList_ = tipList;
this.tipList_.sort((a, b) => new Date(b.MSG_EPOCH).getTime() - new Date(a.MSG_EPOCH).getTime());
this.tipList_ = this.tipList_.filter((v, i, a) => a.findIndex((t) => t.NORAD_CAT_ID === v.NORAD_CAT_ID) === i);
this.tipList_.sort((a, b) => new Date(b.DECAY_EPOCH).getTime() - new Date(a.DECAY_EPOCH).getTime());
}
private eventClicked_(row: number) {
// Check if the selected satellite is still in orbit
const sat = keepTrackApi.getCatalogManager().sccNum2Sat(parseInt(this.tipList_[row].NORAD_CAT_ID));
if (!sat) {
keepTrackApi.getUiManager().toast('Satellite appears to have decayed!', ToastMsgType.caution);
return;
}
const now = new Date();
const decayEpoch = new Date(Date.UTC(
parseInt(this.tipList_[row].DECAY_EPOCH.substring(0, 4)), // year
parseInt(this.tipList_[row].DECAY_EPOCH.substring(5, 7)) - 1, // month (0-based)
parseInt(this.tipList_[row].DECAY_EPOCH.substring(8, 10)), // day
parseInt(this.tipList_[row].DECAY_EPOCH.substring(11, 13)), // hour
parseInt(this.tipList_[row].DECAY_EPOCH.substring(14, 16)), // minute
parseInt(this.tipList_[row].DECAY_EPOCH.substring(17, 19)), // second
));
keepTrackApi.getTimeManager().changeStaticOffset(decayEpoch.getTime() - now.getTime());
keepTrackApi.getMainCamera().isAutoPitchYawToTarget = false;
keepTrackApi.getUiManager().doSearch(`${sat.sccNum5}`);
this.selectSatIdOnCruncher_ = sat.id;
}
private createTable_(): void {
try {
const tbl = <HTMLTableElement>getEl('tip-table'); // Identify the table to update
tbl.innerHTML = ''; // Clear the table from old object data
TrackingImpactPredict.createHeaders_(tbl);
this.createBody_(tbl);
} catch (e) {
errorManagerInstance.warn('Error processing SOCRATES data!');
}
}
private createBody_(tbl: HTMLTableElement) {
for (let i = 0; i < this.tipList_.length; i++) {
this.createRow_(tbl, i);
}
}
private static createHeaders_(tbl: HTMLTableElement) {
const tr = tbl.insertRow();
const names = ['NORAD', 'Decay Date', 'Latitude', 'Longitude', 'Window (min)', 'Next Report', 'High Interest?'];
for (const name of names) {
const column = tr.insertCell();
column.appendChild(document.createTextNode(name));
column.setAttribute('style', 'text-decoration: underline');
column.setAttribute('class', 'center');
}
}
private createRow_(tbl: HTMLTableElement, i: number): HTMLTableRowElement {
// Create a new row
const tr = tbl.insertRow();
tr.setAttribute('class', 'tip-object link');
tr.setAttribute('data-row', i.toString());
// Populate the table with the data
TrackingImpactPredict.createCell_(tr, this.tipList_[i].NORAD_CAT_ID);
TrackingImpactPredict.createCell_(tr, this.tipList_[i].DECAY_EPOCH);
TrackingImpactPredict.createCell_(tr, this.tipList_[i].LAT);
TrackingImpactPredict.createCell_(tr, this.tipList_[i].LON);
TrackingImpactPredict.createCell_(tr, this.tipList_[i].WINDOW);
TrackingImpactPredict.createCell_(tr, this.tipList_[i].NEXT_REPORT);
TrackingImpactPredict.createCell_(tr, this.tipList_[i].HIGH_INTEREST);
return tr;
}
private static createCell_(tr: HTMLTableRowElement, text: string): void {
const cell = tr.insertCell();
cell.appendChild(document.createTextNode(text));
}
}