Skip to content
Snippets Groups Projects
Commit b70f3d17 authored by Leonardo's avatar Leonardo
Browse files

feat: vis1D in insight email

parent 20306f9e
No related branches found
Tags v1.15.0
No related merge requests found
Pipeline #143613 failed
import { RabbitMqBroker } from "ts-common";
import { populateTemplate, RabbitMqBroker } from "ts-common";
import { rabbitMq, ums, mail, SMTP_USER, DEBUG_EMAIL } from "../variables";
import { log } from "../logger";
import type { InsightModel } from "ts-common";
import { populateTemplate, VariableNode } from "../utils/lexical";
import { createHeadlessEditor } from "@lexical/headless";
import { $generateHtmlFromNodes } from "@lexical/html";
import { JSDOM } from "jsdom";
......@@ -11,6 +10,7 @@ import { query2Cypher } from "../utils/cypher/converter";
import { queryService } from "./queryService";
import { statCheck } from "./statCheck";
import { diffCheck } from "./diffCheck";
import { VariableNode } from "../utils/lexical";
const dom = new JSDOM();
function setUpDom() {
......
import { Record, Node, Relationship, Path, PathSegment, isRelationship, isNode, isPath, isPathSegment, Integer, isUnboundRelationship } from 'neo4j-driver';
import { Record, Node, Relationship, Path, PathSegment, isRelationship, isNode, isPath, isPathSegment, Integer, isUnboundRelationship, type RecordShape } from 'neo4j-driver';
import { log } from '../../logger';
import type { EdgeQueryResult, NodeQueryResult } from 'ts-common';
import type { GraphQueryResultFromBackend } from 'ts-common';
export function parseCypherQuery(result: Record[], returnType: "nodelink" | "table" = "nodelink"): GraphQueryResultFromBackend {
export function parseCypherQuery(result: RecordShape[], returnType: "nodelink" | "table" = "nodelink"): GraphQueryResultFromBackend {
try {
try {
switch (returnType) {
......@@ -28,7 +28,7 @@ export function parseCypherQuery(result: Record[], returnType: "nodelink" | "tab
throw err;
}
}
function parseNodeLinkQuery(results: Record[]): GraphQueryResultFromBackend {
function parseNodeLinkQuery(results: RecordShape[]): GraphQueryResultFromBackend {
let nodes: NodeQueryResult[] = [];
let edges: EdgeQueryResult[] = [];
let nodeIds: Set<string> = new Set();
......
......@@ -90,27 +90,3 @@ export class VariableNode extends DecoratorNode<HTMLElement> {
return self.createDOM({ namespace: '', theme: {} });
}
}
async function replaceAllAsync(string: string, regexp: RegExp, replacerFunction: CallableFunction) {
const replacements = await Promise.all(Array.from(string.matchAll(regexp), (match) => replacerFunction(...match)));
let i = 0;
return string.replace(regexp, () => replacements[i++]);
}
export async function populateTemplate(html: string, result: GraphQueryResultMetaFromBackend, openVisualizationArray: any[]) {
const regex = /\ *?{\{\ *?(\w*?):([\w ]*?)\ *?\}\}\ *?/gm;
return replaceAllAsync(html, regex, async (_: string, _type: string, name: string) => {
const type = VariableType[_type as keyof typeof VariableType];
switch (type) {
case VariableType.statistic:
const [nodeType, feature, statistic] = name.split(' ');
const node = result.metaData.nodes.types[nodeType];
const attribute = node?.attributes[feature].statistics as any;
if (attribute == null) return '';
const value = attribute[statistic];
return ` ${value} `;
}
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment