Skip to content

Commit b421716

Browse files
committed
feat: add create long rows function
1 parent 883f178 commit b421716

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

apps/web/src/hooks/useInstrumentVisualization.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,39 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
8383
});
8484
};
8585

86+
const makeLongRows = () => {
87+
let date: Date;
88+
const longRecord: object[] = [];
89+
return exportRecords.map((item) => {
90+
for (const [objKey, objVal] of Object.entries(item)) {
91+
if (objKey === '__date__') {
92+
date = objVal as Date;
93+
continue;
94+
}
95+
if (Array.isArray(objVal)) {
96+
objVal.map((arrayItem) => {
97+
for (const [arrKey, arrItem] of Object.entries(arrayItem as object)) {
98+
longRecord.push({
99+
Date: date.toISOString(),
100+
SubjectID: params.subjectId,
101+
Value: arrItem as string,
102+
Variable: objKey + '-' + arrKey
103+
});
104+
}
105+
});
106+
continue;
107+
}
108+
longRecord.push({
109+
Date: date.toISOString(),
110+
SubjectID: params.subjectId,
111+
Value: objVal,
112+
Variable: objKey
113+
});
114+
}
115+
return longRecord;
116+
});
117+
};
118+
86119
switch (option) {
87120
case 'CSV':
88121
void download(`${baseFilename}.csv`, () => {
@@ -100,8 +133,11 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
100133
return csv;
101134
});
102135
break;
103-
case 'CSV Long':
136+
case 'CSV Long': {
137+
const rows = makeLongRows();
138+
console.log(rows);
104139
break;
140+
}
105141
case 'JSON': {
106142
exportRecords.map((item) => {
107143
item.subjectID = params.subjectId;

0 commit comments

Comments
 (0)