Commit 5e937a61 authored by Knut Behrends's avatar Knut Behrends
Browse files

begin work on fake-scientist, -samples, -requests

parent 8ae69b0b
{"splits":[{"split_id":275,"combined_id":"5363_A_AB_1_1_WR","hole_id":9,"scientist":""},{"split_id":276,"combined_id":"5363_A_AB_1_2_WR","hole_id":9,"scientist":""},{"split_id":277,"combined_id":"5363_A_AB_2_2_WR","hole_id":9,"scientist":""},{"split_id":278,"combined_id":"5363_A_AB_2_1_WR","hole_id":9,"scientist":""},{"split_id":279,"combined_id":"5363_A_AB_3_1_WR","hole_id":9,"scientist":""},{"split_id":280,"combined_id":"5363_A_AB_3_2_WR","hole_id":9,"scientist":""},{"split_id":282,"combined_id":"5363_A_AB_4_2_WR","hole_id":9,"scientist":""},{"split_id":281,"combined_id":"5363_A_AB_4_1_WR","hole_id":9,"scientist":""},{"split_id":283,"combined_id":"5363_A_AB_4_3_WR","hole_id":9,"scientist":""},{"split_id":284,"combined_id":"5363_A_AB_5_2_WR","hole_id":9,"scientist":""},{"split_id":286,"combined_id":"5363_A_AB_5_1_WR","hole_id":9,"scientist":""},{"split_id":285,"combined_id":"5363_A_AB_5_4_WR","hole_id":9,"scientist":""},{"split_id":287,"combined_id":"5363_A_AB_5_3_WR","hole_id":9,"scientist":""},{"split_id":288,"combined_id":"5363_A_AB_6_1_WR","hole_id":9,"scientist":""},{"split_id":289,"combined_id":"5363_A_AB_6_2_WR","hole_id":9,"scientist":""},{"split_id":290,"combined_id":"5363_A_AB_6_3_WR","hole_id":9,"scientist":""},{"split_id":291,"combined_id":"5363_A_AB_6_4_WR","hole_id":9,"scientist":""},{"split_id":292,"combined_id":"5363_A_AB_7_2_WR","hole_id":9,"scientist":""},{"split_id":293,"combined_id":"5363_A_AB_7_1_WR","hole_id":9,"scientist":""},{"split_id":294,"combined_id":"5363_A_AB_8_2_WR","hole_id":9,"scientist":""},{"split_id":295,"combined_id":"5363_A_AB_8_1_WR","hole_id":9,"scientist":""},{"split_id":296,"combined_id":"5363_A_AB_8_4_WR","hole_id":9,"scientist":""},{"split_id":297,"combined_id":"5363_A_AB_8_3_WR","hole_id":9,"scientist":""},{"split_id":298,"combined_id":"5363_A_AB_9_1_WR","hole_id":9,"scientist":""},{"split_id":299,"combined_id":"5363_A_AB_9_2_WR","hole_id":9,"scientist":""},{"split_id":440,"combined_id":"5363_A_AB_10_2_A","hole_id":9,"scientist":"Dillon Kunze"},{"split_id":439,"combined_id":"5363_A_AB_10_2_W","hole_id":9,"scientist":"Sophia Morar"},{"split_id":300,"combined_id":"5363_A_AB_10_2_WR","hole_id":9,"scientist":""},{"split_id":438,"combined_id":"5363_A_AB_10_1_A","hole_id":9,"scientist":"Yessenia Witting"},{"split_id":445,"combined_id":"5363_A_AB_10_1_W","hole_id":9,"scientist":"Virginia Mueller"},{"split_id":301,"combined_id":"5363_A_AB_10_1_WR","hole_id":9,"scientist":""},{"split_id":443,"combined_id":"5363_A_AB_10_3_A","hole_id":9,"scientist":"Erick Hansen"},{"split_id":442,"combined_id":"5363_A_AB_10_3_W","hole_id":9,"scientist":"Cordia Gislason"},{"split_id":303,"combined_id":"5363_A_AB_10_3_WR","hole_id":9,"scientist":""},{"split_id":444,"combined_id":"5363_A_AB_10_4_A","hole_id":9,"scientist":"Cynthia Hoeger"},{"split_id":441,"combined_id":"5363_A_AB_10_4_W","hole_id":9,"scientist":"Keegan Fadel"},{"split_id":302,"combined_id":"5363_A_AB_10_4_WR","hole_id":9,"scientist":""},{"split_id":416,"combined_id":"5363_A_AB_11_1_A","hole_id":9,"scientist":"Beulah Lockman"},{"split_id":414,"combined_id":"5363_A_AB_11_1_W","hole_id":9,"scientist":"Ashtyn Wintheiser"},{"split_id":304,"combined_id":"5363_A_AB_11_1_WR","hole_id":9,"scientist":""},{"split_id":415,"combined_id":"5363_A_AB_11_2_A","hole_id":9,"scientist":"Shanny Hessel"},{"split_id":417,"combined_id":"5363_A_AB_11_2_W","hole_id":9,"scientist":"Burnice Jerde"},{"split_id":305,"combined_id":"5363_A_AB_11_2_WR","hole_id":9,"scientist":""},{"split_id":419,"combined_id":"5363_A_AB_12_1_A","hole_id":9,"scientist":"Margaret Quigley"},{"split_id":418,"combined_id":"5363_A_AB_12_1_W","hole_id":9,"scientist":"Jaylen Strosin"},{"split_id":306,"combined_id":"5363_A_AB_12_1_WR","hole_id":9,"scientist":""},{"split_id":421,"combined_id":"5363_A_AB_13_1_A","hole_id":9,"scientist":"Lula Wisozk"},{"split_id":422,"combined_id":"5363_A_AB_13_1_W","hole_id":9,"scientist":"Johnnie Hamill"},{"split_id":307,"combined_id":"5363_A_AB_13_1_WR","hole_id":9,"scientist":""},{"split_id":420,"combined_id":"5363_A_AB_13_3_A","hole_id":9,"scientist":"Roxane Eichmann"},{"split_id":424,"combined_id":"5363_A_AB_13_3_W","hole_id":9,"scientist":"Katherine Pacocha"},{"split_id":309,"combined_id":"5363_A_AB_13_3_WR","hole_id":9,"scientist":""},{"split_id":423,"combined_id":"5363_A_AB_13_2_A","hole_id":9,"scientist":"Wilfrid Heidenreich"},{"split_id":425,"combined_id":"5363_A_AB_13_2_W","hole_id":9,"scientist":"Jamar Jacobson"},{"split_id":308,"combined_id":"5363_A_AB_13_2_WR","hole_id":9,"scientist":""},{"split_id":428,"combined_id":"5363_A_AB_14_1_A","hole_id":9,"scientist":"Alivia Lesch"},{"split_id":427,"combined_id":"5363_A_AB_14_1_W","hole_id":9,"scientist":"Wanda Bernier"},{"split_id":310,"combined_id":"5363_A_AB_14_1_WR","hole_id":9,"scientist":""},{"split_id":426,"combined_id":"5363_A_AB_14_2_A","hole_id":9,"scientist":"Amely Hyatt"},{"split_id":429,"combined_id":"5363_A_AB_14_2_W","hole_id":9,"scientist":"Dean Bernhard"},{"split_id":311,"combined_id":"5363_A_AB_14_2_WR","hole_id":9,"scientist":""},{"split_id":431,"combined_id":"5363_A_AB_15_2_A","hole_id":9,"scientist":"Jazmin Blick"},{"split_id":432,"combined_id":"5363_A_AB_15_2_W","hole_id":9,"scientist":"Vernie Maggio"},{"split_id":312,"combined_id":"5363_A_AB_15_2_WR","hole_id":9,"scientist":""},{"split_id":430,"combined_id":"5363_A_AB_15_1_A","hole_id":9,"scientist":"Jimmy Toy"},{"split_id":434,"combined_id":"5363_A_AB_15_1_W","hole_id":9,"scientist":"Noemi Hamill"},{"split_id":313,"combined_id":"5363_A_AB_15_1_WR","hole_id":9,"scientist":""},{"split_id":433,"combined_id":"5363_A_AB_15_4_A","hole_id":9,"scientist":"Vilma Sipes"},{"split_id":435,"combined_id":"5363_A_AB_15_4_W","hole_id":9,"scientist":"Aliya Bogan"},{"split_id":314,"combined_id":"5363_A_AB_15_4_WR","hole_id":9,"scientist":""},{"split_id":436,"combined_id":"5363_A_AB_15_3_A","hole_id":9,"scientist":"Leopold Christiansen"},{"split_id":437,"combined_id":"5363_A_AB_15_3_W","hole_id":9,"scientist":"Katelyn Kessler"},{"split_id":315,"combined_id":"5363_A_AB_15_3_WR","hole_id":9,"scientist":""}]}
\ No newline at end of file
......@@ -54,12 +54,7 @@ async function inspect_section(ax, section_url, core_info, i) {
try {
const response = await ax.get(section_url)
if (
typeof response.data !== undefined &&
typeof response.data.items !== undefined &&
Array.isArray(response.data.items[0]) !== undefined &&
response.data.items.length > 0
) {
if (response?.data?.items?.length > 0) {
const section = response.data.items[0]
section_frag = {
"id": section.id,
......
#!/usr/bin/env node
"use strict"
//var moment = require("moment")
const faker = require("faker")
const Util = require("./fake-util")
//faker.seed(112)
const util = new Util()
module.exports = class SampleRequest {
constructor(props, section, prev_section) {
this._props = props
this._section = section
this._prev_section = prev_section
for (let k of [
"id",
"archive_files",
"combined_id",
"igsn",
"ukbgs_section_id",
"igsn_ukbgs",
]) {
delete this._props[k]
}
}
fake() {
Object.keys(this._props).forEach((property) => {
this._props[property] = this[property]
})
this._props.section = this._section_num
return this._props
}
}
#!/usr/bin/env node
"use strict"
//var moment = require("moment")
const faker = require("faker")
const Util = require("./fake-util")
//faker.seed(112)
const util = new Util()
module.exports = class CoreSectionSplit {
constructor(props, section, prev_section) {
this._props = props
this._section = section
this._prev_section = prev_section
for (let k of [
"id",
"archive_files",
"combined_id",
"igsn",
"ukbgs_section_id",
"igsn_ukbgs",
]) {
delete this._props[k]
}
}
find_id() {
return faker.fake("{{}}{{}}")
}
find_section_split_id() {
return faker.fake("{{}}{{}}")
}
find_combined_id() {
return faker.fake("{{}}{{}}")
}
find_igsn() {
return faker.fake("{{}}{{}}")
}
find_sample_date() {
return faker.fake("{{}}{{}}")
}
find_top() {
return faker.fake("{{}}{{}}")
}
find_bottom() {
return faker.fake("{{}}{{}}")
}
find_interval() {
return faker.fake("{{}}{{}}")
}
find_analyst() {
return faker.fake("{{}}{{}}")
}
find_sample_type() {
return faker.fake("{{}}{{}}")
}
find_section_top_mbsf() {
return faker.fake("{{}}{{}}")
}
find_request_no() {
return faker.fake("{{}}{{}}")
}
find_comment() {
let cond = util
.shuffle([
"BROKEN",
"CHIPS",
"DECOMP",
"DISC",
"FRAGS",
"GROUND",
"INTACT",
"MIXED",
"MUD",
"SAND",
"WEATH",
])
.map((c) => c.toLowerCase())
.slice(-2)
.join(", ")
return faker.fake(
`core ${this.core_id}: {{company.catchPhraseAdjective}}, ${cond} ({{name.firstName}} {{name.lastName}})`
)
}
find_amount() {
return faker.fake("{{}}{{}}")
}
find_amount_unit() {
return faker.fake("{{}}{{}}")
}
find_repository() {
return faker.fake("{{}}{{}}")
}
find_volume() {
return faker.fake("{{}}{{}}")
}
find_sample_top_mbsf() {
return faker.fake("{{}}{{}}")
}
find_sample_bottom_mbsf() {
return faker.fake("{{}}{{}}")
}
find_scientist() {
return faker.fake("{{}}{{}}")
}
fake() {
Object.keys(this._props).forEach((property) => {
this._props[property] = this[property]
})
this._props.section = this._section_num
return this._props
}
get section_split_id() {
return this._props.section_split_id
? this._props.section_split_id
: this.find_section_split_id()
}
get sample_date() {
return this._props.sample_date
? this._props.sample_date
: this.find_sample_date()
}
get top() {
return this._props.top ? this._props.top : this.find_top()
}
get bottom() {
return this._props.bottom ? this._props.bottom : this.find_bottom()
}
get interval() {
return this._props.interval ? this._props.interval : this.find_interval()
}
get analyst() {
return this._props.analyst ? this._props.analyst : this.find_analyst()
}
get sample_type() {
return this._props.sample_type
? this._props.sample_type
: this.find_sample_type()
}
get section_top_mbsf() {
return this._props.section_top_mbsf
? this._props.section_top_mbsf
: this.find_section_top_mbsf()
}
get request_no() {
return this._props.request_no
? this._props.request_no
: this.find_request_no()
}
get comment() {
return this._props.comment ? this._props.comment : this.find_comment()
}
get amount() {
return this._props.amount ? this._props.amount : this.find_amount()
}
get amount_unit() {
return this._props.amount_unit
? this._props.amount_unit
: this.find_amount_unit()
}
get repository() {
return this._props.repository
? this._props.repository
: this.find_repository()
}
get volume() {
return this._props.volume ? this._props.volume : this.find_volume()
}
get sample_top_mbsf() {
return this._props.sample_top_mbsf
? this._props.sample_top_mbsf
: this.find_sample_top_mbsf()
}
get sample_bottom_mbsf() {
return this._props.sample_bottom_mbsf
? this._props.sample_bottom_mbsf
: this.find_sample_bottom_mbsf()
}
get scientist() {
return this._props.scientist ? this._props.scientist : this.find_scientist()
}
}
#!/usr/bin/env node
"use strict"
//var moment = require("moment")
const faker = require("faker")
const Util = require("./fake-util")
//faker.seed(112)
const util = new Util()
module.exports = class SampleScientist {
constructor(props, section, prev_section) {
this._props = props
this._section = section
this._prev_section = prev_section
for (let k of [
"id",
"archive_files",
"combined_id",
"igsn",
"ukbgs_section_id",
"igsn_ukbgs",
]) {
delete this._props[k]
}
}
fake() {
Object.keys(this._props).forEach((property) => {
this._props[property] = this[property]
})
this._props.section = this._section_num
return this._props
}
}
......@@ -9,19 +9,12 @@ const Util = require("./fake-util")
{
"percent": 100,
"percent": 50,
"section_id": 4124,
"type": "A",
"origin_split_id": "WR",
"exists": 1,
"sampleable": 1,
"box": null,
"slot": null,
"origin_split_type": "WR",
"test": null,
"core_id": 94
}
......
......@@ -36,6 +36,7 @@ module.exports = class FakeUtil {
let duration = moment.duration(d1.diff(d2))
return duration.asDays()
}
round(val, digits = 2) {
return lodash.round(val, digits)
}
......@@ -84,4 +85,16 @@ module.exports = class FakeUtil {
}
return obj
}
str_sort_by_map_key(a, b) {
let A = a[0].toUpperCase()
let B = b[0].toUpperCase()
if (A < B) {
return -1
}
if (A > B) {
return 1
}
return 0
}
}
#!/usr/bin/env node
"use strict"
// knb July 2020
// use Node v14+
// insert samples into an mDIS database
// either - for a single split (can be of type W, WR, but not A)
//
// call this script with:
// ../api-caller-sample-inserter.sh
// or
// node src/sample-inserter.js -c 123
// or
// for i in $(seq 101 200) ; do echo $i; node split-inserter.js -c $i ; done
const config = require("./config.js")
const axios = require("axios")
const axutil = require("./axios-util.js")
const querystring = require("querystring")
const getopts = require("getopts")
const Util = require("./classes/fake-util.js")
const CurationSample = require("./classes/fake-samples.js")
const util = new Util()
const options = getopts(process.argv.slice(2), {
alias: {
split_id: "s", //split
core_id: "c", // PK column 'id' of core_core table
//infile: "i", // alternative
},
default: {
//infile: "sections.json",
// core_id: 95, //ENTY
// split_id: 4136,
core_id: 96,
},
})
//let core_url = "/api/v1/form?name=core&per-page=1&sort=-id"
//const core_info = options.infile ? JSON.parse(options.infile) : {}
const ax = axios.create(config.endpoint)
const api_url_frag = `/api/v1/form`
// al sections of
const qs_section_split = {
name: "split",
"per-page": -1,
page: 1,
sort: "section",
"filter[core_id]": options.core_id,
}
let split_sections_by_core = {}
const split_section_get_url =
api_url_frag + "?" + querystring.stringify(qs_section_split)
let split_sections_by_core_map = new Map()
console.log(querystring.unescape(split_section_get_url))
// get section for this core from section table
axutil
.get_items(ax, split_section_get_url)
.then((data) => (split_sections_by_core = data))
.then((_) => {
if (!split_sections_by_core.length) {
console.log(
`Stopped early. Nothing to do. Core id ${options.core_id} has 0 sections.
Create some fake sections for this core first.`
)
process.exit(0)
}
})
.then((_) => {
// get all sections for this core.
// All splits, whole - round and archive / working
// set up a structure finding what was already split
let types = {}
let rx = new RegExp("_A$|_W$|_WR$", "i")
split_sections_by_core.forEach((cs) =>
["A", "W", "WR"].forEach((t) => (types[t] = 0))
)
// initialize an object of all split-types,
// set count for all split - types to 0
split_sections_by_core.forEach((_) => {
const combined_id_core = _.combined_id.replace(rx, "")
_.combined_id_core = combined_id_core
split_sections_by_core_map.set(combined_id_core, Object.assign({}, types))
})
})
.then(() => {
// set count=1 for the respective split-types found
split_sections_by_core_map.forEach((v, k, map) => {
split_sections_by_core.forEach((_) => {
let tmp = split_sections_by_core_map.get(_.combined_id_core)
tmp[`${_.type}`] = 1
split_sections_by_core_map.set(_.combined_id_core, tmp)
})
})
})
.then(() => {
// only include cores that have whole rounds WR
// and that do not have A and W items (s.exists)
let suitable_sections_ids = []
split_sections_by_core_map.forEach((v, k, map) => {
if ((v.A === 1 && v.W === 1) || v.WR === 1) {
suitable_sections_ids.push(k)
}
})
split_sections_by_core_map = new Map(
[...split_sections_by_core_map.entries()].sort(util.str_sort_by_map_key)
)
if (!suitable_sections_ids.length) {
console.log(
`Stop early. Core ${split_sections_by_core[0].combined_id_core} (id ${options.core_id}) and its ${split_sections_by_core_map.size} sections
seems to be split already, at least partially.
Will not create samples if
- only an Archive half A is found, and working half W is missing
- only a Working half W is found, and archive half A is missing`
)
// console.log(split_sections_by_core_map)
console.log(split_sections_by_core_map)
process.exit(0)
} else {
console.log(
` Core ${split_sections_by_core[0].combined_id_core} (id ${options.core_id}) has ${suitable_sections_ids.length} / ${split_sections_by_core_map.size} sections for sampling.`
)
}
return new Promise((resolve, reject) => {
resolve(suitable_sections_ids.sort())
reject(suitable_sections_ids)
})
})
.then((suitable_sections_ids) => {
// filter sections again for appropriate WR sections
// now also apply "still_exists" filter
let suitable_sections = split_sections_by_core.filter((s) =>
suitable_sections_ids.some(
(v) =>
s.combined_id_core === v &&
(s.type === "WR" || s.type === "W") &&
s.exists === 1
)
)
return new Promise((resolve, reject) => {
resolve(suitable_sections)
reject(suitable_sections)
})
})
.then((suitable_sections) => {
// create template object-literals for fake splits
axutil
.get_columns(ax, "sample")
.then((curation_sample_columns) => {
let fake_sample_data = []
for (let s of suitable_sections.sort()) {
let i = 0
for (let t of ["WR", "W"]) {
let templ = new CurationSample(
Object.assign({}, curation_sample_columns),
Object.assign({}, s),
i === 0 ? {} : s[i - 1]
).fake()
fake_sample_data.push(
Object.assign({}, templ, {
"percent": 50,
"section_id": s.section_id,
"type": t,
"origin_split_id": "WR",
"origin_split_type": "WR",
"test": null,
"core_id": options.core_id,
})
)
}
i += 1
}
return new Promise((resolve, reject) => {
resolve(fake_sample_data), reject(fake_sample_data)
})
})
.then((fake_sample_data) => {
return fake_sample_data.flat().map((fake_sample, i) => {
axutil.upload(ax, `${api_url_frag}?name=sample`, fake_sample, i)
})
})
.then((fake_sample_promises) =>
Promise.all(fake_sample_promises).then((s) =>
console.log(`
#############################################################
Core ${options.core_id}, WR-/W- splitsection: Created samples for ${fake_sample_promises.length} sections
############################################################# `)
)
)
.then((_) => {
// set 'sampling' attribute from '-' to 'Y', or similar
for (let s of suitable_sections) {
let url = `${api_url_frag}/${s.id}?name=split`
let put_data = {
sampleable: "",
remarks: `core ${options.core_id}`,
}
axutil.update_item(ax, url, put_data, s.id).then((updated) => {
console.log(
{
"'sampleable' is now:": `${updated?.data?.sampleable}`,
},
{ [`id_${updated?.data?.combined_id}`]: updated?.data?.id }
)
})
}
// finally, set a flag in the core table
let url = `${api_url_frag}/${options.core_id}?name=core`
let put_data = {
oriented: 1,
comments: `sampled ${util.format_date(
util.date_between(),
"YYY-MM-DD"
)}`,
}
axutil
.update_item(ax, url, put_data, options.core_id)
.then((updated) => {
console.log(
{ url: url, "'sampling' is now:": updated?.data?.sampleable },
{ [`id_${updated?.data?.comments}`]: updated?.data?.id }
)
})
})
})
.catch((error) => console.dir(error, { depth: 0 }))
"use strict"
// query all splits of a given hole to find scintists-names
// shell command: node src/scientist-finder.js -h 9 | jq .splits[].scientist | sort | uniq
const config = require("./config.js")
const axios = require("axios")
const getopts = require("getopts")
const fs = require("fs")
const options = getopts(process.argv.slice(2), {
alias: {
hole: "h",
outfile: "f",
},
default: {
hole: 8,
//outfile: "hole-X-cores-sectioncounts.json",
outfile: "",
},
})
//let split_url = "/api/v1/form?name=core&per-page=1&sort=-id"
// let expedition_id = options.expedition
// let site_id = options.site
let hole_id = options.hole
let outfile = options.outfile
// filter[hole_id]=${hole_id}
//&filter[expedition_id]=${expedition_id}&filter[site_id]=${site_id}&
let split_url = `/api/v1/form?name=split&&per-page=1000&page=1&sort=core&filter[hole_id]=${hole_id}`
let section_count = 0
let ax = axios.create(config.endpoint)
//const core = new Core()