receptionDetail.qualityTransform.uts
3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* 将网关 findCheckResultListByReceptionId / findCheckResultByBatchId 返回的质检行
* 加工为 ReceptionQualityAnalysis / DetailData 所需字段(与功能清单第六节对齐)。
*/
import { formatMmSs, getNum, parseStringArray } from "./lists/reception-detail-helpers.uts";
function formatPlainText(s: string): string {
return s.replace(/\r\n/g, "\n").replace(/\n/g, " ").trim();
}
function firstScriptRecLine(raw: any | null): string {
const lines = parseStringArray(raw);
if (lines.length > 0) {
return formatPlainText(lines[0]);
}
return "";
}
/**
* 单条质检维度加工:formatScore、命中意图、话术首行、对话行 time/text_id、话术挂载
*/
export function transformSingleQualityRow(row: UTSJSONObject): UTSJSONObject {
const out = {} as UTSJSONObject;
for (const k in row) {
out[k] = row[k];
}
const scoreRaw = out["score"];
const sumRaw = out["sumScore"];
if (scoreRaw != null && sumRaw != null) {
out["formatScore"] = `${scoreRaw}/${sumRaw}`;
} else {
const fs = out["formatScore"] as string | null;
if (fs == null || fs.trim() == "") {
out["formatScore"] = "-";
}
}
const hitTextList = parseStringArray(out["hitText"]);
if (hitTextList.length > 0) {
out["matchedClass"] = "hit";
out["matchedText"] = "意图匹配";
} else {
out["matchedClass"] = "";
out["matchedText"] = "意图不匹配";
}
const scriptLine = firstScriptRecLine(out["scriptRec"]);
let list: UTSJSONObject[] = [];
const listRaw = out["conversationDetailDTOList"];
if (listRaw != null && listRaw instanceof Array) {
list = listRaw as UTSJSONObject[];
}
const itemOffset = getNum(out, "offset");
let i = 0;
while (i < list.length) {
const line = list[i];
const mo = getNum(line, "mergedOffset");
if (mo != null && mo >= 0) {
const sec = Math.floor(mo);
line["time"] = formatMmSs(sec);
line["text_id"] = `text_${Math.ceil(mo)}`;
}
i++;
}
if (scriptLine != "") {
let attached = false;
let j = 0;
while (j < list.length) {
const line = list[j];
const mo = getNum(line, "mergedOffset");
if (itemOffset != null && mo != null) {
const offSec = itemOffset > 1000 ? itemOffset / 1000.0 : itemOffset;
if (Math.abs(mo - offSec) < 0.001) {
line["scriptRec"] = scriptLine;
attached = true;
break;
}
}
j++;
}
if (!attached && list.length > 0) {
const last = list[list.length - 1];
last["scriptRec"] = scriptLine;
}
out["scriptRec"] = scriptLine;
}
if (list.length == 0) {
const stub = {} as UTSJSONObject;
stub["scriptRec"] = scriptLine != "" ? scriptLine : "暂无话术推荐";
list = [stub];
}
out["conversationDetailDTOList"] = list;
return out;
}
export function transformQualityCheckRows(rawRows: UTSJSONObject[]): UTSJSONObject[] {
const out: UTSJSONObject[] = [];
let i = 0;
while (i < rawRows.length) {
out.push(transformSingleQualityRow(rawRows[i]));
i++;
}
return out;
}