Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates in BYOR data convert options #817

Merged
merged 12 commits into from
Dec 16, 2024
8 changes: 4 additions & 4 deletions src/modules/hugeampkpncms.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ export default {
"https://hugeampkpncms.org/view/rest/get_research_page_access?pageid=" + param.pageID
).then(resp => resp.json());
//check for cookie if dev mode
if(json[0].field_page_mode==='dev'){
if (!!json[0].field_page_mode && json[0].field_page_mode === 'dev') {
const cookieCheck = Vue.$cookies.get(`KPN_${param.pageID}`);
//login if cookie exists
if(cookieCheck) context.dispatch("getResearchDevPage", {pageID: param.pageID, devID: cookieCheck.u, devPW: cookieCheck.p});
if (cookieCheck) context.dispatch("getResearchDevPage", { pageID: param.pageID, devID: cookieCheck.u, devPW: cookieCheck.p });
}
// set the data
context.commit("setResearchMode", json);
Expand All @@ -96,9 +96,9 @@ export default {
"https://hugeampkpncms.org/view/rest/get_research_page_dev?pageid=" + param.pageID + "&&devid=" + param.devID + "&&devpw=" + param.devPW
).then(resp => resp.json());
//if login successful, and user wants to be remembered
if(json.length>0 && param.devCK){
if (json.length > 0 && param.devCK) {
//set cookie for 14 days
const cookieValues = {u: param.devID, p: param.devPW};
const cookieValues = { u: param.devID, p: param.devPW };
Vue.$cookies.set(`KPN_${param.pageID}`, cookieValues, "14d");//14 days //30MIN
}
// set the data
Expand Down
99 changes: 76 additions & 23 deletions src/utils/dataConvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,45 @@ let convertData = function (CONVERT, DATA, PHENOTYPE_MAP) {
let cType = c.type;

switch (cType) {
case "sub to top":

let subList = d;

if (!!c["sub path"]) {
c["sub path"].map(path => {
subList = subList[path];
})
}

if (!!subList) {
let subRow;

if (!!c["copy by"]) {

switch (c["copy by"]) {

case "condition":

if (c["condition"]["type"] == "equal to") {

subList.map(row => {
//console.log("field", row[c["condition"]["field"]], c["condition"]["value"])

if (row[c["condition"]["field"]] == c["condition"]["value"]) {
subRow = row
}
})
}

break;
}
}

tempObj[c["field name"]] = subRow[c["raw field"]];
}

break;

case "join":
tempObj[c["field name"]] = joinValues(c["fields to join"], c["join by"], d);
d[c["field name"]] = tempObj[c["field name"]];
Expand All @@ -94,28 +133,42 @@ let convertData = function (CONVERT, DATA, PHENOTYPE_MAP) {

let newFields = c["field name"];
let newFieldValues = [];
let string2Split = d[c["field to split"]];
let loopIndex = 1;
c["split by"].map(s => {

let [key, ...rest] = string2Split.split(s);
string2Split = rest.join(s)

if (loopIndex < c["split by"].length) {
newFieldValues.push(key)
} else if (loopIndex = c["split by"].length) {
newFieldValues.push(key)
newFieldValues.push(rest.join(s))
}
loopIndex++;
})
let string2Split = (!!tempObj[c["field to split"]]) ? tempObj[c["field to split"]] : d[c["field to split"]];

//console.log('c["field name"]', c["field name"]);

if (!!string2Split) {
let loopIndex = 1;
c["split by"].map(s => {

let [key, ...rest] = string2Split.split(s);
string2Split = rest.join(s)

if (loopIndex < c["split by"].length) {
newFieldValues.push(key)
} else if (loopIndex = c["split by"].length) {
newFieldValues.push(key)
newFieldValues.push(rest.join(s))
}
loopIndex++;
})

//console.log("newFieldValues", newFieldValues);

loopIndex = 0;
newFields.map(f => {
tempObj[f] = newFieldValues[loopIndex];
d[f] = tempObj[f];



loopIndex++;
})

console.log(tempObj);
}


loopIndex = 0;
newFields.map(f => {
tempObj[f] = newFieldValues[loopIndex];
d[f] = tempObj[f];
loopIndex++;
})

break;

Expand All @@ -126,7 +179,6 @@ let convertData = function (CONVERT, DATA, PHENOTYPE_MAP) {

case "calculate":


let calType = c["calculation type"];

switch (calType) {
Expand All @@ -140,7 +192,8 @@ let convertData = function (CONVERT, DATA, PHENOTYPE_MAP) {
let calcString = "";

c["expression"].map(e => {
let eValue = !!["+", "-", "*", "/", "(", ")"].includes(e) ? e : (typeof e === 'number') ? e : d[e];
let eValue = !!["+", "-", "*", "/", "(", ")"].includes(e) ? e : (typeof e === 'number') ? e :
(!!tempObj[e] || tempObj[e] === 0) ? (tempObj[e] === 0) ? 0 : tempObj[e] : (d[e] === 0) ? 0 : d[e];
calcString += eValue;
});

Expand Down
Loading