Skip to content

Commit

Permalink
Merge branch 'Ren22-master' (PR #6): optical images deletion, fdrCoun…
Browse files Browse the repository at this point in the history
…ts resolver
  • Loading branch information
intsco committed Mar 16, 2018
1 parent b0a1674 commit cb97991
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 17 deletions.
5 changes: 2 additions & 3 deletions esConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ module.exports.esSearchResults = function(args, docType) {
from: args.offset,
size: args.limit
};
logger.info(JSON.stringify(body));
console.time('esQuery');
// console.time('esQuery');

return es.search(request).then((resp) => {
console.timeEnd('esQuery');
// console.timeEnd('esQuery');
return resp.hits.hits;
}).catch((e) => {
logger.error(e);
Expand Down
75 changes: 61 additions & 14 deletions resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ function baseDatasetQuery() {
});
}

function checkFetchRes(resp) {
if (resp.ok) {
return resp
} else {
throw new Error(`An error occurred during fetch request - status ${resp.status}`);
}
}

const Resolvers = {
Person: {
name(obj) { return obj.First_Name; },
Expand Down Expand Up @@ -159,17 +167,17 @@ const Resolvers = {
opticalImageUrl(_, {datasetId, zoom}) {
const intZoom = zoom <= 1.5 ? 1 : (zoom <= 3 ? 2 : (zoom <= 6 ? 4 : 8));
return pg.select().from('optical_image')
.where('ds_id', '=', datasetId)
.where('zoom', '=', intZoom)
.then(records => {
if (records.length > 0)
return '/optical_images/' + records[0].id;
else
return null;
})
.catch((e) => {
logger.error(e);
})
.where('ds_id', '=', datasetId)
.where('zoom', '=', intZoom)
.then(records => {
if (records.length > 0)
return '/optical_images/' + records[0].id;
else
return null;
})
.catch((e) => {
logger.error(e);
})
},

rawOpticalImage(_, {datasetId}) {
Expand Down Expand Up @@ -255,6 +263,26 @@ const Resolvers = {

uploadDateTime(ds) {
return ds._source.ds_upload_dt;
},

fdrCounts(ds, {inpFdrLvls}) {
let outFdrLvls = [], outFdrCounts = [];
if(ds._source.annotation_counts && ds._source.ds_status === 'FINISHED') {
let inpAllLvlCounts = ds._source.annotation_counts[0].counts;
inpFdrLvls.forEach(lvl => {
let findRes = inpAllLvlCounts.find(lvlCount => {
return lvlCount.level === lvl
});
if (findRes) {
outFdrLvls.push(findRes.level);
outFdrCounts.push(findRes.n);
}
});
}
return {
'levels': outFdrLvls,
'counts': outFdrCounts
}
}
},

Expand Down Expand Up @@ -501,6 +529,7 @@ const Resolvers = {

async addOpticalImage(_, {input}) {
let {datasetId, imageUrl, transform} = input;
const basePath = `http://localhost:${config.img_storage_port}`;
if (imageUrl[0] == '/') {
// imageUrl comes from the web application and should not include host/port.
//
Expand All @@ -509,18 +538,36 @@ const Resolvers = {
// if internal network is used.
//
// TODO support image storage running on a separate host
imageUrl = 'http://localhost:' + config.img_storage_port + imageUrl;
imageUrl = basePath + imageUrl;
}
const payload = jwt.decode(input.jwt, config.jwt.secret);
try {
logger.info(input);
await checkPermissions(datasetId, payload);
const url = `http://${config.services.sm_engine_api_host}/v1/datasets/${datasetId}/add-optical-image`;
const body = {url: imageUrl, transform};
await fetch(url, {
let processOptImage = await fetch(url, {
method: 'POST',
body: JSON.stringify(body),
headers: {'Content-Type': 'application/json'}});
checkFetchRes(processOptImage);
return 'success';
} catch (e) {
logger.error(e.message);
return e.message;
}
},

async deleteOpticalImage(_, args) {
let {datasetId} = args;
const payload = jwt.decode(args.jwt, config.jwt.secret);
const url = `http://${config.services.sm_engine_api_host}/v1/datasets/${datasetId}/del-optical-image`;
try {
await checkPermissions(datasetId, payload);
let dbDelFetch = await fetch(url, {
method: 'POST',
body: JSON.stringify({datasetId}),
headers: {'Content-Type': 'application/json'}});
checkFetchRes(dbDelFetch);
return 'success';
} catch (e) {
logger.error(e.message);
Expand Down
8 changes: 8 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ enum JobStatus {
FAILED
}

type FdrCounts {
levels: [Float!]!
counts: [Float!]!
}

type Dataset {
id: String!
name: String!
Expand All @@ -70,6 +75,7 @@ type Dataset {
status: JobStatus
inputPath: String
uploadDateTime: String
fdrCounts(inpFdrLvls: [Float!]!): FdrCounts!
}

# fields of categorical type
Expand Down Expand Up @@ -280,6 +286,8 @@ type Mutation {
delRawData: Boolean, sync: Boolean=true): String

addOpticalImage(input: AddOpticalImageInput!): String

deleteOpticalImage(jwt: String!, datasetId: String!): String!
}

type DatasetStatusUpdate {
Expand Down

0 comments on commit cb97991

Please sign in to comment.