2023-10-07 19:12:42 +08:00
|
|
|
export class PHDParser {
|
|
|
|
|
/**
|
|
|
|
|
* 数据类型
|
|
|
|
|
*/
|
|
|
|
|
dataType = ''
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 类型 B G 等
|
|
|
|
|
*/
|
|
|
|
|
fileType = ''
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 质量 FULL 等
|
|
|
|
|
*/
|
|
|
|
|
qualify = ''
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生存时间
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
liveTime = ''
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* sample 谱的文件名
|
|
|
|
|
*/
|
2023-10-08 17:41:37 +08:00
|
|
|
sampleFilePrefix = ''
|
2023-10-07 19:12:42 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 其他文件名
|
|
|
|
|
*/
|
2023-10-08 17:41:37 +08:00
|
|
|
otherFilePrefixes = []
|
2023-10-07 19:12:42 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造函数
|
|
|
|
|
* @param {string} text
|
|
|
|
|
*/
|
|
|
|
|
constructor(text) {
|
|
|
|
|
const getLine = this.readTextLine(text)
|
|
|
|
|
const dataTypeLine = getLine(4)
|
|
|
|
|
const fileTypeLine = getLine(6)
|
|
|
|
|
const fileNameLine = getLine(8)
|
|
|
|
|
const liveTimeLine = getLine(18)
|
|
|
|
|
|
|
|
|
|
this.dataType = this.getOnymousData(dataTypeLine)[0]
|
|
|
|
|
const fileType = this.splitLineText(fileTypeLine)
|
|
|
|
|
this.fileType = fileType[2]
|
|
|
|
|
this.qualify = fileType[4]
|
|
|
|
|
|
|
|
|
|
const liveTime = parseFloat(this.splitLineText(liveTimeLine)[3]).toFixed(1)
|
|
|
|
|
this.liveTime = liveTime.indexOf('.0') == -1 ? liveTime : liveTime.slice(0, -2)
|
|
|
|
|
|
|
|
|
|
// 如果是 Beta 谱
|
|
|
|
|
if (this.fileType == 'B') {
|
|
|
|
|
// 如果解析的是sample 文件,则获取其他三个文件
|
|
|
|
|
if (this.dataType == PHD_DATA_TYPE.SAMPLEPHD) {
|
2023-10-08 17:41:37 +08:00
|
|
|
const filePrefixes = this.getFilePrefixes(fileNameLine)
|
|
|
|
|
this.sampleFilePrefix = filePrefixes.splice(0, 1)[0]
|
|
|
|
|
this.otherFilePrefixes = filePrefixes
|
2023-10-07 19:12:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 将文本按行分割
|
|
|
|
|
* @param {string} text
|
|
|
|
|
* @returns { (line: number) => string }
|
|
|
|
|
*/
|
|
|
|
|
readTextLine(text) {
|
|
|
|
|
const splited = text.split('\n')
|
|
|
|
|
return line => {
|
|
|
|
|
return splited[line - 1]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取 具名 行的数据
|
|
|
|
|
* @param {string} text
|
|
|
|
|
* @example DATA_TYPE SAMPLEPHD 返回['SAMPLEPHD']
|
|
|
|
|
* @returns {string[]}
|
|
|
|
|
*/
|
|
|
|
|
getOnymousData(text) {
|
|
|
|
|
return text.split(' ').slice(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将一行中的文本按空格切割
|
|
|
|
|
* @param {string} text
|
|
|
|
|
*/
|
|
|
|
|
splitLineText(text) {
|
|
|
|
|
return text.replace(/\s+/g, ',').split(',')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取全部文件名
|
|
|
|
|
* @param {string} text
|
|
|
|
|
*/
|
2023-10-08 17:41:37 +08:00
|
|
|
getFilePrefixes(text) {
|
|
|
|
|
const unHandledfilePrefixes = this.splitLineText(text)
|
|
|
|
|
const filePrefixes = unHandledfilePrefixes
|
|
|
|
|
.filter(filePrefix => filePrefix)
|
|
|
|
|
.map(filePrefix => {
|
|
|
|
|
filePrefix = filePrefix.replace(/(\d{4})\/(\d{2})\/(\d{2})-(\d{2}):(\d{2})/, '$1$2$3_$4$5')
|
|
|
|
|
return filePrefix + '_'
|
2023-10-07 19:12:42 +08:00
|
|
|
})
|
2023-10-08 17:41:37 +08:00
|
|
|
return filePrefixes
|
2023-10-07 19:12:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* PHD 类型
|
|
|
|
|
*/
|
|
|
|
|
export const PHD_DATA_TYPE = {
|
|
|
|
|
QCPHD: 'QCPHD',
|
|
|
|
|
DETBKPHD: 'DETBKPHD',
|
|
|
|
|
SAMPLEPHD: 'SAMPLEPHD',
|
|
|
|
|
GASBKPHD: 'GASBKPHD'
|
|
|
|
|
}
|