diff --git a/pychunkedgraph/app/segmentation/common.py b/pychunkedgraph/app/segmentation/common.py index 89696c61f..77144133b 100644 --- a/pychunkedgraph/app/segmentation/common.py +++ b/pychunkedgraph/app/segmentation/common.py @@ -853,8 +853,11 @@ def merge_log(table_id, root_id): def _parse_timestamp(arg_name, default_timestamp=0, return_datetime=False): """Convert seconds since epoch to UTC datetime.""" + timestamp = request.args.get(arg_name, default_timestamp) + if timestamp is None: + raise (cg_exceptions.BadRequest(f"Timestamp parameter {arg_name} is mandatory")) try: - timestamp = float(request.args.get(arg_name, default_timestamp)) + timestamp = float(timestamp) if return_datetime: return datetime.fromtimestamp(timestamp, UTC) else: @@ -1191,3 +1194,18 @@ def parse_attr(attr, val) -> str: details[_k] = _v result[int(k)] = details return result + + +### DELTA ROOTS ------------------------------------------------------------ + + +def delta_roots(table_id): + current_app.table_id = table_id + + timestamp_past = _parse_timestamp("timestamp_past", None, return_datetime=True) + timestamp_future = _parse_timestamp( + "timestamp_future", time.time(), return_datetime=True + ) + cg = app_utils.get_cg(table_id) + old_roots, new_roots = cg.get_proofread_root_ids(timestamp_past, timestamp_future) + return {"old_roots": old_roots, "new_roots": new_roots} diff --git a/pychunkedgraph/app/segmentation/v1/routes.py b/pychunkedgraph/app/segmentation/v1/routes.py index 6e48ba57f..83af1118f 100644 --- a/pychunkedgraph/app/segmentation/v1/routes.py +++ b/pychunkedgraph/app/segmentation/v1/routes.py @@ -501,3 +501,14 @@ def operation_details(table_id): int64_as_str = request.args.get("int64_as_str", default=False, type=toboolean) resp = common.operation_details(table_id) return jsonify_with_kwargs(resp, int64_as_str=int64_as_str) + + +### GET PROOFREAD IDS -------------------------------------------------------- + + +@bp.route("/table//delta_roots", methods=["GET"]) +@auth_requires_permission("view") +def delta_roots(table_id): + int64_as_str = request.args.get("int64_as_str", default=False, type=toboolean) + resp = common.delta_roots(table_id) + return jsonify_with_kwargs(resp, int64_as_str=int64_as_str)