MCPcopy
hub / github.com/microsoft/SandDance / loadDataArray

Function loadDataArray

packages/sanddance-explorer/src/dataLoader.ts:52–91  ·  view source on GitHub ↗
(data: object[], type: DataFileType)

Source from the content-addressed store, hash-verified

50});
51
52export const loadDataArray = (data: object[], type: DataFileType) => new Promise<DataContent>((resolve, reject) => {
53 const parse = type === 'csv' || type === 'tsv';
54 if (parse) {
55 //convert empty strings to null so that vega.inferType will get dates
56 data.forEach(row => {
57 for (const column in row) {
58 if (row[column] === '') {
59 row[column] = null;
60 }
61 }
62 });
63 }
64 const columns = SandDance.util.
65 getColumnsFromData(SandDance.VegaDeckGl.base.vega.inferTypes, data)
66 .filter(c => c.name && c.name.trim())
67 .sort((a, b) => a.name.localeCompare(b.name));
68 if (parse) {
69 const booleanColumns = columns.filter(c => c.type === 'boolean');
70 const dateColumns = columns.filter(c => c.type === 'date');
71 const numericColumns = columns.filter(c => c.type === 'integer' || c.type === 'number');
72 data.forEach(obj => {
73 booleanColumns.forEach(c => {
74 obj[c.name] = ('' + obj[c.name]).toLowerCase() === 'true';
75 });
76 dateColumns.forEach(c => {
77 const input = obj[c.name];
78 if (input !== null) {
79 const d = new Date(input) as DateWithSource;
80 d.input = input;
81 obj[c.name] = d;
82 }
83 });
84 numericColumns.forEach(c => {
85 const n = parseFloat(obj[c.name]);
86 obj[c.name] = isNaN(n) ? null : n;
87 });
88 });
89 }
90 resolve({ data, columns });
91});

Callers 2

loadMethod · 0.90
handleRawTextFunction · 0.70

Calls 3

resolveFunction · 0.50
forEachMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected