AnalysisSystemForRadionucli.../src/utils/phdHelper.js

117 lines
2.4 KiB
JavaScript
Raw Normal View History

export class PHDParser {
/**
* 数据类型
*/
dataType = ''
/**
* 类型 B G
*/
fileType = ''
/**
* 质量 FULL
*/
qualify = ''
/**
* 生存时间
*/
liveTime = ''
/**
* sample 谱的文件名
*/
sampleFilePrefix = ''
/**
* 其他文件名
*/
otherFilePrefixes = []
/**
* 构造函数
* @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) {
const filePrefixes = this.getFilePrefixes(fileNameLine)
this.sampleFilePrefix = filePrefixes.splice(0, 1)[0]
this.otherFilePrefixes = filePrefixes
}
}
}
/**
* 将文本按行分割
* @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
*/
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 + '_'
})
return filePrefixes
}
}
/**
* PHD 类型
*/
export const PHD_DATA_TYPE = {
QCPHD: 'QCPHD',
DETBKPHD: 'DETBKPHD',
SAMPLEPHD: 'SAMPLEPHD',
GASBKPHD: 'GASBKPHD'
}