Skip to content

Commit 5a9981f

Browse files
committed
Added monitor page
1 parent a0fde3d commit 5a9981f

File tree

6 files changed

+82
-96
lines changed

6 files changed

+82
-96
lines changed

src/superannotate/lib/app/input_converters/sa_conversion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ def from_pixel_to_vector(json_paths, output_dir):
6868
outer_points = contours[outer].flatten().tolist()
6969
exclude_points = [contours[i].flatten().tolist() for i in inners]
7070
temp = instance.copy()
71-
del temp['parts']
71+
del temp["parts"]
7272
temp["pointLabels"] = {}
7373
temp["groupId"] = group_id
7474
temp["type"] = "polygon"
7575
temp["points"] = outer_points
7676
temp["exclude"] = exclude_points
7777
new_instances.append(temp)
7878

79-
sa_json['instances'] = new_instances
79+
sa_json["instances"] = new_instances
8080
write_to_json(output_dir / file_name, sa_json)
8181
img_names.append(file_name.replace("___objects.json", ""))
8282
return img_names

src/superannotate/lib/app/server/__app.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
from superannotate import SAServer
1+
from superannotate import create_app
2+
from superannotate import SAClient
23

3-
app = SAServer()
4+
sa_client = SAClient()
5+
app = create_app([])
46

57

6-
@app.route("/", methods=["POST"])
8+
@app.route("/", methods=["GET"])
9+
def health_check(request):
10+
return "Hello World!!!"
11+
12+
13+
@app.route("/project_created", methods=["POST"])
714
def index(request):
8-
return "Hello, World!"
15+
"""
16+
Create default folders when project created.
17+
"""
18+
project_name = request.json["after"]["name"]
19+
sa_client.create_folder(project_name, "default_folder_1")
20+
sa_client.create_folder(project_name, "default_folder_2")
21+
return "Default folders created."
922

1023

1124
if __name__ == "__main__":

src/superannotate/lib/app/server/default_app.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import linecache
32

43
from lib.app.server import SAServer
54
from lib.core import LOG_FILE_LOCATION
@@ -16,23 +15,17 @@ def monitor_view(request):
1615

1716
@app.route("/logs", methods=["GET"])
1817
def logs(request):
19-
data = []
20-
limit = 20
21-
items = []
22-
cursor = None
23-
offset = request.args.get('offset', None)
18+
offset = request.args.get("offset", None)
2419
if offset:
2520
offset = int(offset)
26-
limit = int(request.args.get('limit', 20))
27-
response = {
28-
'data': []
29-
}
21+
limit = int(request.args.get("limit", 20))
22+
response = {"data": []}
3023

3124
with open(f"{LOG_FILE_LOCATION}/sa_server.log") as log_file:
3225
log_file.seek(0, 2)
3326
if not offset:
3427
offset = log_file.tell()
35-
cursor = max(offset - 2048, 0)
28+
cursor = max(offset - 2048, 0)
3629
while True:
3730
log_file.seek(cursor, 0)
3831
tmp_cursor = cursor
@@ -42,18 +35,17 @@ def logs(request):
4235
cursor = max(cursor - 2048, 0)
4336
break
4437
try:
45-
response['data'].append(json.loads(line))
46-
except Exception:
38+
response["data"].append(json.loads(line))
39+
except Exception as _:
4740
...
4841
cursor = max(cursor - 2048, 0)
49-
if len(response['data']) >= limit or cursor == 0:
42+
if len(response["data"]) >= limit or cursor == 0:
5043
break
51-
response['data'] = []
52-
response['offset'] = cursor
44+
response["data"] = []
45+
response["offset"] = cursor
5346
return response
5447

5548

56-
5749
#
5850
# @app.route("/_log_stream", methods=["GET"])
5951
# def log_stream(request):

src/superannotate/lib/app/server/templates/monitor.html

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<body>
7777
<div class="container py-4 page-wrapper">
7878
<div class="row content-wrapper">
79-
<div class="col-6 left-content">
79+
<div class="col-6 left-content" id="left-content">
8080
<div class="d-flex space-between align-items-center mb-3 request-list-header pb-1">
8181
<h5>All Requests</h5>
8282
</div>
@@ -144,40 +144,64 @@ <h5 class="mb-2 mt-2">Response</h5>
144144
</div>
145145
</div>
146146
<script>
147+
let offset = 0;
148+
const limit =20;
149+
const path = `${window.location.origin}/logs`;
147150
$.ajax({
148-
url: `${window.location.origin}/logs`,
151+
url: `${path}?limit=${limit}`,
149152
dataType: "text",
150-
success: function (data) {
151-
var jsondata = $.parseJSON(data);
152-
$.each(jsondata.data, function (index, item) {
153-
const requestItem = jQuery(`<div class="row p-2 mb-2 request-item">
153+
success: (data) => renderLogs(data)
154+
});
155+
156+
$('#left-content').scroll(function () {
157+
if (this.scrollTop === (this.scrollHeight - this.offsetHeight) && offset) {
158+
$.ajax({
159+
url: `${path}?limit=${limit}&offset=${offset}`,
160+
dataType: "text",
161+
success: (data) => renderLogs(data)
162+
});
163+
164+
}
165+
}
166+
);
167+
168+
function renderLogs(data) {
169+
let jsondata = $.parseJSON(data);
170+
if (!jsondata.data.length) {
171+
offset = null;
172+
return;
173+
}
174+
175+
$.each(jsondata.data, function (index, item) {
176+
const requestItem = jQuery(`<div class="row p-2 mb-2 request-item">
154177
<div class="col-3">${item.request.method}</div>
155178
<div class="col-7">${item.request.path}</div>
156179
<div class="col-1">${item.response.status_code}</div>
157180
</div>`)
158-
requestItem.click(function () {
159-
$(this).siblings('div.request-item').removeClass('active-request-item');
160-
$(this).addClass('active-request-item');
161-
$('#selected-request').empty().append(`${item.request.method} ${item.request.path}`);
162-
$('#request-header').empty().append(`<pre>${JSON.stringify(item.request.headers, null, 4)}</pre>`);
163-
$('#response-header').empty().append(`<pre>${JSON.stringify(item.response.headers, null, 4)}</pre>`);
164-
$('#request-body').empty().append(`<pre>${JSON.stringify(item.request.data, null, 4)}</pre>`);
165-
$('#response-body').empty().append(`<pre>${JSON.stringify(item.response.data, null, 4)}</pre>`);
166-
$("#right-content").animate({scrollTop: 0}, "fast");
167-
})
168-
169-
170-
$('#request-list-wrapper').append(requestItem);
171-
if (index === 0) {
172-
requestItem.click();
173-
}
174-
});
175-
}
176-
});
181+
requestItem.click(function () {
182+
$(this).siblings('div.request-item').removeClass('active-request-item');
183+
$(this).addClass('active-request-item');
184+
$('#selected-request').empty().append(`${item.request.method} ${item.request.path}`);
185+
$('#request-header').empty().append(`<pre>${JSON.stringify(item.request.headers, null, 4)}</pre>`);
186+
$('#response-header').empty().append(`<pre>${JSON.stringify(item.response.headers, null, 4)}</pre>`);
187+
$('#request-body').empty().append(`<pre>${JSON.stringify(item.request.data, null, 4)}</pre>`);
188+
$('#response-body').empty().append(`<pre>${JSON.stringify(item.response.data, null, 4)}</pre>`);
189+
$("#right-content").animate({scrollTop: 0}, "fast");
190+
})
191+
192+
193+
$('#request-list-wrapper').append(requestItem);
194+
if (index === 0 && offset === 0) {
195+
requestItem.click();
196+
}
197+
198+
offset = jsondata.offset
199+
});
200+
}
177201
</script>
178202
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
179203
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
180204
crossorigin="anonymous"></script>
181205
</body>
182206

183-
</html>
207+
</html>

src/superannotate/lib/app/server/templates/monitor_old.html

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

src/superannotate/lib/core/usecases/images.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,10 @@ def __init__(
654654
)
655655

656656
def validate_project_type(self):
657-
if self._project.type in constances.LIMITED_FUNCTIONS:
658-
raise AppValidationException(
659-
constances.LIMITED_FUNCTIONS[self._project.type]
660-
)
661-
if self._project.upload_state == constances.UploadState.EXTERNAL.value:
657+
if (
658+
self._project.type in constances.LIMITED_FUNCTIONS
659+
or self._project.upload_state == constances.UploadState.EXTERNAL.value
660+
):
662661
raise AppValidationException(
663662
"The feature does not support projects containing attached URLs."
664663
)

0 commit comments

Comments
 (0)