diff --git a/libs/shared/lib/data-access/api/eventBus.tsx b/libs/shared/lib/data-access/api/eventBus.tsx index 2d9b86d9205cd71d93fe3c0b43682b9d22f75835..da623966ee559403111ef1b33425c61dd10a7ed7 100644 --- a/libs/shared/lib/data-access/api/eventBus.tsx +++ b/libs/shared/lib/data-access/api/eventBus.tsx @@ -52,7 +52,7 @@ import { isEqual } from 'lodash-es'; import { addSchemaAttributeDimensions, addSchemaAttributeInformation } from '../store/schemaSlice'; import { addError } from '@graphpolaris/shared/lib/data-access/store/configSlice'; import { unSelect } from '../store/interactionSlice'; -import { GraphAttributeStats } from '../../schema'; +import { SchemaGraphStats } from '../../schema'; export const EventBus = (props: { onRunQuery: Function; onAuthorized: Function }) => { const { login } = useAuth(); @@ -113,7 +113,7 @@ export const EventBus = (props: { onRunQuery: Function; onAuthorized: Function } }), ); - Broker.instance().subscribe((data: GraphAttributeStats) => { + Broker.instance().subscribe((data: SchemaGraphStats) => { dispatch(addSchemaAttributeInformation(data)); dispatch(addInfo('Received attribute information')); }, 'schema_stats_result'); diff --git a/libs/shared/lib/data-access/store/schemaSlice.ts b/libs/shared/lib/data-access/store/schemaSlice.ts index b3d4d01f8b3f465c496b0550e6276f75213f9cdb..fd21442faa5849e5fd848c6a070f4e29ebecbe5a 100644 --- a/libs/shared/lib/data-access/store/schemaSlice.ts +++ b/libs/shared/lib/data-access/store/schemaSlice.ts @@ -2,7 +2,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import type { RootState } from './store'; import { AllLayoutAlgorithms, Layouts } from '@graphpolaris/shared/lib/graph-layout'; import { SchemaUtils } from '../../schema/schema-utils'; -import { GraphAttributeStats, SchemaFromBackend, SchemaGraph, SchemaGraphology } from '../../schema'; +import { DimensionType, SchemaGraphStats, SchemaFromBackend, SchemaGraph, SchemaGraphology, SchemaGraphInference } from '../../schema'; /**************************************************************** */ @@ -16,12 +16,22 @@ export type SchemaSettings = { type schemaSliceI = { graph: SchemaGraph; + graphInference: SchemaGraphInference; + graphStats: SchemaGraphStats; settings: SchemaSettings; }; // Define the initial state using that type export const initialState: schemaSliceI = { graph: new SchemaGraphology().export(), + graphInference: { + nodeInference: {}, + edgeInference: {}, + }, + graphStats: { + nodeStats: {}, + edgeStats: {}, + }, // layoutName: 'Cytoscape_fcose', settings: { connectionType: 'connection', @@ -49,12 +59,12 @@ export const schemaSlice = createSlice({ state.settings = action.payload; }, - addSchemaAttributeDimensions: (state, action: PayloadAction<any>) => { - state.graph = SchemaUtils.addAttributeDimensionsToGraph(state.graph, JSON.parse(action.payload)); + addSchemaAttributeDimensions: (state, action: PayloadAction<SchemaGraphInference>) => { + state.graphInference = action.payload; }, - addSchemaAttributeInformation: (state, action: PayloadAction<GraphAttributeStats>) => { - state.graph = SchemaUtils.addAttributeInfoToGraph(state.graph, action.payload); + addSchemaAttributeInformation: (state, action: PayloadAction<SchemaGraphStats>) => { + state.graphStats = action.payload; }, }, }); diff --git a/libs/shared/lib/schema/model/FromBackend.ts b/libs/shared/lib/schema/model/FromBackend.ts index 278c3f69f9ba4c1f512d99d94fe8463e7b9e6905..5158465e19fc402c7bc8baf3bf0be99f6064aea6 100644 --- a/libs/shared/lib/schema/model/FromBackend.ts +++ b/libs/shared/lib/schema/model/FromBackend.ts @@ -1,3 +1,4 @@ +import { type } from 'os'; /*************** schema format from the backend *************** */ /** Schema type, consist of nodes and edges */ @@ -37,16 +38,6 @@ export type DimensionType = 'categorical' | 'numerical' | 'temporal' | 'spatial' export type SchemaAttribute = { name: string; type: SchemaAttributeTypes; - dimension?: DimensionType; - uniqueCount?: number; - categoryCounts?: Record<string, number>; - minValue?: number | string; - maxValue?: number | string; - avgValue?: number; - stDevValue?: number; - firstDate?: string; - lastDate?: string; - [id: string]: any; }; /** Node type, consist of a name and a list of attributes */ @@ -56,43 +47,48 @@ export type SchemaNode = { type?: string; }; -export type GraphAttributeStats = { - nodeStats: Array<NodeOrEdgeStats>; - edgeStats: Array<NodeOrEdgeStats>; +export type SchemaGraphInference = { + nodeInference: Record<string, Record<string, DimensionType>>; // node key -> attribute label -> dimension + edgeInference: Record<string, Record<string, DimensionType>>; +}; + +export type SchemaGraphStats = { + nodeStats: Record<string, NodeOrEdgeStats>; // node key -> Stats + edgeStats: Record<string, NodeOrEdgeStats>; // edge key -> Stats }; export type NodeOrEdgeStats = { key: string; type?: string; count: number; - attributeStats: Array<AttributeStats>; + attributeStats: Array<SchemaAttributeStats>; }; -export type AttributeStats = - | BooleanAttributeStats - | StringAttributeStats - | NumberAttributeStats - | DateTimeAttributeStats - | LocationAttributeStats; +export type SchemaAttributeStats = + | BooleanSchemaAttributeStats + | StringSchemaAttributeStats + | NumberSchemaAttributeStats + | DateTimeSchemaAttributeStats + | LocationSchemaAttributeStats; -export type CommonAttributeStats = { +export type CommonSchemaAttributeStats = { name: string; type: string; }; -export type BooleanAttributeStats = CommonAttributeStats & { +export type BooleanSchemaAttributeStats = CommonSchemaAttributeStats & { type: 'boolean'; uniqueCount: number; categoryCounts?: Record<string, number>; }; -export type StringAttributeStats = CommonAttributeStats & { +export type StringSchemaAttributeStats = CommonSchemaAttributeStats & { type: 'string'; uniqueCount: number; categoryCounts?: Record<string, number>; }; -export type NumberAttributeStats = CommonAttributeStats & { +export type NumberSchemaAttributeStats = CommonSchemaAttributeStats & { type: 'number'; minValue: number; maxValue: number; @@ -100,13 +96,13 @@ export type NumberAttributeStats = CommonAttributeStats & { stDevValue: number; }; -export type DateTimeAttributeStats = CommonAttributeStats & { +export type DateTimeSchemaAttributeStats = CommonSchemaAttributeStats & { type: 'datetime'; firstDate: string; lastDate: string; }; -export type LocationAttributeStats = CommonAttributeStats & { +export type LocationSchemaAttributeStats = CommonSchemaAttributeStats & { type: 'location'; minValue: string; maxValue: string; diff --git a/libs/shared/lib/schema/schema-utils/schema-utils.ts b/libs/shared/lib/schema/schema-utils/schema-utils.ts index fc4b47be903bf4bf934859bd1e366cff18bb1daf..e6a632d0e05c5f702466890d0f1ba10c6fa0a881 100644 --- a/libs/shared/lib/schema/schema-utils/schema-utils.ts +++ b/libs/shared/lib/schema/schema-utils/schema-utils.ts @@ -1,7 +1,7 @@ import { DimensionType, GraphAttributeDimensions, - GraphAttributeStats, + SchemaGraphStats, SchemaFromBackend, SchemaGraph, SchemaGraphology, @@ -51,59 +51,59 @@ export class SchemaUtils { return schemaGraphology; } - public static addAttributeDimensionsToGraph(graph: SchemaGraph, inference: GraphAttributeDimensions): SchemaGraph { - const { nodes, edges } = inference; + // public static addAttributeDimensionsToGraph(graph: SchemaGraph, inference: GraphAttributeDimensions): SchemaGraph { + // const { nodes, edges } = inference; - graph.nodes.forEach((node) => { - const dimensions = nodes[node.key]; - if (dimensions) { - node.attributes?.attributes.forEach((attribute) => { - const dimension = dimensions[attribute.name] as DimensionType | undefined; - if (dimension) { - attribute.dimension = dimension; - } - }); - } - }); + // graph.nodes.forEach((node) => { + // const dimensions = nodes[node.key]; + // if (dimensions) { + // node.attributes?.attributes.forEach((attribute) => { + // const dimension = dimensions[attribute.name] as DimensionType | undefined; + // if (dimension) { + // attribute.dimension = dimension; + // } + // }); + // } + // }); - graph.edges.forEach((edge) => { - const dimensions = edges[edge.attributes?.name]; - if (dimensions) { - edge.attributes?.attributes.forEach((attribute: any) => { - const dimension = dimensions[attribute.name] as DimensionType | undefined; - if (dimension) { - attribute.dimension = dimension; - } - }); - } - }); + // graph.edges.forEach((edge) => { + // const dimensions = edges[edge.attributes?.name]; + // if (dimensions) { + // edge.attributes?.attributes.forEach((attribute: any) => { + // const dimension = dimensions[attribute.name] as DimensionType | undefined; + // if (dimension) { + // attribute.dimension = dimension; + // } + // }); + // } + // }); - return graph; - } + // return graph; + // } - public static addAttributeInfoToGraph(graph: SchemaGraph, graphStats: GraphAttributeStats): SchemaGraph { - const { nodeStats, edgeStats } = graphStats; + // public static addAttributeInfoToGraph(graph: SchemaGraph, graphStats: GraphAttributeStats): SchemaGraph { + // const { nodeStats, edgeStats } = graphStats; - graph.nodes.forEach((node) => { - const nodeStat = nodeStats.find((stat) => stat.key === node.key); - if (nodeStat && node.attributes?.attributes) { - node.attributes.attributes = node.attributes.attributes.map((attribute) => { - const attrStat = nodeStat.attributeStats.find((stat) => stat.name === attribute.name); - return attrStat ? { ...attribute, ...attrStat } : attribute; - }); - } - }); + // graph.nodes.forEach((node) => { + // const nodeStat = nodeStats.find((stat) => stat.key === node.key); + // if (nodeStat && node.attributes?.attributes) { + // node.attributes.attributes = node.attributes.attributes.map((attribute) => { + // const attrStat = nodeStat.attributeStats.find((stat) => stat.name === attribute.name); + // return attrStat ? { ...attribute, ...attrStat } : attribute; + // }); + // } + // }); - graph.edges.forEach((edge) => { - const edgeStat = edgeStats.find((stat) => stat.type === edge.attributes?.name); - if (edgeStat && edge.attributes?.attributes) { - edge.attributes.attributes = edge.attributes.attributes.map((attribute: any) => { - const attrStat = edgeStat.attributeStats.find((stat) => stat.name === attribute.name); - return attrStat ? { ...attribute, ...attrStat } : attribute; - }); - } - }); + // graph.edges.forEach((edge) => { + // const edgeStat = edgeStats.find((stat) => stat.type === edge.attributes?.name); + // if (edgeStat && edge.attributes?.attributes) { + // edge.attributes.attributes = edge.attributes.attributes.map((attribute: any) => { + // const attrStat = edgeStat.attributeStats.find((stat) => stat.name === attribute.name); + // return attrStat ? { ...attribute, ...attrStat } : attribute; + // }); + // } + // }); - return graph; - } + // return graph; + // } }