Skip to content

Commit 723dcc9

Browse files
dgarciabrisenoDaniel Garcia Briseno
andauthored
Replace data coverage charts with a dashboard from Apache Superset (#473)
* Add superset data coverage page * Link to new coverage page * Remove old coverages * Put dashboard ID in configuration --------- Co-authored-by: Daniel Garcia Briseno <daniel.garciabriseno@nasa.gov>
1 parent c87991c commit 723dcc9

4 files changed

Lines changed: 157 additions & 52 deletions

File tree

docroot/statistics/bokeh/coverages/index.html

Lines changed: 0 additions & 26 deletions
This file was deleted.

docroot/statistics/coverage.php

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php
2+
require_once '../../src/Config.php';
3+
$config = new Config('../../settings/Config.ini');
4+
?>
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<title>Helioviewer.org - Data Coverage Statistics</title>
10+
<style>
11+
html, body {
12+
height: 100%;
13+
margin: 0;
14+
padding: 0;
15+
background-color: #1a1a1a;
16+
color: #e0e0e0;
17+
}
18+
#main {
19+
display: flex;
20+
flex-direction: column;
21+
height: 100vh;
22+
background-color: #1a1a1a;
23+
}
24+
#header {
25+
flex-shrink: 0;
26+
background-color: #2a2a2a;
27+
padding: 5px 10px;
28+
display: flex;
29+
align-items: center;
30+
gap: 10px;
31+
}
32+
#header img {
33+
height: 30px;
34+
width: auto;
35+
}
36+
#headerText {
37+
color: #e0e0e0;
38+
font-size: 14px;
39+
margin: 0;
40+
}
41+
#dashboard-container {
42+
flex: 1;
43+
width: 100vw;
44+
min-height: 0;
45+
margin: 0;
46+
padding: 0;
47+
}
48+
#dashboard-container iframe {
49+
width: 100%;
50+
height: 100%;
51+
border: none;
52+
display: block;
53+
}
54+
#error-message {
55+
display: none;
56+
padding: 10px;
57+
margin: 10px;
58+
background-color: #5c1c1c;
59+
color: #ff8a80;
60+
border-radius: 4px;
61+
}
62+
#loading-message {
63+
padding: 10px;
64+
margin: 10px;
65+
text-align: center;
66+
font-size: 14px;
67+
color: #e0e0e0;
68+
}
69+
</style>
70+
</head>
71+
72+
<body>
73+
<div id="main">
74+
<div id="header">
75+
<img src="../resources/images/logos/hvlogo1s_transparent_logo.png" alt="Helioviewer logo" />
76+
<div id='headerText'>The Helioviewer Project - Data Coverage</div>
77+
</div>
78+
79+
<div id="loading-message">Loading dashboard...</div>
80+
<div id="error-message"></div>
81+
<div id="dashboard-container"></div>
82+
</div>
83+
84+
<script src="https://unpkg.com/@superset-ui/embedded-sdk"></script>
85+
<script type="text/javascript">
86+
const DASHBOARD_ID = '<?= HV_SUPERSET_COVERAGE_DASHBOARD_ID ?>';
87+
const GUEST_TOKEN_URL = '<?= HV_SUPERSET_SIDECAR_URL ?>/guest_token.php';
88+
const SUPERSET_URL = '<?= HV_SUPERSET_URL ?>';
89+
90+
async function fetchGuestToken() {
91+
try {
92+
const response = await fetch(GUEST_TOKEN_URL, {
93+
method: 'POST',
94+
headers: {
95+
'Content-Type': 'application/json',
96+
},
97+
body: JSON.stringify({
98+
dashboard_id: DASHBOARD_ID
99+
})
100+
});
101+
102+
if (!response.ok) {
103+
throw new Error(`HTTP error! status: ${response.status}`);
104+
}
105+
106+
const data = await response.json();
107+
108+
if (!data.success || !data.token) {
109+
throw new Error('Failed to retrieve guest token from response');
110+
}
111+
112+
return data.token;
113+
} catch (error) {
114+
console.error('Error fetching guest token:', error);
115+
throw error;
116+
}
117+
}
118+
119+
async function embedDashboard() {
120+
try {
121+
const guestToken = await fetchGuestToken();
122+
123+
// Hide loading message
124+
document.getElementById('loading-message').style.display = 'none';
125+
126+
// Embed the dashboard
127+
supersetEmbeddedSdk.embedDashboard({
128+
id: DASHBOARD_ID,
129+
supersetDomain: SUPERSET_URL,
130+
mountPoint: document.getElementById('dashboard-container'),
131+
fetchGuestToken: () => guestToken,
132+
dashboardUiConfig: {
133+
hideTitle: true,
134+
hideChartControls: false,
135+
hideTab: false,
136+
},
137+
});
138+
} catch (error) {
139+
console.error('Error embedding dashboard:', error);
140+
document.getElementById('loading-message').style.display = 'none';
141+
const errorDiv = document.getElementById('error-message');
142+
errorDiv.style.display = 'block';
143+
errorDiv.textContent = 'Failed to load dashboard: ' + error.message;
144+
}
145+
}
146+
147+
// Initialize dashboard when page loads
148+
window.addEventListener('load', embedDashboard);
149+
</script>
150+
</body>
151+
</html>

docroot/status/index.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,6 @@
3333
"RHESSI" => $PROVIDERS['RHESSI']
3434
);
3535

36-
const COVERAGE = array (
37-
"AIA" => "SDO_coverage.html",
38-
"HMI" => "SDO_coverage.html",
39-
"EIT" => "SOHO_coverage.html",
40-
"LASCO" => "SOHO_coverage.html",
41-
"COSMO" => "MLSO_coverage.html",
42-
"EUI" => "SOLO_coverage.html",
43-
"COR1-A" => "STEREO_A_coverage.html",
44-
"COR2-A" => "STEREO_A_coverage.html",
45-
"EUVI-A" => "STEREO_A_coverage.html",
46-
"COR1-B" => "STEREO_B_coverage.html",
47-
"COR2-B" => "STEREO_B_coverage.html",
48-
"EUVI-B" => "STEREO_B_coverage.html",
49-
"IRIS" => "IRIS_coverage.html",
50-
"SWAP" => "PROBA2_coverage.html",
51-
"SXT" => "Yohkoh_coverage.html",
52-
"XRT" => "Hinode_coverage.html",
53-
"RHESSI" => "RHESSI_coverage.html"
54-
);
55-
5636
const TABLE_ROW_TEMPLATE = "<tr class='%s'><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td align='center'>%s</td></tr>";
5737

5838
function formatDate(?DateTime $date) {
@@ -102,12 +82,7 @@ function genRobLink($name, $url) {
10282
}
10383

10484
function genCoverageLink($source) {
105-
$instrument = explode(" ", $source)[0];
106-
if (array_key_exists($instrument, COVERAGE)) {
107-
$coverage_page = "/statistics/bokeh/coverages/" . COVERAGE[$instrument];
108-
} else {
109-
$coverage_page = "#";
110-
}
85+
$coverage_page = "/statistics/coverage.php";
11186
return "<a href=".$coverage_page.">$source</a>";
11287
}
11388

settings/Config.Example.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,8 @@ http_export = ''
192192
# If running the coordinator locally, then change this to
193193
# http://localhost:port
194194
coordinator_url = 'http://coordinator'
195+
196+
[superset]
197+
superset_url = 'http://localhost:8088'
198+
superset_sidecar_url = 'http://localhost:8087'
199+
superset_coverage_dashboard_id = 'your-dashboard-id-here'

0 commit comments

Comments
 (0)