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

finish work on fake-scientists :-)

parent c1d6b221
{"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
{"splits":[{"split_id":440,"combined_id":"5363_A_AB_10_2_A","expedition_id":10,"scientist":"Dillon Kunze","first_name":"Dillon","last_name":"Kunze"},{"split_id":439,"combined_id":"5363_A_AB_10_2_W","expedition_id":10,"scientist":"Sophia Morar","first_name":"Sophia","last_name":"Morar"},{"split_id":438,"combined_id":"5363_A_AB_10_1_A","expedition_id":10,"scientist":"Yessenia Witting","first_name":"Yessenia","last_name":"Witting"},{"split_id":445,"combined_id":"5363_A_AB_10_1_W","expedition_id":10,"scientist":"Virginia Mueller","first_name":"Virginia","last_name":"Mueller"},{"split_id":443,"combined_id":"5363_A_AB_10_3_A","expedition_id":10,"scientist":"Erick Hansen","first_name":"Erick","last_name":"Hansen"},{"split_id":442,"combined_id":"5363_A_AB_10_3_W","expedition_id":10,"scientist":"Cordia Gislason","first_name":"Cordia","last_name":"Gislason"},{"split_id":444,"combined_id":"5363_A_AB_10_4_A","expedition_id":10,"scientist":"Cynthia Hoeger","first_name":"Cynthia","last_name":"Hoeger"},{"split_id":441,"combined_id":"5363_A_AB_10_4_W","expedition_id":10,"scientist":"Keegan Fadel","first_name":"Keegan","last_name":"Fadel"},{"split_id":416,"combined_id":"5363_A_AB_11_1_A","expedition_id":10,"scientist":"Beulah Lockman","first_name":"Beulah","last_name":"Lockman"},{"split_id":414,"combined_id":"5363_A_AB_11_1_W","expedition_id":10,"scientist":"Ashtyn Wintheiser","first_name":"Ashtyn","last_name":"Wintheiser"},{"split_id":415,"combined_id":"5363_A_AB_11_2_A","expedition_id":10,"scientist":"Shanny Hessel","first_name":"Shanny","last_name":"Hessel"},{"split_id":417,"combined_id":"5363_A_AB_11_2_W","expedition_id":10,"scientist":"Burnice Jerde","first_name":"Burnice","last_name":"Jerde"},{"split_id":419,"combined_id":"5363_A_AB_12_1_A","expedition_id":10,"scientist":"Margaret Quigley","first_name":"Margaret","last_name":"Quigley"},{"split_id":418,"combined_id":"5363_A_AB_12_1_W","expedition_id":10,"scientist":"Jaylen Strosin","first_name":"Jaylen","last_name":"Strosin"},{"split_id":421,"combined_id":"5363_A_AB_13_1_A","expedition_id":10,"scientist":"Lula Wisozk","first_name":"Lula","last_name":"Wisozk"},{"split_id":422,"combined_id":"5363_A_AB_13_1_W","expedition_id":10,"scientist":"Johnnie Hamill","first_name":"Johnnie","last_name":"Hamill"},{"split_id":420,"combined_id":"5363_A_AB_13_3_A","expedition_id":10,"scientist":"Roxane Eichmann","first_name":"Roxane","last_name":"Eichmann"},{"split_id":424,"combined_id":"5363_A_AB_13_3_W","expedition_id":10,"scientist":"Katherine Pacocha","first_name":"Katherine","last_name":"Pacocha"},{"split_id":423,"combined_id":"5363_A_AB_13_2_A","expedition_id":10,"scientist":"Wilfrid Heidenreich","first_name":"Wilfrid","last_name":"Heidenreich"},{"split_id":425,"combined_id":"5363_A_AB_13_2_W","expedition_id":10,"scientist":"Jamar Jacobson","first_name":"Jamar","last_name":"Jacobson"},{"split_id":428,"combined_id":"5363_A_AB_14_1_A","expedition_id":10,"scientist":"Alivia Lesch","first_name":"Alivia","last_name":"Lesch"},{"split_id":427,"combined_id":"5363_A_AB_14_1_W","expedition_id":10,"scientist":"Wanda Bernier","first_name":"Wanda","last_name":"Bernier"},{"split_id":426,"combined_id":"5363_A_AB_14_2_A","expedition_id":10,"scientist":"Amely Hyatt","first_name":"Amely","last_name":"Hyatt"},{"split_id":429,"combined_id":"5363_A_AB_14_2_W","expedition_id":10,"scientist":"Dean Bernhard","first_name":"Dean","last_name":"Bernhard"},{"split_id":431,"combined_id":"5363_A_AB_15_2_A","expedition_id":10,"scientist":"Jazmin Blick","first_name":"Jazmin","last_name":"Blick"},{"split_id":432,"combined_id":"5363_A_AB_15_2_W","expedition_id":10,"scientist":"Vernie Maggio","first_name":"Vernie","last_name":"Maggio"},{"split_id":430,"combined_id":"5363_A_AB_15_1_A","expedition_id":10,"scientist":"Jimmy Toy","first_name":"Jimmy","last_name":"Toy"},{"split_id":434,"combined_id":"5363_A_AB_15_1_W","expedition_id":10,"scientist":"Noemi Hamill","first_name":"Noemi","last_name":"Hamill"},{"split_id":433,"combined_id":"5363_A_AB_15_4_A","expedition_id":10,"scientist":"Vilma Sipes","first_name":"Vilma","last_name":"Sipes"},{"split_id":435,"combined_id":"5363_A_AB_15_4_W","expedition_id":10,"scientist":"Aliya Bogan","first_name":"Aliya","last_name":"Bogan"},{"split_id":436,"combined_id":"5363_A_AB_15_3_A","expedition_id":10,"scientist":"Leopold Christiansen","first_name":"Leopold","last_name":"Christiansen"},{"split_id":437,"combined_id":"5363_A_AB_15_3_W","expedition_id":10,"scientist":"Katelyn Kessler","first_name":"Katelyn","last_name":"Kessler"}]}
\ No newline at end of file
......@@ -8,10 +8,9 @@ const Util = require("./fake-util")
const util = new Util()
module.exports = class SampleScientist {
constructor(props, section, prev_section) {
constructor(props, scientist, prev_section) {
this._props = props
this._section = section
this._prev_section = prev_section
this._scientist = scientist
for (let k of [
"id",
"archive_files",
......@@ -23,12 +22,198 @@ module.exports = class SampleScientist {
delete this._props[k]
}
}
find_first_name() {
return faker.fake("{{name.firstName}}")
}
find_last_name() {
return faker.fake("{{name.lastName}}")
}
find_title() {
const title_fakes = [
"",
"",
"",
"",
"Dr.",
"Dr.",
"Dipl.-Geol.",
"Dr",
"Prof.",
"Prof. Dr",
"Jun. Prof.",
"MSc.",
"Dr. h.c.",
"Stud. rer. geol.",
"Dr. habil., Dr. med. dent.",
"Dr. Ing.",
]
return util
.shuffle([faker.fake("{{name.title}}"), title_fakes].flat())
.pop()
}
find_institute() {
let d = util
.shuffle(["Geophysics", "Geology", "Microbiology", "Paleontology"])
.pop()
let i = util
.shuffle(["Centre", "Institute", "Institute", "Society", "Academy"])
.pop()
let f = util.shuffle(["for", "of", "for"]).pop()
let x = Math.random > 0.7 ? `${this.department}` : ""
let b = faker
.fake("{{company.bsAdjective}}")
.split(/[ -]/)
.map((b) => util.ucfirstlc(b))
.join("-")
let c = this.city.replace(/,.*/, "")
let z = /^[BP]/.test(this.city)
? `${[Math.random() > 0.5 ? "Uni " : "TU-"]}${this.city}`
: faker
.fake(`${c} ${i} ${f} ${x} ${b} ${d}`)
.split(/[ -]/)
.map((b) => util.ucfirstlc(b))
.join(" ")
this._props.institute = z
return z
}
find_department() {
return faker.fake(`{{commerce.department}}`)
}
find_street() {
let s = faker.fake("{{address.streetAddress}}")
let g = /^(\d+)/.test(s) ? s.replace(RegExp.$1, "").trim() : ""
let w = util
.shuffle(["Weg", "Str", "Str.", "Allee", "Platz", "Straße"])
.pop()
g = `${g} ${w} ${Number.parseInt(Math.random() * 15) + 1}`
return this.country === "Germany" ? g : s
}
find_city() {
const c = Number.parseInt(Math.random() * 1000)
const v = [8, 7, 3, 1].find((n) => c % n === 0)
let city = ""
switch (v) {
case 8:
city = faker.fake(`{{address.city}} {{address.citySuffix}}`)
break
case 7:
city = faker.fake(`{{address.cityPrefix}} {{address.city}}`)
break
case 3:
city = faker.fake(`{{address.city}}, {{address.stateAbbr}}`)
break
case 2:
city = faker.fake(`{{address.city}} {{address.city}}`)
break
default:
city = util
.shuffle([
"Kiel",
"Potsdam",
"Berlin",
"Potsdam",
"Berlin",
"potsdam",
"Berlin-Spandau",
"Bremen",
"Bremen",
])
.pop()
break
}
this._props.city = city
return city
}
find_zip() {
let z = /^[BP]/.test(this.city)
? `${14473 + Math.trunc(Math.random() * 30)}`
: faker.fake("{{address.zipCode}}")
return z
}
find_state() {
let z = /^[BP]/.test(this.city) ? "-" : faker.fake("{{address.state}}")
return z
}
find_country() {
let z = /^[BP]/.test(this.city)
? "Germany"
: faker.fake("{{address.state}}")
this._props.country = z
return z
}
find_email() {
let z = /^[BP]/.test(this.city)
? `${this.last_name}@${this.institute.replace(" ", "-").toLowerCase()}.de`
: faker.fake(
`${[
Math.random() > 0.5 ? this.first_name : this.last_name,
]}@{{internet.domainName}}.${[
Math.random() > 0.5 ? this.city : "ac",
]}.{{internet.domainSuffix}}`
)
return z
}
find_phone() {
return faker.fake("{{phone.phoneNumber}}")
}
find_full_name() {
const t = Math.random() > 0.8 ? `${this.title} ` : ""
return `${t}${this.first_name} ${this.last_name}`
}
fake() {
Object.keys(this._props).forEach((property) => {
this._props[property] = this[property]
})
this._props.section = this._section_num
this._props.expedition_id = this._scientist.expedition_id
return this._props
}
get first_name() {
return this._props.first_name
? this._props.first_name
: this.find_first_name()
}
get last_name() {
return this._props.last_name ? this._props.last_name : this.find_last_name()
}
get title() {
return this._props.title ? this._props.title : this.find_title()
}
get institute() {
return this._props.institute ? this._props.institute : this.find_institute()
}
get department() {
return this._props.department
? this._props.department
: this.find_department()
}
get street() {
return this._props.street ? this._props.street : this.find_street()
}
get city() {
return this._props.city ? this._props.city : this.find_city()
}
get zip() {
return this._props.zip ? this._props.zip : this.find_zip()
}
get state() {
return this._props.state ? this._props.state : this.find_state()
}
get country() {
return this._props.country ? this._props.country : this.find_country()
}
get email() {
return this._props.email ? this._props.email : this.find_email()
}
get phone() {
return this._props.phone ? this._props.phone : this.find_phone()
}
get full_name() {
return this._props.full_name ? this._props.full_name : this.find_full_name()
}
}
......@@ -97,4 +97,8 @@ module.exports = class FakeUtil {
}
return 0
}
ucfirstlc(str) {
return lodash.upperFirst(lodash.toLower(str))
}
}
......@@ -131,10 +131,7 @@ axutil
// 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
(v) => (s.type === "WR" || s.type === "W") && s.exists === 1
)
)
return new Promise((resolve, reject) => {
......
......@@ -45,13 +45,22 @@ ax.get(split_url)
// core_id: element.core,
// section_count: element.last_section,
// recovered_length: element.core_recovery,
// expedition_id: element.expedition_id,
expedition_id: element.expedition_id,
//site_id: element.site_id,
hole_id: element.hole_id,
// remark: element.remarks,
scientist: /\((.+)\)/.test(element.remarks) ? RegExp.$1 : "",
})
})
splits = splits
.filter((s) => s.scientist)
.map((s) => {
let sc = s.scientist
s.first_name = sc.replace(/ .+$/, "")
s.last_name = sc.replace(/^.+ /, "")
s.full_name = sc.scientist
return s
})
let json = JSON.stringify({ splits })
if (outfile) {
fs.writeFileSync(outfile, json, (err) => {
......
......@@ -2,24 +2,11 @@
"use strict"
// knb July 2020
// use Node v14+
// insert section-splits into mDIS database
// either - for a single core (which contains 1-4 sections)
// TODO
// or read in from infile (created by 'sectioncount-of-cores-of-single-hole.js')
// with the following structure:
/* { "cores": [ {
"id": 121,
"combined_id": "2739_A_A_1",
"core_id": 1,
"section_count": 4,
}, ] } */
// insert fake scietists into mDIS database
// call this script with:
// ../api-caller-split-inserter.sh
// or
// node src/split-inserter.js -c 123
// or
// for i in $(seq 101 200) ; do echo $i; node split-inserter.js -c $i ; done
// node src/scientist-inserter.js -f infile.json
const config = require("./config.js")
const axios = require("axios")
const axutil = require("./axios-util.js")
......@@ -28,13 +15,40 @@ const getopts = require("getopts")
const Util = require("./classes/fake-util.js")
const SampleScientist = require("./classes/fake-scientists.js")
const util = new Util()
const fs = require("fs")
const options = getopts(process.argv.slice(2), {
alias: {
infile: "i",
},
default: {
infile: "scientists.json",
// example_infile: {
// "splits": [
// {
// "split_id": 275,
// "combined_id": "5363_A_AB_1_1_WR",
// "hole_id": 9,
// "scientist": "Knut Behrends",
// },
// // ],
// "columns": [
// "id",
// "expedition_id",
// "first_name",
// "last_name",
// "title",
// "institute",
// "department",
// "street",
// "city",
// "zip",
// "state",
// "country",
// "email",
// "phone",
// "full_name",
// ],
// },
},
})
......@@ -44,182 +58,53 @@ const ax = axios.create(config.endpoint)
const api_url_frag = `/api/v1/form`
// al sections of
const qs_section_split = {
name: "split",
name: "scientist",
"per-page": -1,
page: 1,
sort: "section",
"filter[core_id]": options.core_id,
sort: "scientist",
// "filter[]": options.,
}
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()
let scientists_from_file = JSON.parse(fs.readFileSync(options.infile, "utf8"))
// console.log(scientists_from_file)
let scientist_defaults = scientists_from_file.splits
console.log(querystring.unescape(split_section_get_url))
console.log(scientist_defaults)
// process.exit(0)
// 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 splittable_sections_ids = []
split_sections_by_core_map.forEach((v, k, map) => {
if (v.A === 0 && v.W === 0 && v.WR === 1) {
splittable_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 (!splittable_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.
Maybe create the missing split sections manually.`
)
// 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 ${splittable_sections_ids.length} / ${split_sections_by_core_map.size} splittable sections.`
.get_columns(ax, "scientist")
.then((scientist_columns) => {
let fake_scientist_data = []
for (let s of scientist_defaults) {
let templ = new SampleScientist(
Object.assign({}, scientist_columns),
s
).fake()
fake_scientist_data.push(
Object.assign({}, templ, {
first_name: s.first_name,
last_name: s.last_name,
//full_name: s.full_name,
expedition_id: s.expedition_id,
})
)
}
return new Promise((resolve, reject) => {
resolve(splittable_sections_ids.sort())
reject(splittable_sections_ids)
resolve(fake_scientist_data), reject(fake_scientist_data)
})
})
.then((splittable_sections_ids) => {
// filter sections again for appropriate WR sections
// now also apply "still_exists" filter
let splittable_sections = split_sections_by_core.filter((s) =>
splittable_sections_ids.some(
(v) => s.combined_id_core === v && s.type === "WR" && s.exists === 1
)
)
return new Promise((resolve, reject) => {
resolve(splittable_sections)
reject(splittable_sections)
.then((fake_scientist_data) => {
return fake_scientist_data.flat().map((fake_scientist, i) => {
axutil.upload(ax, `${api_url_frag}?name=scientists`, fake_scientist, i)
})
})
.then((splittable_sections) => {
// create template object-literals for fake splits
axutil
.get_columns(ax, "split")
.then((core_section_split_columns) => {
let fake_section_data = []
for (let s of splittable_sections.sort()) {
let i = 0
for (let t of ["A", "W"]) {
let templ = new CoreSectionSplit(
Object.assign({}, core_section_split_columns),
Object.assign({}, s),
i === 0 ? {} : s[i - 1]
).fake()
fake_section_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_section_data), reject(fake_section_data)
})
})
.then((fake_section_data) => {
return fake_section_data.flat().map((fake_split, i) => {
axutil.upload(ax, `${api_url_frag}?name=split`, fake_split, i)
})
})
.then((fake_split_promises) =>
Promise.all(fake_split_promises).then((s) =>
console.log(`
.then((fake_scientist_promises) =>
Promise.all(fake_scientist_promises).then((s) =>
console.log(`
#############################################################
Core ${options.core_id}: Created A- and W- splits for ${fake_split_promises.length} sections
Created fake scientists from entries in file ${options.infile}
############################################################# `)
)
)
.then((_) => {
// set still_exists attribute from 1 to 0
for (let s of splittable_sections) {
let url = `${api_url_frag}/${s.id}?name=split`
let put_data = {
exists: 0,
remarks: `core ${options.core_id}`,
}
axutil.update_item(ax, url, put_data, s.id).then((updated) => {
console.log(
{
"'still_exists' is now:": `${updated?.data?.exists}`,
},
{ [`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: `split ${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, "'oriented/split' is now:": updated?.data?.oriented },
{ [`id_${updated?.data?.comments}`]: updated?.data?.id }
)
})
})
})
)
)
.catch((error) => console.dir(error, { depth: 0 }))
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