Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
siibra-explorer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xiao Gui
siibra-explorer
Commits
795764ad
Commit
795764ad
authored
5 years ago
by
Xiao Gui
Browse files
Options
Downloads
Patches
Plain Diff
chore: cleanup code, rename var, fix typos
parent
d2a6ab56
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
deploy/datasets/query.js
+36
-37
36 additions, 37 deletions
deploy/datasets/query.js
deploy/datasets/spatialRouter.js
+2
-1
2 additions, 1 deletion
deploy/datasets/spatialRouter.js
with
38 additions
and
38 deletions
deploy/datasets/query.js
+
36
−
37
View file @
795764ad
...
...
@@ -15,12 +15,12 @@ const STORAGE_PATH = process.env.STORAGE_PATH || path.join(__dirname, 'data')
let
getPublicAccessToken
const
fetchDatasetFromKg
=
async
(
arg
)
=>
{
const
fetchDatasetFromKg
=
async
(
{
user
}
=
{}
)
=>
{
const
userState
=
await
getUserKGRequestInfo
(
arg
)
const
{
releasedOnly
,
option
}
=
await
getUserKGRequestInfo
(
{
user
}
)
return
await
new
Promise
((
resolve
,
reject
)
=>
{
request
(
`
${
queryUrl
}${
userState
.
releasedOnly
?
'
&databaseScope=RELEASED
'
:
''
}
`
,
userState
.
option
,
(
err
,
resp
,
body
)
=>
{
request
(
`
${
queryUrl
}${
releasedOnly
?
'
&databaseScope=RELEASED
'
:
''
}
`
,
option
,
(
err
,
resp
,
body
)
=>
{
if
(
err
)
return
reject
(
err
)
if
(
resp
.
statusCode
>=
400
)
...
...
@@ -185,7 +185,7 @@ exports.getPreview = ({ datasetName, templateSelected }) => getPreviewFile({ dat
* change to real spatial query
*/
const
cachedMap
=
new
Map
()
const
fetchSpatialDataFromKg
=
async
({
templateName
,
queryArg
,
req
})
=>
{
const
fetchSpatialDataFromKg
=
async
({
templateName
,
queryArg
,
user
})
=>
{
try
{
const
filename
=
path
.
join
(
STORAGE_PATH
,
templateName
+
'
.json
'
)
const
exists
=
fs
.
existsSync
(
filename
)
...
...
@@ -196,27 +196,16 @@ const fetchSpatialDataFromKg = async ({ templateName, queryArg, req }) => {
const
data
=
fs
.
readFileSync
(
filename
,
'
utf-8
'
)
const
json
=
JSON
.
parse
(
data
)
var
splitQueryArg
=
queryArg
.
split
(
'
__
'
);
const
cubeDots
=
[]
splitQueryArg
.
forEach
(
element
=>
{
cubeDots
.
push
(
element
.
split
(
'
_
'
))
});
const
coordsString
=
queryArg
.
split
(
'
__
'
);
const
boundingBoxCorners
=
coordsString
.
map
(
coordString
=>
coordString
.
split
(
'
_
'
))
if
(
templateName
!==
'
Waxholm Space rat brain atlas v.2.0
'
)
{
return
json
.
filter
(
filterByqueryArg
(
cubeDot
s
))
return
json
.
filter
(
filterByqueryArg
(
boundingBoxCorner
s
))
}
else
{
const
centerDifference
=
[
-
9.550781
,
-
24.355468
,
-
9.707031
]
let
calculatedCubeDots
=
[]
cubeDots
.
forEach
((
dots
,
index
)
=>
{
calculatedCubeDots
[
index
]
=
cubeDots
[
index
].
map
((
num
,
idx
)
=>
{
return
+
num
-
centerDifference
[
idx
]
})
})
calculatedCubeDots
=
calculatedCubeDots
.
map
(
x
=>
transformToWoxel
(
x
))
const
resultFromKG
=
await
getSpatialSearchOk
({
calculatedCubeDots
,
req
})
if
(
resultFromKG
&&
resultFromKG
[
'
total
'
]
&&
resultFromKG
[
'
total
'
]
>
0
)
{
return
json
.
filter
(
filterByqueryArg
(
cubeDots
))
const
boundingBoxInWaxhomV2VoxelSpace
=
boundingBoxCorners
.
map
(
transformWaxholmV2NmToVoxel
)
const
{
total
=
0
}
=
await
getSpatialSearchOk
({
boundingBoxInWaxhomV2VoxelSpace
,
user
})
if
(
total
>
0
)
{
return
json
.
filter
(
filterByqueryArg
(
boundingBoxCorners
))
}
else
{
return
[]
}
...
...
@@ -227,8 +216,8 @@ const fetchSpatialDataFromKg = async ({ templateName, queryArg, req }) => {
}
}
exports
.
getSpatialDatasets
=
async
({
templateName
,
queryGeometry
,
queryArg
,
req
})
=>
{
return
await
fetchSpatialDataFromKg
({
templateName
,
queryArg
,
req
})
exports
.
getSpatialDatasets
=
async
({
templateName
,
queryGeometry
,
queryArg
,
user
})
=>
{
return
await
fetchSpatialDataFromKg
({
templateName
,
queryArg
,
user
})
}
...
...
@@ -240,26 +229,21 @@ function filterByqueryArg(cubeDots) {
if
(
cubeDots
[
0
][
0
]
<=
px
&&
px
<=
cubeDots
[
1
][
0
]
&&
cubeDots
[
0
][
1
]
<=
py
&&
py
<=
cubeDots
[
1
][
1
]
&&
cubeDots
[
0
][
2
]
<=
pz
&&
pz
<=
cubeDots
[
1
][
2
])
{
return
true
;
return
true
}
return
false
}
return
false
;
}
async
function
getSpatialSearchOk
(
arg
)
{
async
function
getSpatialSearchOk
(
{
user
,
boundingBoxInWaxhomV2VoxelSpace
}
)
{
const
userState
=
await
getUserKGRequestInfo
(
arg
.
req
)
const
option
=
{
headers
:
{
'
Authorization
'
:
userState
.
token
}
}
const
{
releasedOnly
,
option
}
=
await
getUserKGRequestInfo
({
user
})
const
spatialQuery
=
'
https://kg.humanbrainproject.org/query/minds/core/dataset/v1.0.0/spatialSimple/instances?size=10
'
return
await
new
Promise
((
resolve
,
reject
)
=>
{
request
(
`
${
spatialQuery
}
${
'
&boundingBox=waxholmV2:
'
+
arg
.
calculatedCubeDots
[
0
].
concat
(
arg
.
calculatedCubeDots
[
1
])}${
userState
.
releasedOnly
?
'
&databaseScope=RELEASED
'
:
''
}
`
,
option
,
(
err
,
resp
,
body
)
=>
{
request
(
`
${
spatialQuery
}
&boundingBox=waxholmV2:
${
boundingBoxInWaxhomV2VoxelSpace
.
map
(
cornerCoord
=>
cornerCoord
.
join
(
'
,
'
)).
join
(
'
,
'
)}${
releasedOnly
?
'
&databaseScope=RELEASED
'
:
''
}
`
,
option
,
(
err
,
resp
,
body
)
=>
{
if
(
err
)
return
reject
(
err
)
if
(
resp
.
statusCode
>=
400
)
...
...
@@ -270,8 +254,8 @@ async function getSpatialSearchOk(arg) {
})
}
async
function
getUserKGRequestInfo
(
arg
)
{
const
accessToken
=
arg
&&
arg
.
user
&&
arg
.
user
.
tokenset
&&
arg
.
user
.
tokenset
.
access_token
async
function
getUserKGRequestInfo
(
{
user
}
)
{
const
accessToken
=
user
&&
user
.
tokenset
&&
user
.
tokenset
.
access_token
const
releasedOnly
=
!
accessToken
let
publicAccessToken
if
(
!
accessToken
&&
getPublicAccessToken
)
{
...
...
@@ -288,8 +272,23 @@ async function getUserKGRequestInfo(arg) {
return
{
option
,
releasedOnly
,
token
:
accessToken
||
publicAccessToken
||
process
.
env
.
ACCESS_TOKEN
}
}
const
transformToWoxel
=
(
coord
)
=>
{
/**
*
*/
const
transformWaxholmV2NmToVoxel
=
(
coord
)
=>
{
/**
* as waxholm is already in RAS, does not need to swap axis
*/
/**
* atlas viewer applies translation (below in nm) in order to center the brain
* query already translates nm to mm, so the unit of transl should be [mm, mm, mm]
*/
const
transl
=
[
-
9550781
,
-
24355468
,
-
9707031
].
map
(
v
=>
v
/
1
e6
)
/**
* mm/voxel
*/
const
voxelDim
=
[
0.0390625
,
0.0390625
,
0.0390625
]
return
coord
.
map
((
v
,
idx
)
=>
(
v
-
transl
[
idx
])
/
voxelDim
[
idx
]
)
}
...
...
This diff is collapsed.
Click to expand it.
deploy/datasets/spatialRouter.js
+
2
−
1
View file @
795764ad
...
...
@@ -25,8 +25,9 @@ router.get('/templateName/:templateName/:queryGeometry/:queryArg', (req, res, ne
trace
:
'
dataset#spatialRouter
'
})
const
{
user
}
=
req
getSpatialDatasets
({
templateName
,
queryGeometry
,
queryArg
,
req
})
getSpatialDatasets
({
templateName
,
queryGeometry
,
queryArg
,
user
})
.
then
(
arr
=>
res
.
status
(
200
).
json
(
arr
))
.
catch
(
error
=>
{
next
({
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment