Skip to content

Commit b3bd28a

Browse files
committed
Add homepage with diagnostics
1 parent 1e5ae7c commit b3bd28a

File tree

5 files changed

+107
-15
lines changed

5 files changed

+107
-15
lines changed

bossphorus/__init__.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,24 @@
1818

1919
import io
2020
import json
21-
21+
import os
2222
from typing import List
2323

2424
import blosc
25-
from flask import Flask, request, Response, jsonify, make_response
25+
from flask import Flask, request, Response, jsonify, make_response, render_template
2626
import numpy as np
2727

2828
from . import storagemanager
2929
from . import version
3030

3131
__version__ = version.__version__
3232

33+
3334
def create_app(mgr: storagemanager.StorageManager = None):
3435
"""
3536
Create a Bossphorus server app.
3637
"""
37-
app = Flask(__name__)
38+
app = Flask(__name__, os.path.realpath(__file__))
3839
if mgr:
3940
manager = mgr
4041
else:
@@ -57,7 +58,8 @@ def upload_cutout_xyz(collection, experiment, channel, resolution, x_range, y_ra
5758
zs = [int(i) for i in z_range.split(":")]
5859
data = data.reshape(xs[1] - xs[0], ys[1] - ys[0], zs[1] - zs[0])
5960
data = data.transpose()
60-
manager.setdata(data, collection, experiment, channel, resolution, zs, ys, xs)
61+
manager.setdata(data, collection, experiment,
62+
channel, resolution, zs, ys, xs)
6163
return make_response("", 201)
6264

6365
@app.route(
@@ -74,7 +76,8 @@ def upload_cutout_json(collection, experiment, channel, resolution, x_range, y_r
7476
ys = [int(i) for i in y_range.split(":")]
7577
zs = [int(i) for i in z_range.split(":")]
7678
data = data.reshape(xs[1] - xs[0], ys[1] - ys[0], zs[1] - zs[0])
77-
manager.setdata(data, collection, experiment, channel, resolution, xs, ys, zs)
79+
manager.setdata(data, collection, experiment,
80+
channel, resolution, xs, ys, zs)
7881
return ""
7982

8083
@app.route(
@@ -112,7 +115,7 @@ def get_experiment(collection, experiment):
112115
return jsonify({
113116
"name": experiment,
114117
"collection": collection,
115-
"coord_frame": "NoneSpecified", # TODO
118+
"coord_frame": "NoneSpecified", # TODO
116119
"description": "",
117120
"type": "image",
118121
"base_resolution": 0,
@@ -153,7 +156,8 @@ def get_cutout_xyz(collection, experiment, channel, resolution, x_range, y_range
153156
ys = [int(i) for i in y_range.split(":")]
154157
zs = [int(i) for i in z_range.split(":")]
155158
try:
156-
data = manager.getdata(collection, experiment, channel, resolution, xs, ys, zs)
159+
data = manager.getdata(
160+
collection, experiment, channel, resolution, xs, ys, zs)
157161
data = np.ascontiguousarray(np.transpose(data))
158162
response = make_response(blosc.compress(data, typesize=16))
159163
return response
@@ -165,8 +169,12 @@ def get_cutout_xyz(collection, experiment, channel, resolution, x_range, y_range
165169
)
166170

167171
@app.route("/")
168-
def hello():
169-
"""Root route."""
170-
return __version__
172+
def home():
173+
return render_template("home.html", **{
174+
"version": __version__,
175+
"cache_stack":
176+
[*manager.get_stack_names()]
177+
178+
})
171179

172180
return app

bossphorus/storagemanager/StorageManager.py

+4
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ def setdata(
4949
xs: Tuple[int, int], ys: Tuple[int, int], zs: Tuple[int, int]
5050
):
5151
...
52+
53+
@abstractmethod
54+
def get_stack_names(self):
55+
...

bossphorus/storagemanager/_FilesystemStorageManager.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
"""
16-
from typing import Tuple
16+
from typing import Tuple, List
1717

1818
import os
1919
import numpy as np
2020

2121
from .StorageManager import StorageManager
2222
from .utils import file_compute, blockfile_indices
2323

24+
2425
class FilesystemStorageManager(StorageManager):
2526
"""
2627
File System management for volumetric data.
@@ -39,6 +40,7 @@ def __init__(
3940
storage_path: Where to store the data tree
4041
block_size: How much data should go in each file
4142
"""
43+
self.name = "FilesystemStorageManager"
4244
self.is_terminal = is_terminal
4345
self.storage_path = storage_path
4446
self.block_size = block_size
@@ -123,9 +125,9 @@ def getdata(self, col: str, exp: str, chan: str, res: int,
123125
i[2][0]:i[2][1],
124126
]
125127
payload[
126-
(f[0] + i[0][0]) - xs[0] : (f[0] + i[0][1]) - xs[0],
127-
(f[1] + i[1][0]) - ys[0] : (f[1] + i[1][1]) - ys[0],
128-
(f[2] + i[2][0]) - zs[0] : (f[2] + i[2][1]) - zs[0],
128+
(f[0] + i[0][0]) - xs[0]: (f[0] + i[0][1]) - xs[0],
129+
(f[1] + i[1][0]) - ys[0]: (f[1] + i[1][1]) - ys[0],
130+
(f[2] + i[2][0]) - zs[0]: (f[2] + i[2][1]) - zs[0],
129131
] = data_partial
130132

131133
return payload
@@ -178,3 +180,6 @@ def retrieve(self, col: str, exp: str, chan: str, res: int,
178180
(b[2], b[2] + self.block_size[2]),
179181
)
180182
return np.load(fname)
183+
184+
def get_stack_names(self) -> List[str]:
185+
return [self.name, *["<END>" if self.is_terminal else "dest"]]

bossphorus/templates/home.html

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
9+
<style>
10+
body,
11+
html {
12+
font-family: 'Roboto', sans-serif;
13+
max-width: 70em;
14+
margin: auto;
15+
}
16+
17+
table {
18+
width: 100%;
19+
}
20+
21+
table tr:nth-child(2n),
22+
thead {
23+
background: rgba(10, 10, 40, 0.05);
24+
}
25+
26+
tr:hover {
27+
background: rgba(100, 100, 150, 0.1) !important;
28+
}
29+
30+
blockquote {
31+
background: rgba(10, 20, 10, 0.05);
32+
padding: 1em;
33+
}
34+
</style>
35+
<title>bossphorus {{ version }}</title>
36+
</head>
37+
38+
<body>
39+
<center>
40+
<h1>bossphorus server is running.</h1>
41+
<h6>bossphorus version {{ version }}</h6>
42+
</center>
43+
44+
<blockquote>
45+
<table>
46+
<thead>
47+
<tr>
48+
<th>Key</th>
49+
<th>Value</th>
50+
<th>Notes</th>
51+
</tr>
52+
</thead>
53+
<tbody>
54+
<tr>
55+
<td>Version</td>
56+
<td>{{ version }}</td>
57+
<td></td>
58+
</tr>
59+
<tr>
60+
<td rowspan="{{(cache_stack | length) + 1 }}">Cache Stack</td>
61+
<td><code>API Layer</code></td>
62+
<td></td>
63+
</tr>
64+
{% for layer in cache_stack %}
65+
<tr>
66+
<td><code>{{ layer }}</code></td>
67+
<td></td>
68+
</tr>
69+
{% endfor %}
70+
</tbody>
71+
</table>
72+
</blockquote>
73+
</body>
74+
75+
</html>

local_debug_run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
from bossphorus import create_app
1818

1919
app = create_app()
20-
app.run(host="0.0.0.0", port=5000, debug=True)
20+
app.run(host="0.0.0.0", port=5050, debug=True)

0 commit comments

Comments
 (0)