From 06f5cb5d7ab8933046934a8852836c8daa68c9f6 Mon Sep 17 00:00:00 2001 From: o9h <hoppdj@ornl.gov> Date: Mon, 24 Apr 2023 14:44:50 -0400 Subject: [PATCH] Tweak convertToCSV --- code/javascript/exportFunctions.js | 36 ++++++++++++++++++++++-------- code/javascript/jarvisCommands.js | 7 ------ code/javascript/jarvisFunctions.js | 2 +- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/code/javascript/exportFunctions.js b/code/javascript/exportFunctions.js index befd1217..86c8c403 100755 --- a/code/javascript/exportFunctions.js +++ b/code/javascript/exportFunctions.js @@ -28,7 +28,7 @@ function exportJSONFile(fileName, string){ } } -function convertToCSV(objArray) { +function convertToCSV_Old(objArray) { let array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray; let str = ''; @@ -46,15 +46,33 @@ function convertToCSV(objArray) { return str; } -function exportCSVFile(csv, fileTitle) { +function convertToCSV(objArray) { + let array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray; + let str = ''; + + for (let i = 0; i < array.length; i++) { + let line = ''; + for (let index in array[i]) { + // if (line != '') line += ',' + + line += array[i][index]; + } + + str += line + '\r\n'; + } + + return str; +} + +function exportCSVFile(items, fileTitle) { // Convert Object to JSON - // var csv; - // try {let jsonObject = JSON.stringify(items); - // csv = this.convertToCSV(jsonObject);} - // catch { - // csv = items - // } + var csv; + try {let jsonObject = JSON.stringify(items); + csv = this.convertToCSV(jsonObject);} + catch { + csv = items + } let exportedFilename = fileTitle + '.csv' || 'export.csv'; @@ -81,7 +99,7 @@ function exportCSVFile_Old(items, fileTitle) { // Convert Object to JSON var csv; try {let jsonObject = JSON.stringify(items); - csv = this.convertToCSV(jsonObject);} + csv = this.convertToCSV_Old(jsonObject);} catch { csv = items } diff --git a/code/javascript/jarvisCommands.js b/code/javascript/jarvisCommands.js index 3336397c..fc882a12 100755 --- a/code/javascript/jarvisCommands.js +++ b/code/javascript/jarvisCommands.js @@ -6,13 +6,6 @@ function jarvisCommand(command){ command = command.toUpperCase(); // Will be removed once all commands are processed by the database switch (true) { - case (command.includes('download 7 by 7 points'.toUpperCase()) || - command.includes('download seven by seven points'.toUpperCase()) || - command.includes('download 7x7 points'.toUpperCase()) || - command.includes('download 7 x 7 points'.toUpperCase())): - downloadPoints_Old("16","solo.id", "7x7_Matrix"); - break; - // Old Command functions to be improved/replaced /* NON FLY-TO POINTS --------------------------------------------------------------------------------------------------*/ case (command.includes('Jarvis show me Metabolomics'.toUpperCase())): diff --git a/code/javascript/jarvisFunctions.js b/code/javascript/jarvisFunctions.js index 0da0b155..4fa68a31 100755 --- a/code/javascript/jarvisFunctions.js +++ b/code/javascript/jarvisFunctions.js @@ -349,7 +349,7 @@ function downloadPoints_Old(id, columnName, fileName) { ).then(function (response) { //console.log(response.headers); response.json().then(function (myJson) { - console.log(myJson); + // console.log(myJson); exportCSVFile_Old(myJson, fileName); }); }); -- GitLab