mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-08 02:38:11 +08:00
thuang-compress-annotation (#1980)
* thuang-compress-annotation * compress test * use zlib.decompress directly
This commit is contained in:
Generated
+1
-2
@@ -15483,8 +15483,7 @@
|
|||||||
"pako": {
|
"pako": {
|
||||||
"version": "1.0.11",
|
"version": "1.0.11",
|
||||||
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
|
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
|
||||||
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==",
|
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"parallel-transform": {
|
"parallel-transform": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
"is-number": "^7.0.0",
|
"is-number": "^7.0.0",
|
||||||
"lodash": "^4.17.20",
|
"lodash": "^4.17.20",
|
||||||
"memoize-one": "^5.1.1",
|
"memoize-one": "^5.1.1",
|
||||||
|
"pako": "^1.0.11",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-async": "^10.0.1",
|
"react-async": "^10.0.1",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
Action creators for user annotation
|
Action creators for user annotation
|
||||||
*/
|
*/
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import pako from "pako";
|
||||||
import * as globals from "../globals";
|
import * as globals from "../globals";
|
||||||
import { MatrixFBS, AnnotationsHelpers } from "../util/stateManager";
|
import { MatrixFBS, AnnotationsHelpers } from "../util/stateManager";
|
||||||
|
|
||||||
@@ -347,6 +348,7 @@ export const saveObsAnnotationsAction = () => async (dispatch, getState) => {
|
|||||||
|
|
||||||
const df = await annoMatrix.fetch("obs", writableAnnotations(annoMatrix));
|
const df = await annoMatrix.fetch("obs", writableAnnotations(annoMatrix));
|
||||||
const matrix = MatrixFBS.encodeMatrixFBS(df);
|
const matrix = MatrixFBS.encodeMatrixFBS(df);
|
||||||
|
const compressedMatrix = pako.deflate(matrix);
|
||||||
try {
|
try {
|
||||||
const queryString =
|
const queryString =
|
||||||
!dataCollectionNameIsReadOnly && !!dataCollectionName
|
!dataCollectionNameIsReadOnly && !!dataCollectionName
|
||||||
@@ -358,7 +360,7 @@ export const saveObsAnnotationsAction = () => async (dispatch, getState) => {
|
|||||||
`${globals.API.prefix}${globals.API.version}annotations/obs${queryString}`,
|
`${globals.API.prefix}${globals.API.version}annotations/obs${queryString}`,
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
body: matrix,
|
body: compressedMatrix,
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
"Content-Type": "application/octet-stream",
|
"Content-Type": "application/octet-stream",
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import copy
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
import zlib
|
||||||
|
|
||||||
from flask import make_response, jsonify, current_app, abort
|
from flask import make_response, jsonify, current_app, abort
|
||||||
from werkzeug.urls import url_unquote
|
from werkzeug.urls import url_unquote
|
||||||
@@ -159,13 +160,17 @@ def annotations_put_fbs_helper(data_adaptor, fbs):
|
|||||||
annotations.write_labels(new_label_df, data_adaptor)
|
annotations.write_labels(new_label_df, data_adaptor)
|
||||||
|
|
||||||
|
|
||||||
|
def inflate(data):
|
||||||
|
return zlib.decompress(data)
|
||||||
|
|
||||||
|
|
||||||
def annotations_obs_put(request, data_adaptor):
|
def annotations_obs_put(request, data_adaptor):
|
||||||
annotations = data_adaptor.dataset_config.user_annotations
|
annotations = data_adaptor.dataset_config.user_annotations
|
||||||
if annotations is None:
|
if annotations is None:
|
||||||
return abort(HTTPStatus.NOT_IMPLEMENTED)
|
return abort(HTTPStatus.NOT_IMPLEMENTED)
|
||||||
|
|
||||||
anno_collection = request.args.get("annotation-collection-name", default=None)
|
anno_collection = request.args.get("annotation-collection-name", default=None)
|
||||||
fbs = request.get_data()
|
fbs = inflate(request.get_data())
|
||||||
|
|
||||||
if anno_collection is not None:
|
if anno_collection is not None:
|
||||||
if not annotations.is_safe_collection_name(anno_collection):
|
if not annotations.is_safe_collection_name(anno_collection):
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
import zlib
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -343,7 +344,7 @@ class EndPointsAnnotations(EndPoints):
|
|||||||
url = f"{self.URL_BASE}{endpoint}?{query}"
|
url = f"{self.URL_BASE}{endpoint}?{query}"
|
||||||
n_rows = self.data.get_shape()[0]
|
n_rows = self.data.get_shape()[0]
|
||||||
fbs = make_fbs({"cat_A": pd.Series(["label_A"] * n_rows, dtype="category")})
|
fbs = make_fbs({"cat_A": pd.Series(["label_A"] * n_rows, dtype="category")})
|
||||||
result = self.session.put(url, data=fbs)
|
result = self.session.put(url, data=zlib.compress(fbs))
|
||||||
self.assertEqual(result.status_code, HTTPStatus.OK)
|
self.assertEqual(result.status_code, HTTPStatus.OK)
|
||||||
self.assertEqual(result.headers["Content-Type"], "application/json")
|
self.assertEqual(result.headers["Content-Type"], "application/json")
|
||||||
self.assertEqual(result.json(), {"status": "OK"})
|
self.assertEqual(result.json(), {"status": "OK"})
|
||||||
|
|||||||
Reference in New Issue
Block a user