Skip to content

Commit 80e2590

Browse files
committed
Update record parsing logic to handle missing field when generating the csv
1 parent dccae3d commit 80e2590

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Frontend/ui-library/src/UI/SessionTest.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ type StatsIds =
5353
type AggregatedStatsKeys = Exclude<keyof typeof AggregatedStats, 'prototype'>;
5454
type AggregatedStatsIds = (typeof AggregatedStats)[AggregatedStatsKeys];
5555

56-
type TempIds = AggregatedStatsIds | StatsIds;
57-
58-
type ElementType<T extends Iterable<any>> = T extends Iterable<infer E> ? E : never;
56+
type AllIds = AggregatedStatsIds | StatsIds;
5957
/**
6058
* Session test UI elements and results handling.
6159
*/
@@ -103,7 +101,7 @@ export class SessionTest {
103101
'How long the test runs for (seconds)',
104102
0 /*min*/,
105103
3600 /*max*/,
106-
1 /*default*/,
104+
60 /*default*/,
107105
false
108106
);
109107
const testTimeFrameSetting = new SettingUINumber(this._testTimeFrameSetting);
@@ -148,7 +146,6 @@ export class SessionTest {
148146
Logger.Warning(`Finished session test`);
149147

150148
const csvHeader: string[] = [];
151-
let csvBody = '';
152149

153150
this.records.forEach((record) => {
154151
for (const i in record) {
@@ -161,8 +158,6 @@ export class SessionTest {
161158
if (csvHeader.indexOf(`${i}.${j}.${k}`) === -1) {
162159
csvHeader.push(`${i}.${j}.${k}`);
163160
}
164-
165-
csvBody += `"${arrayVal[k]}",`;
166161
}
167162
}
168163
} else if (obj instanceof Map) {
@@ -172,21 +167,28 @@ export class SessionTest {
172167
if (csvHeader.indexOf(`${i}.${j}.${k}`) === -1) {
173168
csvHeader.push(`${i}.${j}.${k}`);
174169
}
175-
176-
csvBody += `"${mapVal[k]}",`;
177170
}
178171
}
179172
} else {
180173
for (const j in obj) {
181174
if (csvHeader.indexOf(`${i}.${j}`) === -1) {
182175
csvHeader.push(`${i}.${j}`);
183176
}
184-
185-
csvBody += `"${obj[j as StatsIds]}",`;
186177
}
187178
}
188179
}
189-
csvBody += '\n';
180+
});
181+
182+
let csvBody = '';
183+
this.records.forEach((record) =>{
184+
csvHeader.forEach((field) => {
185+
try {
186+
csvBody += `"${field.split('.').reduce((o, k) => o[k as AllIds], record)}",`;
187+
} catch (_) {
188+
csvBody += `"",`;
189+
}
190+
});
191+
csvBody += `\n`;
190192
});
191193

192194
const file = new Blob([`${csvHeader.join(',')}\n${csvBody}`], { type: 'text/plain' });

0 commit comments

Comments
 (0)