Skip to content

Commit

Permalink
Merge pull request #252 from neherlab/fix/export
Browse files Browse the repository at this point in the history
add cumulative fields to export, fix time
  • Loading branch information
ivan-aksamentov committed Mar 28, 2020
2 parents f76b74c + 127e6f8 commit 21d9672
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/algorithms/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,12 @@ export function exportSimulation(result: UserResult) {
// TODO: Make the down sampling interval a parameter

const header = keys(result.trajectory[0].current)
const tsv = [header.join('\t')]
const tsv_header : String[] = header.map(x => ( x == 'critical' ? 'ICU' : x))

const header_cumulative = keys(result.trajectory[0].cumulative)
const tsv_header_cumulative = header_cumulative.map(x => "cumulative_"+x)

const tsv = ['time\t' + tsv_header.concat(tsv_header_cumulative).join('\t')]

const pop: Record<string, boolean> = {}
result.trajectory.forEach((d) => {
Expand All @@ -495,10 +500,13 @@ export function exportSimulation(result: UserResult) {
return
} // skip if date is already in table
pop[t] = true
let buf = '${d.time}'
let buf = t
header.forEach((k) => {
buf += `\t${Math.round(d.current[k].total)}`
})
header_cumulative.forEach(k => {
buf += `\t${Math.round(d.cumulative[k].total)}`
})
tsv.push(buf)
})

Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/utils/exportResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function exportAll(result: AlgorithmResult) {
if (!deterministic) {
console.error('Error: the results of the simulation cannot be exported because they are nondeterministic')
} else {
zip.file('covid.results.deterministic.csv', exportSimulation(deterministic))
zip.file('covid.results.deterministic.tsv', exportSimulation(deterministic))
}

const zipFile = await zip.generateAsync({ type: 'blob' })
Expand All @@ -64,7 +64,7 @@ export function exportResult(result: AlgorithmResult) {
return
}

saveFile(exportSimulation(deterministic), 'covid.results.deterministic.csv')
saveFile(exportSimulation(deterministic), 'covid.results.deterministic.tsv')
}

export function exportParams(result: AlgorithmResult) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Main/Results/ExportSimulationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export default function ExportSimulationDialog({ showModal, toggleShowModal, res
</td>
</tr>
<tr>
<td>covid.results.deterministic.csv</td>
<td>covid.results.deterministic.tsv</td>
<td>{t('The deterministic results of the simulation')}</td>
<td>CSV</td>
<td>TSV</td>
<td>
<Button
disabled={!(result?.deterministic ?? null)}
Expand Down

1 comment on commit 21d9672

@vercel
Copy link

@vercel vercel bot commented on 21d9672 Mar 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.