diff options
author | Sonja Galovic <galovicsonja@gmail.com> | 2022-03-08 23:38:40 +0100 |
---|---|---|
committer | Sonja Galovic <galovicsonja@gmail.com> | 2022-03-08 23:38:40 +0100 |
commit | 04b1d70fb48093608cc8084fff82cb319fa0becd (patch) | |
tree | 652bca069ce5fbc97dc061db3c0709c3edd832c0 /frontend/src/app/_elements/dataset-load/dataset-load.component.ts | |
parent | 3b9e1089b94799ee0c82fb68c71688566ab903c6 (diff) |
Komponenta za ucitavanje i prikaz csv fajla - v1 (probna)
Diffstat (limited to 'frontend/src/app/_elements/dataset-load/dataset-load.component.ts')
-rw-r--r-- | frontend/src/app/_elements/dataset-load/dataset-load.component.ts | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/frontend/src/app/_elements/dataset-load/dataset-load.component.ts b/frontend/src/app/_elements/dataset-load/dataset-load.component.ts new file mode 100644 index 00000000..d97e7cbe --- /dev/null +++ b/frontend/src/app/_elements/dataset-load/dataset-load.component.ts @@ -0,0 +1,82 @@ +import { Component, OnInit, ViewChild } from '@angular/core'; + +@Component({ + selector: 'app-dataset-load', + templateUrl: './dataset-load.component.html', + styleUrls: ['./dataset-load.component.css'] +}) +export class DatasetLoadComponent { + + //array varibales to store csv data + lines : any[] = []; //for headings + linesR : any[] = []; // for rows + +/* + const csv = require('csv-parser') + const fs = require('fs') + const res : string[] = []; + + fs.createReadStream('https://raw.githubusercontent.com/sharmaroshan/Churn-Modelling-Dataset/master/Churn_Modelling.csv') + .pipe(csv()) + .on('data', (data : string) => res.push(data)) + .on('end', () => { + console.log(res); + +*/ + + changeListener(files: FileList) { + + console.log(files); + + if(files && files.length > 0) { + + let file: File | null = files.item(0); + if (file == null) + return; + + if (file) { + console.log(file.name); + console.log(file.size); + console.log(file.type); + //File reader method + let reader: FileReader = new FileReader(); + reader.readAsText(file); + reader.onload = (e) => { + let csv: any = reader.result; + let allTextLines = []; + allTextLines = csv.split(/\r|\n|\r/); + + //Table Headings + let headers = allTextLines[0].split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/); + let data = headers; + let tarr = []; + for (let j = 0; j < headers.length; j++) { + tarr.push(data[j]); + } + //Pusd headings to array variable + this.lines.push(tarr); + //console.log(this.lines); + + + // Table Rows + let tarrR : string[] = []; + + let arrl = allTextLines.length; + let rows = []; + for(let i = 1; i < arrl; i++){ + rows.push(allTextLines[i].split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/)); + + } + + for (let j = 0; j < arrl; j++) { + tarrR.push(rows[j]); + } + //Push rows to array variable + this.linesR.push(tarrR); + console.log(this.linesR); + } + } + } + } + +} |