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

insert new valuelist items (rock_types,colors, from JSON file)

parent d3daf57d
#!/usr/bin/env bash
\ No newline at end of file
#!/usr/bin/env node
const data = require("../data/macrotstrat-lithclasses-extended.json")
// {
// id: 24929,
// listname: 'Ctrl_rock_calssification',
// display: 'Xenolithic-Metamorphic-Slate',
// remark: 'Xenolithic',
// sort: 76
// }
//["lith_id","name","type","group","class","color","fill","t_units"]
//const litho_data = require("../data/macrotstrat-lithclasses-extended.json")
let i = 0
let original_lists = new Map()
original_lists.set("rock_classes", {
data: new Set([
...data.success.data
.sort(by_class)
.map((v, k) => v.class)
.sort(),
]),
list_name: "Ctrl_rock_calssification",
})
original_lists.set("rock_types", {
data: new Set([...data.success.data.map((v, k) => v.type).sort()]),
list_name: "UNIT_TYPE",
})
original_lists.set("rock_colors", {
data: new Set([...data.success.data.map((v, k) => v.color_name)].sort()),
list_name: "COLOUR",
})
let rock_classes = []
let rock_types = []
let rock_colors = []
//console.log(closest_colors)
let value_list_data = {
rock_classes,
rock_types,
rock_colors,
}
i = 0
original_lists.forEach((set, k, map) => {
set.data.forEach((v) => {
i++
value_list_data[k].push({
listname: `${map.get(k).list_name}`,
display: v,
remark: v,
sort: i * 100,
})
})
i = 0
})
i = 0
//console.log(JSON.stringify(rock_classes))
// console.log(rock_classes)
// console.log(rock_types)
// console.log(rock_colors)
function by_class(a, b) {
let A = a.class.toUpperCase()
let B = b.class.toUpperCase()
if (A < B) {
return -1
}
if (A > B) {
return 1const config = require("./config.js")
// console.log(value_list_data)
console.log(JSON.stringify(value_list_data))
//module.export = { value_list_data }
"use strict"
// for synchronous operation
// call this as:
// for i in $(seq 1 3); do echo $i; node api - caller.js; done
const axutil = require("./axios-util.js")
const axios = require("axios")
const config = require("./config.js")
let value_list_data = require("../data/value_lists/macrostrat_rock_classes.json")
let value_list_post_url = `/api/v1/list-values?name=ListValues`
let ax = axios.create(config.endpoint)
let i = 0
// value_list_data.forEach((list) => {
// list.forEach((record) => {
// axutil.upload(ax, value_list_post_url, record, i)
// i++
// })
// })
Object.values(value_list_data)
.map((r) => Object.values(r))
.map((v) =>
v.forEach((record, k) => {
axutil.upload(ax, value_list_post_url, record, i)
i++
})
)
......@@ -12,7 +12,7 @@ const options = getopts(process.argv.slice(2), {
"listname": "n",
"filter": "f",
"display": "d", // show .display Value only
"display": "e", // show .value : r.remark
"display": "e", // show {.value : r.remark}
},
default: {
all: "",
......@@ -28,12 +28,12 @@ const ax = axios.create(config.endpoint)
/**
* {{baseUrl}}/api/v1/list-values/list-names
*/
let finder = new Finder(ax, "/api/v1/list-values")
let finder = new Finder(ax, "/api/v1/list-values?per-page=1000&")
let rx = new RegExp(`${options.f}`, "i")
if (options.n) {
options.a = false
let url = `/api/v1/list-values?per-page=-1&filter[listname]=${options.listname}`
let url = `/api/v1/list-values?per-page=1000&filter[listname]=${options.listname}`
finder
.find_list_values(url)
.then((data) => {
......@@ -49,7 +49,7 @@ if (options.n) {
})
.catch((error) => console.dir(error, { depth: 0 }))
} else if (options.a) {
let url = `/api/v1/list-values/list-names`
let url = `/api/v1/list-values/list-names?per-page=1000&page=2`
let listnames = []
finder
......
let obj = [
{
"request_part": "s",
"id": 5,
"expedition_id": 10,
"combined_id": "5363_s",
"request_id": "4533",
"request_type": "ShipShore",
"scientist_1": "Erick Hansen",
"scientist_2": null,
"scientist_3": null,
"purpose": "Q_TS",
"request_date": "2020-02-19",
"approval_date": "2020-04-01",
"completion_date": "2020-04-01",
"remarks": "maximize",
"sample_material": "",
"sample_volume": 11.41,
"request_no": 4533,
"request_complete": "yes",
"sample_amount": null,
"sample_unit": "ATP",
"analyst": "KH",
"program_id": 1,
},
]
let existing_samples_reqno = [4533]
let previous_requests = obj.filter((r) =>
existing_samples_reqno.some((s) => Number.parseInt(r.request_no) === s)
)
let req_len_before = obj.length
let new_requests = obj.filter((r) => {
const current_reqno = Number.parseInt(r.request_no)
// let equal_request_nos = (el) => el === current_reqno
return !(-1 === existing_samples_reqno.find((el) => el === current_reqno))
})
debugger
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