Skip to content

Commit

Permalink
feat: optimize
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Nov 29, 2023
1 parent 2be2bb4 commit 13b799b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions server/parsers/visualization_card_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { IMessage, Interaction } from '../../common/types/chat_saved_object_attributes';
import { getJsonFromString } from '../utils/csv-parser-helper';

const extractNthColumn = async (csv: string, column: number) => {
const extractIdsFromCsvString = async (csv: string) => {
const lines = (await getJsonFromString(csv)) as Array<{ Id: string }>;
return lines
.map((line) => line.Id)
Expand All @@ -16,16 +16,15 @@ const extractNthColumn = async (csv: string, column: number) => {
export const VisualizationCardParser = {
id: 'core_visualization',
async parserProvider(interaction: Interaction) {
const additionalInfo = interaction.additional_info as {
'VisualizationTool.output': string[];
} | null;
const visualizationOutputs = additionalInfo?.['VisualizationTool.output'];
const visualizationOutputs = interaction.additional_info?.['VisualizationTool.output'] as
| string[]
| undefined;
if (!visualizationOutputs) {
return [];
}
const visualizationIds = (
await Promise.all(visualizationOutputs.map((output) => extractNthColumn(output, 1)))
).flatMap((id) => id); // second column is id field
await Promise.all(visualizationOutputs.map((output) => extractIdsFromCsvString(output)))
).flatMap((id) => id);

const visOutputs: IMessage[] = visualizationIds
/**
Expand Down

0 comments on commit 13b799b

Please sign in to comment.