2
Fork 0

Add timestamps to export file names

This commit is contained in:
Kai S. K. Engelbart 2021-01-25 10:31:18 +01:00
parent 41060a0436
commit efd4e3f5e9
1 changed files with 9 additions and 3 deletions

View File

@ -138,16 +138,22 @@ export class PredictionComponent implements OnInit {
return zip(this.spectrumNames, values);
}
// Generates a timestamp suitable for file naming
generateTimestamp() {
let d = new Date();
return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + '--' + d.getHours() + "-" + d.getMinutes();
}
// Converts the prediction results to a CSV file
exportCSV() {
const predictions = this.prepareExport();
const csv = predictions.map(line => line.join(";")).join("\n");
FileSaver.saveAs(new Blob([csv], { type: 'text/csv;charset=utf-8' }), "predictions.csv");
FileSaver.saveAs(new Blob([csv], { type: 'text/csv;charset=utf-8' }), 'predictions-' + this.generateTimestamp() + '.csv');
}
// Converts the prediction results to a PDF file
exportPDF() {
const dd = {
const doc = {
content: [
{
text: 'DeFinMa - Decoding the Fingerprint of Materials by AI',
@ -270,6 +276,6 @@ export class PredictionComponent implements OnInit {
pageMargins: [50, 50, 50, 15]
};
pdfMake.createPdf(dd).download();
pdfMake.createPdf(doc).download('predictions-' + this.generateTimestamp() + '.pdf');
}
}