var parseCSV = function(data){ if (!$ || !$.csv){ console.log("The csv parser not be loaded!"); return; } return $.csv.toObjects(data); };
var parseTSV = function(data){ if (!$ || !$.csv){ console.log("The csv parser not be loaded!"); return; } return $.csv.toObjects(data, {separator:"\t"}); };
reader.onload = function (event) { var csv = event.target.result; var tableData = []; $.csv.toArrays(csv, scope.fileParams).forEach(function (row, ix) { // ensure we have 11 columns (Initial version of aggregate data csv file has 12 columns) if ((!scope.fileParams.headerRow || ix !== 0) && row.length >= 12) { tableData.push({ rowId: ix, year: row[0], week: row[1], visitDate: parseDate(row[2]), medicalFacility: { name: row[3], location: { district: row[3], country: row[3] }, sites: { total: !isNaN(row[5]) ? row[5] : undefined, reporting: !isNaN(row[6]) ? row[6] : undefined } }, createDate: parseDate(row[4]), acuteFever: !isNaN(row[7]) ? row[7] : undefined, diarrhoea: !isNaN(row[8]) ? row[8] : undefined, influenza: !isNaN(row[9]) ? row[9] : undefined, prolongedFever: !isNaN(row[10]) ? row[10] : undefined, dengue: !isNaN(row[11]) ? row[11] : undefined }); } }); scope.$apply(function () { scope.tableData = tableData; }); $rootScope.$emit('csvData', scope.tableData); };