fix(analysis): 统一方案名与接口错误提示
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
export const SCHEME_NAME_PREFIXES = {
|
||||
dmaLeakIdentification: "dma_leak",
|
||||
flushingAnalysis: "flush",
|
||||
burstDetection: "burst_detect",
|
||||
burstAnalysis: "burst_sim",
|
||||
burstLocation: "burst_locate",
|
||||
contaminantAnalysis: "water_quality",
|
||||
sensorPlacement: "sensor_place",
|
||||
} as const;
|
||||
|
||||
export type SchemeNamePrefix =
|
||||
(typeof SCHEME_NAME_PREFIXES)[keyof typeof SCHEME_NAME_PREFIXES];
|
||||
|
||||
export const SCHEME_NAME_MAX_LENGTH = 32;
|
||||
|
||||
export const normalizeSchemeName = (value: string) =>
|
||||
value
|
||||
.normalize("NFC")
|
||||
.replace(/\p{Default_Ignorable_Code_Point}/gu, "")
|
||||
.trim();
|
||||
|
||||
export const isSchemeNameValid = (value: string) => {
|
||||
const normalized = normalizeSchemeName(value);
|
||||
return normalized.length > 0 && normalized.length <= SCHEME_NAME_MAX_LENGTH;
|
||||
};
|
||||
|
||||
const padNumber = (value: number, length = 2) =>
|
||||
String(value).padStart(length, "0");
|
||||
|
||||
export const createSchemeName = (
|
||||
prefix: SchemeNamePrefix,
|
||||
date = new Date(),
|
||||
) => {
|
||||
const timestamp = [
|
||||
padNumber(date.getFullYear() % 100),
|
||||
padNumber(date.getMonth() + 1),
|
||||
padNumber(date.getDate()),
|
||||
].join("");
|
||||
const time = [
|
||||
padNumber(date.getHours()),
|
||||
padNumber(date.getMinutes()),
|
||||
padNumber(date.getSeconds()),
|
||||
padNumber(date.getMilliseconds(), 3),
|
||||
].join("");
|
||||
|
||||
return `${prefix}_${timestamp}_${time}`;
|
||||
};
|
||||
Reference in New Issue
Block a user