From c051378c1803aacddd85842c4d79a6d8b28e8e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santanch=C3=A8?= Date: Fri, 3 Nov 2023 11:44:34 -0300 Subject: [PATCH] refactor (report): play report with configurable schema --- .../report/category/cases/play/index.html | 8 +++++++ .../schemas/experiment-clinical-reasoning.csv | 1 + .../cases/play/schemas/mutant-cell.csv | 1 + src/adonisjs/public/report/js/report.js | 23 ++++++++++++------- 4 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 src/adonisjs/public/report/category/cases/play/schemas/experiment-clinical-reasoning.csv create mode 100644 src/adonisjs/public/report/category/cases/play/schemas/mutant-cell.csv diff --git a/src/adonisjs/public/report/category/cases/play/index.html b/src/adonisjs/public/report/category/cases/play/index.html index cdc7ed9e..1a616980 100644 --- a/src/adonisjs/public/report/category/cases/play/index.html +++ b/src/adonisjs/public/report/category/cases/play/index.html @@ -41,6 +41,7 @@ + @@ -86,6 +87,13 @@

Report

+
+
+ Schema: list of fields to be retrieved + +
+
+
diff --git a/src/adonisjs/public/report/category/cases/play/schemas/experiment-clinical-reasoning.csv b/src/adonisjs/public/report/category/cases/play/schemas/experiment-clinical-reasoning.csv new file mode 100644 index 00000000..be31fb9d --- /dev/null +++ b/src/adonisjs/public/report/category/cases/play/schemas/experiment-clinical-reasoning.csv @@ -0,0 +1 @@ +Caso_01.hypothesis,Caso_02.hypothesis,Caso_03.hypothesis,Caso_04.hypothesis,Caso_05.hypothesis,Caso_06.hypothesis,Caso_07.hypothesis,Caso_08.hypothesis,Caso_09.hypothesis,Caso_10.hypothesis,Caso_11.hypothesis,Caso_12.hypothesis,Pergunta_01.hypothesis,Pergunta_02.hypothesis \ No newline at end of file diff --git a/src/adonisjs/public/report/category/cases/play/schemas/mutant-cell.csv b/src/adonisjs/public/report/category/cases/play/schemas/mutant-cell.csv new file mode 100644 index 00000000..896ad824 --- /dev/null +++ b/src/adonisjs/public/report/category/cases/play/schemas/mutant-cell.csv @@ -0,0 +1 @@ +Perguntas_1.q1,Perguntas_1.q2,Perguntas_1.q3,Perguntas_1.q4,Perguntas_1.q5 \ No newline at end of file diff --git a/src/adonisjs/public/report/js/report.js b/src/adonisjs/public/report/js/report.js index 1c54b54d..0adc1cec 100644 --- a/src/adonisjs/public/report/js/report.js +++ b/src/adonisjs/public/report/js/report.js @@ -4,6 +4,7 @@ class ReportManager { MessageBus.i.subscribe('report/update', this._report) this._download = this._download.bind(this) MessageBus.i.subscribe('report/download', this._download) + MessageBus.i.subscribe('table/updated', this._updateCSV.bind(this)) } async _requestLogger () { @@ -19,15 +20,19 @@ class ReportManager { return logger } + _updateCSV (topic, message) { + console.log('===== CSV received') + console.log(message.table.schema) + this._schema = message.table.schema + } + async _download () { const zeroPad = (num) => String(num).padStart(2, '0') const logger = await this._requestLogger() if (logger != null) { - const schema = ['Caso_01', 'Caso_02', 'Caso_03', 'Caso_04', 'Caso_05', - 'Caso_06', 'Caso_07', 'Caso_08', 'Caso_09', 'Caso_10', - 'Caso_11', 'Caso_12', 'Pergunta_01', 'Pergunta_02'] + const schema = this._schema let table = '"user id","user","start","date"' for (const s of schema) table += ',"' + s + '","time","miliseconds"' @@ -41,16 +46,18 @@ class ReportManager { zeroPad(lastTime.getDate()) + '/' + zeroPad(lastTime.getMonth() + 1) + '/' + zeroPad(lastTime.getFullYear()) + '"' + console.log(track) + console.log(schema) for (const s of schema) { - const sh = s + '.hypothesis' + console.log(track[s]) let time = -1 - if (track[sh] != null) { - const t = new Date(track[sh]) + if (track[s] != null) { + const t = new Date(track[s]) time = new Date(t - lastTime) lastTime = t } - table += ',"' + (answers.variables[sh] == null ? '' - : answers.variables[sh].replace(/"/g, '""')) + + table += ',"' + (answers.variables[s] == null ? '' + : answers.variables[s].replace(/"/g, '""')) + '","' + (time == -1 ? '' : zeroPad(time.getMinutes()) + ':' + zeroPad(time.getSeconds())) + '","' +