Commit b9ab9c19 authored by Knut Behrends's avatar Knut Behrends
Browse files

improve documentation, refine shell scripts

parent aaf77b1a
......@@ -6,3 +6,12 @@ notes.txt
test.js
scientists.json
data
src/*.json
bin/exp-1-mefiex-sections.json
bin/exp-2-manycores-sections.json
bin/section_counts.json
package.json
package-lock.json
scientists-hole-1-mefiex.json
scientists-hole-20-enty.json
sections_inspected.json
......@@ -24,18 +24,99 @@ or enter the `src/`subdirectory to execute node scripts.
#### Inserting a Fake Section
Creating new sections is a complex operation. There are two scripts to execute,
1. `api-caller-core-section-find.sh`,
1. `api-caller-core-section-insert.sh`.
The first writes a JSON file that the second script reads and turns into API calls.
```sh
cd bin
../api-caller-core-section-find.sh
../api-caller-core-section-insert.sh
```
Script 1:
```sh
./api-caller-core-section-find.sh -e 2 -s 2 -h 2 -f exp-2-manycores-sections.json
Finding cores and respective section counts
22 cores found
JSON data file 'section_counts.json' overwritten as requested,
please use this with the 'section-inspect.sh' script now
```
Script 2:
```sh
# looks for file section_coints.json in same directory, and processes it.
./api-caller-core-section-insert.sh
# use -i to process a different infile.
# ./api-caller-core-section-insert.sh -i infile.json
```
Output:
```
Inspecting cores and their core sections
2 cores found in infile 'section_counts.json'
core 1 of 2
core 1: 4 sections
{
id: 228,
combined_id: '8224_B_A_1',
core_id: 1,
section_count: 4,
recovered_length: 2.29,
expedition_id: 12,
site_id: 8,
hole_id: 21
}
# sends
{"core_id":228,"section":1,"top_depth":0.57,"section_length":1.58,"bottom_depth":2.7,"analyst":"CK","section_state":"discontinuous","curated_length":1.45,"comment":"c.1 s.1/4, cL: 2.29m (0.57 - 3.04m)"}
# receives
{
'1': '{"core_id":228,"section":1,"top_depth":0.57,"section_length":1.58,"bottom_depth":2.7,"analyst":"CK","section_state":"discontinuous","curated_length":1.45,"comment":"c.1 s.1/4, cL: 2.29m (0.57 - 3.04m)"}'
}
{
'2': {},
'3': {},
'4': {}
}
```
#### Inserting a Fake Split
Command:
```sh
./api-caller-sectionsplit-insert.sh -c 226 # core 226
node src/split-inserter.js -c 118 # -c stands for core
#node src/split-inserter.js -c 118 # -c stands for core, (core 118)
```
Expected outputs:
_Core was not split before_:
```
#############################################################
Core 226: Created A- and W- splits for 4 sections
#############################################################
{ url: '/api/v1/form/226?name=core', "'oriented/split' is now:": 1 } { 'id_split 202020-07-23': 226 }
{ "'still_exists' is now:": '0' } { id_8224_A_A_1_2_WR: 152 }
{ "'still_exists' is now:": '0' } { id_8224_A_A_1_1_WR: 151 }
```
_Core *was* split before. Results in early stopping._
```sh
/api/v1/form?name=split&per-page=-1&page=1&sort=section&filter[core_id]=118
Stop early. Core 5363_A_AB_14_1 (id 118) and its 2 sections
......@@ -47,9 +128,66 @@ Map(2) {
}
```
#### Inserting a Fake scientist
Scientists issue _sample requests_ to express their intention to sample a certain core. The actual sample is taken from a section-split.
For now, assign scientists on a per-hole-level.
These scientists will then later express interest in splits from _all_ sites and holes from that expedition.
`# write new science team to a JSON file`
`node src/scientist-finder.js -h 20 > scientists-hole-20-enty.json`
The add the new science team to the table of scientists:
`node src/scientist-inserter.js -i scientists-hole-20-enty.json`
```
{
'11': '{"expedition_id":12,"first_name":"Elissa","last_name":"Johnston","title":"Product Paradigm Agent","institute":"TU-Potsdam","department":"Sports","street":"Hal Summit Straße 8","city":"Potsdam","zip":"14496","state":"-","country":"Germany","email":"Johnston@tu-potsdam.de","phone":"1-780-138-4107 x28919","full_name":"Elissa Johnston"}'
}
#############################################################
Created fake scientists from undefined entries in file scientists-hole-20-enty.json
#############################################################
```
#### Inserting a Fake sample
For adding fake samples for an hole, there must splits, scientists, requests, samples for that hole.
```
node src/sample-inserter.js -h 12
```
When not all preconditions are met:
```
/api/v1/form?name=expedition&filter[id]=12
/api/v1/form?name=split&per-page=-1&page=1&sort=id&filter[type]=[^A]&filter[expedition_id]=12
/api/v1/form?name=scientists&per-page=-1&page=1&sort=city&filter[expedition_id]=12
/api/v1/form?name=sample-requests&per-page=-1&page=1&sort=id&filter[expedition_id]=12
/api/v1/form?name=sample&filter[expedition_id]=12
Expedition 12 (ENTY) has 1 expeditions.
Expedition 12 (ENTY) has 28 splits.
########################################################################
Expedition 12 (ENTY) has no scientists, requests, samples.
To continue adding samples,
all expeditions, splits, scientists, requests, samples are required to be > 0.
Must exit now.
########################################################################
```
#### Inserting a Fake sample request
#### Inserting a Fake section-unit (lithology)
#### Inserting a Fake New List-Value Entry
### Querying the List-values table
Get value list names, and get all items of that list.
Get value-list names, and get all items of that list.
#### Get value list names
......@@ -59,20 +197,22 @@ node list-values.js -a
'ABUNDANCE',
'ACCESSORIES',
'ACTIVITY_TYPE',
] // and ~ 100 more
// ...
] // + ~ 100 more valuelist-names
```
#### Get all entries of a single value list, filtered by na
#### Get all entries of a _single_ value list
Get all entries of a single value list, filtered by name
Pick one name from the resultset above, e.g. 'ACCESSORIES' or 'CITIES'.
optionally.
-d values only, or
-e value+remark/labeltext paired
Get all entries of that single value list
optionally.
-n -d _values only, or_
-n -e _value+remark/labeltext paired_
```sh
node list-values.js -n CITIES -e
node list-values.js -n CITIES -e
```
......@@ -84,9 +224,27 @@ node list-values.js -n CITIES -e
Aarhus: 'Central Jutland, Denmark',
Abiko: 'Chiba, Japan',
Abo: 'Finland Proper, Finland',
// + many more
}
```
### Configuration
To use the scripts you must get a [Bearer token](https://data.icdp-online.org/mdis-docs/guide/rest-api/#security) for the REST API first. Add it either as an environment variable, or insert it at the top of the `src/config` file.
To use the scripts you must get a [Bearer token](https://data.icdp-online.org/mdis-docs/guide/rest-api/#security) for the REST API first. Add it either as an environment variable (`export token=thiSisWHatAtOKENlooKSLikE`), or insert it at the top of the `src/config` file.
Example.
Response for a user that has an expired token, and not enough privileges to add new data.
```
node src/split-inserter.js -c 118
```
```
/api/v1/form?name=split&per-page=-1&page=1&sort=section&filter[core_id]=118
Unauthorized
Your request was made with invalid credentials.
Unauthorized
Stopped early. Nothing to do. Core id 118 has 0 sections.
Create some fake sections for this core first.
```
......@@ -24,7 +24,14 @@ do
;;
f) f=1 # overwrite outfile
;;
*) echo "Usage: $0 [e s h f] [-d] (activates Node's chrome debugger)" && exit 0 ;;
*) echo "Usage: $0 [-e eid -s sid -h hid] [-f] [-d] \
-e expedition_id -s site_id -h hole_id \
-f force-overwrite (outfile is always ./section-count.json)\
(-d activates Node's chrome debugger)" && exit 0
;;
esac
done
......@@ -32,10 +39,10 @@ echo Finding cores and respective section counts
echo ""
node_version=$(node -v | grep -P v1[456789])
if [[ -z "$node_version" ]]; then
echo "You must use Node v14+ to run the split-inserter script"
echo "You must use Node v14+ to run the section-finder script"
exit 1
fi
section_counts=$(node $debug ../src/sectioncount-of-cores-of-single-hole.sh -h $h);
section_counts=$(node $debug ../src/sectioncount-of-cores-of-single-hole.js -h $h);
outfile=section_counts.json
......@@ -43,11 +50,11 @@ cores_count=$(echo $section_counts | jq '.meta.totalCount')
if [[ "$cores_count" -gt 0 ]]; then
echo "$cores_count cores found"
if [[ -f $outfile && ! $f ]]; then
echo "JSON data file '$outfile' exists, use the -f option"
echo "JSON data file './$outfile' exists, use the -f option"
fi
if [[ ! -f $outfile && ! $f ]]; then
if [[ ! -f $outfile || "$f" ]]; then
echo $section_counts > $outfile
echo "Wrote JSON data to file '$outfile',
echo "Wrote JSON data to file './$outfile',
please use this with the 'section-inspect.sh' script now"
fi
if [[ -f $outfile && $f ]]; then
......
......@@ -35,14 +35,14 @@ if [[ -z "$node_version" ]]; then
fi
########## main script
echo Core $c: Creating split-sections from Whole-round sections >&2
echo Core $core: Creating split-sections from Whole-round sections >&2
if [[ "$cores_count" -gt 0 ]]; then
#for i in $(seq 13 100) ; do echo $i; node split-inserter.js -c $i ; done
node $debug ../split-inserter.js -c $i done
if [[ "$core" -gt 0 ]]; then
#for i in $(seq 92 120) ; do echo $i; node split-inserter.js -c $i ; done
node $debug ../src/split-inserter.js -c $core
else
echo "No core or no sections found for core $i."
echo "No core or no sections found for core $core."
echo "Core number must be the autoincrement-id of that core."
echo "Do not use value of combined_id or a different id-column"
fi
......@@ -75,7 +75,7 @@ module.exports = class FakeUtil {
}
padLeft(str, n = 2, p = "0") {
return str.padStart(str, n, p)
return str.toString().padStart(str, n, p)
}
map2object(myMap) {
......
......@@ -4,9 +4,9 @@
// use Node v14+
// insert fake scietists into mDIS database
// call this script with:
// ../api-caller-split-inserter.sh
// ../api-caller-scientist-inserter.sh # does not exist
// or
// node src/scientist-inserter.js -f infile.json
// node src/scientist-inserter.js -i infile.json
const config = require("./config.js")
const axios = require("axios")
const axutil = require("./axios-util.js")
......
"use strict"
// insert core-sections in mDIS database
// call this with:
// ../api-caller-core-section-inserter.sh
// ../api-caller-core-section-insert.sh
// or
// node src/section-inserter.js {"id":2,"combined_id":"5065_1_A_1","core_id":1,"section_count":3...}
const config = require("./config.js")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment