Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
metrics-collect
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reto Gerber
metrics-collect
Commits
a487e35e
Commit
a487e35e
authored
3 years ago
by
Reto Gerber
Browse files
Options
Downloads
Patches
Plain Diff
Saved changes to: metrics-collect.Rproj src/dataset_utils.sh
parent
45f2c9ed
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
metrics-collect.Rproj
+1
-1
1 addition, 1 deletion
metrics-collect.Rproj
src/dataset_utils.sh
+131
-0
131 additions, 0 deletions
src/dataset_utils.sh
with
132 additions
and
1 deletion
metrics-collect.Rproj
+
1
−
1
View file @
a487e35e
...
...
@@ -10,4 +10,4 @@ NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
\ No newline at end of file
LaTeX: pdfLaTeX
This diff is collapsed.
Click to expand it.
src/dataset_utils.sh
0 → 100644
+
131
−
0
View file @
a487e35e
#!/usr/bin/env bash
# author: Oksana Riba Grognuz
function
list_datasets_matching_string
()
{
USAGE
=
"
\n
Usage:
\n
${
FUNCNAME
[*]
}
<string>
\n\n\
List dataset identifiers for all datasets
\n\
with any fields matching <string>.
\n
"
if
[
$#
-eq
0
]
then
echo
-e
$USAGE
;
return
fi
local
query
=
$1
curl
-s
"https://renkulab.io/knowledge-graph/datasets?query=
$query
"
| jq
-r
'.[] | .identifier'
}
function
datasets_properties_by_id
()
{
USAGE
=
"
\n
Usage:
\n
${
FUNCNAME
[*]
}
<dataset_id> <field>
\n\n\
Return dataset <field> value for a <dataset_id>.
\n\
If field is not specified, then retrieve name.
\n
"
if
[
$#
-eq
0
]
then
echo
-e
$USAGE
;
return
fi
local
dataset_id
=
$1
local
field
=
${
2
:-
name
}
curl
-s
"https://renkulab.io/knowledge-graph/datasets/
$dataset_id
"
| jq
-r
'.'
\"
$field
\"
''
}
function
query_datasets_by_string
()
{
USAGE
=
"
\n
Usage:
\n
${
FUNCNAME
[*]
}
<string> <field>
\n\n\
Retrieve dataset <field> values for all datasets
\n\
with any fields matching <string>.
\n\
Specify <field> as: name, title, description, identifier
\n\
If <field> is not specified, then retrieve identifier.
\n
"
if
[
$#
-eq
0
]
then
echo
-e
$USAGE
;
return
fi
local
keyword
=
$1
local
field
=
${
2
:-
identifier
}
for
dataset_id
in
`
list_datasets_matching_string
"
$keyword
"
`
do
datasets_properties_by_id
$dataset_id
$field
done
}
function
match_datasets_keywords
()
{
USAGE
=
"
\n
Usage:
\n
${
FUNCNAME
[*]
}
<dataset_id> <keyword> <field>
\n\n\
Return dataset <field> value if there is an exact
\n\
case insensitive match of <dataset_id> keywords to <keyword>.
\n\
If field is not specified, then retrieve identifier.
\n
"
if
[
$#
-eq
0
]
then
echo
-e
$USAGE
;
return
fi
local
dataset_id
=
$1
local
keyword
=
`
echo
$2
|
awk
'{print tolower($0)}'
`
local
field
=
${
3
:-
identifier
}
curl
-s
"https://renkulab.io/knowledge-graph/datasets/
$dataset_id
"
\
| jq
-r
'select(.keywords[] | ascii_downcase == ('
\"
$keyword
\"
')) | .'
\"
$field
\"
''
}
function
query_datasets_by_keyword
()
{
USAGE
=
"
\n
Usage:
\n
${
FUNCNAME
[*]
}
<keyword> <field>
\n\n\
Return dataset <field> value for all datasets with an exact
\n\
case insensitive match of dataset keywords to <keyword>.
\n\
If field is not specified, then retrieve identifier.
\n
"
if
[
$#
-eq
0
]
then
echo
-e
$USAGE
;
return
fi
local
keyword
=
$1
local
field
=
${
2
:-
identifier
}
for
dataset_id
in
`
list_datasets_matching_string
"
$keyword
"
`
do
match_datasets_keywords
$dataset_id
"
$keyword
"
$field
done
}
function
import_datasets_by_keyword
()
{
USAGE
=
"
\n
Usage:
\n
${
FUNCNAME
[*]
}
<keyword>
\n\n\
Import all datasets annotated with <keyword>.
\n\
Update, if datasets were already imported.
\n
"
if
[
$#
-eq
0
]
then
echo
-e
$USAGE
;
return
fi
local
keyword
=
$1
for
dataset_id
in
`
query_datasets_by_keyword
$keyword
identifier
`
do
local
data_name
=
`
datasets_properties_by_id
$dataset_id
name
`
local
data_path
=
"
${
WORK_DIR
}
/data/
${
data_name
}
"
local
data_url
=
`
datasets_properties_by_id
$dataset_id
url
`
if
[
-d
"
${
data_path
}
"
]
then
renku dataset update
$data_name
else
renku dataset import
-y
$data_url
fi
done
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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