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

imrpove details of a few .js scripts

parent b9ab9c19
......@@ -15,3 +15,7 @@ package-lock.json
scientists-hole-1-mefiex.json
scientists-hole-20-enty.json
sections_inspected.json
scientists-hole-10-samp.json
scientists-hole-21-enty.json
scientists-hole-8-samp.json
scientists-hole-9-samp.json
......@@ -24,12 +24,15 @@ 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,
Creating new sections is a complex operation.
There must not be any sections for a core defined previously (the scripts does not check for uplicate entries).
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.
The first writes a JSON file with fake data. The second script reads that file and uploads it to mDIS. The benefit of this two-step approach is tha you can have a look at the data before it actually gets created inside mDIS.
```sh
cd bin
......@@ -138,10 +141,12 @@ These scientists will then later express interest in splits from _all_ sites and
`# 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:
Then add the new science team to the table of scientists:
`node src/scientist-inserter.js -i scientists-hole-20-enty.json`
Part of the response:
```
{
'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"}'
......@@ -152,9 +157,13 @@ Created fake scientists from undefined entries in file scientists-hole-20-enty.j
#############################################################
```
#### Inserting a Fake sample request
`node src/request-inserter.js -e 10 # -e is the expedition number`
#### Inserting a Fake sample
For adding fake samples for an hole, there must splits, scientists, requests, samples for that hole.
Fake Samples for a hole can only be added, if splits, scientists, requests for that hole exist.
```
node src/sample-inserter.js -h 12
......@@ -172,17 +181,19 @@ Expedition 12 (ENTY) has 1 expeditions.
Expedition 12 (ENTY) has 28 splits.
########################################################################
Expedition 12 (ENTY) has no scientists, requests, samples.
Expedition 12 (ENTY) has no scientists, requests.
To continue adding samples,
all expeditions, splits, scientists, requests, samples are required to be > 0.
all expeditions, splits, scientists, requests are required to be > 0.
Must exit now.
########################################################################
```
#### Inserting a Fake sample request
#### Inserting a Fake section-unit (lithology)
`node src/geology-inserter.js -e 10 # -e is the expedition-id`
Depth values and sample amounts, interval lengths etc are not really assigned in a meaningful way yet.
#### Inserting a Fake New List-Value Entry
### Querying the List-values table
......
......@@ -55,12 +55,12 @@ if [[ "$cores_count" -gt 0 ]]; then
if [[ ! -f $outfile || "$f" ]]; then
echo $section_counts > $outfile
echo "Wrote JSON data to file './$outfile',
please use this with the 'section-inspect.sh' script now"
please use this with the 'section-insert.sh' script now"
fi
if [[ -f $outfile && $f ]]; then
echo $section_counts > $outfile
echo "JSON data file '$outfile' overwritten as requested,
please use this with the 'section-inspect.sh' script now"
please use this with the 'section-insert.sh' script now"
fi
else
......
......@@ -31,36 +31,38 @@ module.exports = class CurationSample {
return this._props.sample_date
}
find_bottom() {
const b = util.round((
this.top + this.interval
), 1)
const b = util.round(
this.top + this.interval,
1
)
this._props.bottom = b
return b
}
find_top() {
const t = util.round((
const t = util.round(
this._section.top_depth +
util.frac_below(0.3) * (this._props.section_length_cm ) //cm
), 1)
util.frac_below(0.3) * this._props.section_length_cm, //cm
1
)
this._props.top = t
return t
}
find_interval() {
const sl = this._props.section_length_cm
const sl = this._props.section_length_cm
const minlen = 0.03 * (sl + 1)
let len = 0
if(sl < 10){
if (sl < 10) {
// allow larger pieces for smaller sections
len = sl * util.frac_above(0.3)
} else {
len = sl * util.frac_below(0.2)
}
const int = util.round((minlen + len), 1)
this._props.interval= int
const int = util.round(minlen + len, 1)
this._props.interval = int
return int
}
find_analyst() {
......@@ -71,7 +73,7 @@ module.exports = class CurationSample {
//return this._props.sample_type
}
find_section_top_mbsf() {
const t = util.round(this._section.top_depth/100,0) + 1000 //faker.fake("{{random.number}}") % 200
const t = util.round(this._section.top_depth / 100, 0) + 1000 //faker.fake("{{random.number}}") % 200
this._props.section_top_mbsf = t
return t
}
......@@ -92,7 +94,10 @@ module.exports = class CurationSample {
return `core id: ${this._section.core_id} ${this._props.remarks}`
}
find_amount() {
return util.round((faker.fake("{{random.number}}") % 200) * util.frac_above(0.5), 0)
return util.round(
(faker.fake("{{random.number}}") % 200) * util.frac_above(0.5),
0
)
}
find_amount_unit() {
return util.shuffle(CoreDefaults.sampling_units).pop()
......@@ -109,14 +114,20 @@ module.exports = class CurationSample {
return t
}
find_sample_bottom_mbsf() {
return util.round(this.section_top_mbsf + this.top + this.interval/100, 1)
return util.round(this.section_top_mbsf + this.top + this.interval / 100, 1)
}
find_scientist() {
return Array.of(
this._props.scientist_1,
this._props.scientist_2,
this._props.scientist_3
).filter((s) => s?.length ).join(", ")
)
.filter((s) => s?.length)
.join(", ")
}
find_purpose() {
return "DNA"
}
fake() {
......@@ -195,4 +206,8 @@ module.exports = class CurationSample {
get scientist() {
return this._props.scientist ? this._props.scientist : this.find_scientist()
}
get purpose() {
return this._props.purose ? this._props.purpose : this.find_purpose()
}
}
......@@ -42,7 +42,7 @@ const qs_splits = {
"per-page": -1,
page: 1,
sort: "id",
"filter[type]": "[^A]",
"filter[type]": "[^W$]",
"filter[expedition_id]": options.expedition,
}
const qs_expedition = {
......
......@@ -117,7 +117,12 @@ axutil
.map((_) => Number.parseInt(util.frac_below(0.2) * n_max))
for (let r of requests_per_scientists.filter((n) => n > 0)) {
let templ = new SampleRequest(
Object.assign({}, request_columns, { request_id: "CAIR" }),
Object.assign({}, request_columns, {
request_id: `req-${util.format_date(
new Date(),
"YYYY-MM-DD HH:mm"
)}`,
}),
scientists,
options.expedition_id
).fake()
......
......@@ -116,7 +116,9 @@ Promise.all(queries_map.values())
key_names.push(k)
if (!v.length) {
no_results.push(k)
if (!k.includes("samples")) {
no_results.push(k)
}
} else {
console.log(
`Expedition ${
......@@ -139,9 +141,10 @@ Promise.all(queries_map.values())
.then((_) => {
let [expedition, splits, scientists, requests, samples] = query_results
// for
let existing_samples_reqno = samples
.map((s) => Number.parseInt(s.request_no))
.flat()
console.log(samples)
let existing_samples_reqno = !Object.keys(samples).length
? []
: samples.map((s) => Number.parseInt(s.request_no)).flat()
let previous_requests = requests.filter((r) =>
existing_samples_reqno.some((s) => r.request_no === s)
)
......
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