Skip to content

Commit

Permalink
Merge pull request #461 from harena-lab/development
Browse files Browse the repository at this point in the history
refactor (report): play report with configurable schema
  • Loading branch information
santanche authored Nov 3, 2023
2 parents bba2e97 + c051378 commit 889976e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/adonisjs/public/report/category/cases/play/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<script src="/dccs/components/data/dcc-submit.js"></script>
<script src="/dccs/components/data/dcc-model.js"></script>
<script src="/dccs/components/data/dcc-record.js"></script>
<script src="/dccs/components/data/dcc-table-csv.js"></script>

<script src="/dccs/base/subscribe-dcc.js"></script>
<script src="/dccs/base/trigger-dcc.js"></script>
Expand Down Expand Up @@ -86,6 +87,13 @@
<p>Report</p>
</div>

<hr>
<div class="mt-2">
Schema: list of fields to be retrieved
<dcc-table-csv separator="," view=""></dcc-table-csv>
</div>
<hr>

<div id="case-boxes" class="container-fluid draft-scroll-container">
<dcc-rest id="harena-logger-list" bind="harena-logger-list" subscribe="logger/list/get"></dcc-rest>
<dcc-rest id="harena-logger-list-page" bind="harena-logger-list-page"></dcc-rest>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Perguntas_1.q1,Perguntas_1.q2,Perguntas_1.q3,Perguntas_1.q4,Perguntas_1.q5
23 changes: 15 additions & 8 deletions src/adonisjs/public/report/js/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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"'
Expand All @@ -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())) + '","' +
Expand Down

0 comments on commit 889976e

Please sign in to comment.