Commit a014e1d3 by Lin Wang

fix: change the diff fields name

parent 0b0147cd
......@@ -19,6 +19,27 @@ export const section_selectors = [
"27656391"
]
export const sectionSelectorLanguages: Record<string, string> = {
"27328697": "EN",
"27328389": "DE",
"27328392": "ES",
"27328396": "PT",
"27328399": "FR",
"27328401": "IT",
"27328404": "JP",
"27328406": "ID",
"27328408": "NL",
"27328410": "FI",
"27328412": "SV",
"27328414": "CS",
"27328415": "RO",
"27328416": "CN_ZH",
"27328417": "CN_TW",
"27328419": "AR",
"27665235": "NO",
"27656391": "PL"
}
export const ai_section_selectors = [
"29279960",
"29286540",
......@@ -39,3 +60,24 @@ export const ai_section_selectors = [
"29278297",
"29279930"
]
export const aiSectionSelectorsLanguages: Record<string, string> = {
"29279960": "EN",
"29286540": "DE",
"29286613": "ES",
"29286646": "PT",
"29278357": "FR",
"29286780": "IT",
"29278350": "JP",
"29286835": "ID",
"29286857": "NL",
"29279949": "FI",
"29278331": "SV",
"29278319": "CS",
"29278287": "RO",
"29278284": "CN_ZH",
"29278371": "CN_TW",
"29279914": "AR",
"29278297": "NO",
"29279930": "PL"
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
import { diff } from 'deep-diff';
import { readFileSync, writeFileSync, mkdirSync, rmSync } from 'fs';
import { join } from 'path';
import { section_selectors, ai_section_selectors } from '../constant/section_selectors';
import { section_selectors, sectionSelectorLanguages, ai_section_selectors, aiSectionSelectorsLanguages } from '../constant/section_selectors';
// Directory containing JSON outputs to compare
const srcDir = 'src/detect_section_selector_masters/extractOutput';
......@@ -18,11 +18,12 @@ mkdirSync(outDir, { recursive: true });
const useAiSelectors = process.env.USE_AI_SELECTORS === 'true';
// 根据环境变量选择使用哪个 selector 数组
const selectedSelectors = useAiSelectors ? ai_section_selectors : section_selectors;
const selectedLanguages = useAiSelectors ? aiSectionSelectorsLanguages : sectionSelectorLanguages;
// Baseline section ID (override via BASELINE_ID env variable)
const EN_SITE_ID = 27328697;
const AI_EN_SITE_ID = 29279960;
const baselineId = useAiSelectors ? AI_EN_SITE_ID : EN_SITE_ID ;
const baselineId = useAiSelectors ? AI_EN_SITE_ID : EN_SITE_ID;
const baselineFile = `${baselineId}_extract.json`;
// Read baseline data
......@@ -48,14 +49,14 @@ selectedSelectors
if (typeof first === 'number') {
const pageA = baselineData[first] || {};
const pageB = otherData[first] || {};
context.baselineData = { pageUid: pageA.pageUid, pageTitle: pageA.pageTitle, sectionIndex: pageA.sectionIndex };
context.testData = { pageUid: pageB.pageUid, pageTitle: pageB.pageTitle, sectionIndex: pageB.sectionIndex };
context[selectedLanguages[baselineId]] = { pageUid: pageA.pageUid, pageTitle: pageA.pageTitle, sectionIndex: pageA.sectionIndex };
context[selectedLanguages[otherId]] = { pageUid: pageB.pageUid, pageTitle: pageB.pageTitle, sectionIndex: pageB.sectionIndex };
const idx = change.path.indexOf('result');
if (idx !== -1) {
const itemIdx = change.path[idx + 1];
if (typeof itemIdx === 'number') {
context.baselineData.id = pageA.result?.[itemIdx]?.id;
context.testData.id = pageB.result?.[itemIdx]?.id;
context[selectedLanguages[baselineId]].id = pageA.result?.[itemIdx]?.id;
context[selectedLanguages[otherId]].id = pageB.result?.[itemIdx]?.id;
}
}
}
......@@ -64,15 +65,30 @@ selectedSelectors
// Convert to semantic format
const semantic = annotated.map(change => {
const map: Record<string, string> = { E: 'modified', N: 'added', D: 'deleted', A: 'arrayChange' };
const map: Record<string, string> = { E: '修改', N: '新增', D: '删除', A: '数组类型的变更' };
const type = map[change.kind] || change.kind;
const pathStr = (change.path || []).map(seg => typeof seg === 'number' ? `[${seg}]` : seg).join('.');
let oldV: any, newV: any;
if (change.kind === 'E') { oldV = (change as any).lhs; newV = (change as any).rhs; }
else if (change.kind === 'N') { newV = (change as any).rhs; }
else if (change.kind === 'D') { oldV = (change as any).lhs; }
else if (change.kind === 'A') { oldV = (change as any).item.lhs; newV = (change as any).item.rhs; }
return { changeType: type, path: pathStr, oldValue: oldV, newValue: newV, context: change.context };
if (change.kind === 'E') {
oldV = (change as any).lhs;
newV = (change as any).rhs;
} else if (change.kind === 'N') {
oldV = (change as any).lhs;
newV = (change as any).rhs;
} else if (change.kind === 'D') {
oldV = (change as any).lhs;
newV = (change as any).rhs;
} else if (change.kind === 'A') {
oldV = (change as any).item.lhs;
newV = (change as any).item.rhs;
}
return {
"更改类型": type,
"问题类型": pathStr,
[`${selectedLanguages[baselineId]}模版值`]: oldV,
[`${selectedLanguages[otherId]}模版值`]: newV,
context: change.context
};
});
const outFile = `${baselineId}_vs_${otherId}_diff.json`;
......
......@@ -25,11 +25,11 @@ const DETECT_ONLY = commandMode === 'detect';
function handleFullDiffNode(node: any, path: string[], output: any) {
// 检查当前节点是否为 RichText
if (node.type === "RichText") {
const getInlineColors = extractInlineColors(node.value);
const getInlineColors = extractInlineColors(node.value).join(',');
output.result.push({
type: "RichText",
path: path.join('.'),
inlineColors: getInlineColors,
RichText_type: "RichText",
RichText_path: path.join('.'),
RichText_color: getInlineColors,
id: node.id || null
});
}
......@@ -40,10 +40,10 @@ function handleFullDiffNode(node: any, path: string[], output: any) {
const items = node.components.block1?.items || [];
items.filter((btn: any) => btn.type === "Button").forEach((btn: any) => {
output.result.push({
type: "Button",
path: path.join('.'),
color: btn.color,
backgroundSettings: btn.backgroundSettings || {},
Button_type: "Button",
Button_path: path.join('.'),
Button_color: btn.color,
Button_backgroundSettings: btn.backgroundSettings || {},
id: btn.id || null
});
});
......@@ -52,24 +52,24 @@ function handleFullDiffNode(node: any, path: string[], output: any) {
// 检查当前节点是否为 Button
if (node.type === "Button") {
output.result.push({
type: "Button",
path: path.join('.'),
color: node.color,
backgroundSettings: node.backgroundSettings || {},
Button_type: "Button",
Button_path: path.join('.'),
Button_color: node.color,
Button_backgroundSettings: node.backgroundSettings || {},
id: node.id || null
});
}
if (node.type === "SlideSettings" && node.layout_config?.hasOwnProperty("card")) {
output.result.push({
type: 'SlideSettings.layout_config.card',
path: path.join('.'),
card: node.layout_config.card,
card_color: node.layout_config.card_color,
border: node.layout_config.border,
border_color: node.layout_config.border_color,
cardBackgroundSettings: node.layout_config.cardBackgroundSettings || {},
borderBackgroundSettings: node.layout_config.borderBackgroundSettings || {},
featureList_type: 'SlideSettings.layout_config.card',
featureList_path: path.join('.'),
featureList_card: node.layout_config.card,
featureList_card_color: node.layout_config.card_color,
featureList_border: node.layout_config.border,
featureList_border_color: node.layout_config.border_color,
featureList_cardBackgroundSettings: node.layout_config.cardBackgroundSettings || {},
featureList_borderBackgroundSettings: node.layout_config.borderBackgroundSettings || {},
id: node.id || null,
})
}
......@@ -80,26 +80,26 @@ function handleFullDiffNode(node: any, path: string[], output: any) {
const useVideo = node.videoHtml
if (useImage) {
output.result.push({
type: "Background.textColor",
textColor: node.textColor || '',
path: path.join("."),
Background_textColor_type: "Background.textColor",
Background_textColor: node.textColor || '',
Background_textColor_path: path.join("."),
id: node.id || null,
note: "The background is image",
Background_textColor_note: "The background is image",
})
} else if (useVideo) {
output.result.push({
type: "Background.videoHtml",
path: path.join("."),
Background_video_type: "Background.videoHtml",
Background_video_path: path.join("."),
id: node.id || null,
note: "The background is video",
Background_video_note: "The background is video",
})
} else {
output.result.push({
type: "BackgroundColor",
backgroundColor: node.backgroundColor?.value || '',
path: path.join("."),
Background_color_type: "BackgroundColor",
Background_color: node.backgroundColor?.value || '',
Background_color_path: path.join("."),
id: node.id || null,
note: "The background is background color",
Background_color_note: "The background is background color",
})
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment