Merge branch 'feature-analysis-RLR-renpy' of http://git.hivekion.com:3000/xiaoguangbin/AnalysisSystemForRadionuclide_vue into master-dev

This commit is contained in:
xiaoguangbin 2023-10-09 20:07:13 +08:00
commit 692cb33145
6 changed files with 204 additions and 102 deletions

View File

@ -37,6 +37,7 @@ export const showSaveFileModal = (data, ext) => {
* 读文件 * 读文件
* @param {File} file * @param {File} file
* @param { 'arrayBuffer' | 'text' | 'dataURL' | 'binaryString'} fileType * @param { 'arrayBuffer' | 'text' | 'dataURL' | 'binaryString'} fileType
* @returns {Promise<string | ArrayBuffer}
*/ */
export const readFile = (file, fileType = 'text') => { export const readFile = (file, fileType = 'text') => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -66,8 +67,16 @@ export const readFile = (file, fileType = 'text') => {
export const zipFile = async (fileList, zipName) => { export const zipFile = async (fileList, zipName) => {
const zip = new JSZip() const zip = new JSZip()
const promises = [] const promises = []
const readFileWithName = async file => {
const data = await readFile(file, 'arrayBuffer')
return {
fileName: file.name,
data
}
}
fileList.forEach(file => { fileList.forEach(file => {
promises.push(readFile(file, 'arrayBuffer')) promises.push(readFileWithName(file))
}) })
const result = await Promise.all(promises) const result = await Promise.all(promises)
result.forEach(res => { result.forEach(res => {

View File

@ -1,4 +1,30 @@
/**
* PHD 类型
*/
export const PHD_DATA_TYPE = {
QCPHD: 'QCPHD',
DETBKPHD: 'DETBKPHD',
SAMPLEPHD: 'SAMPLEPHD',
GASBKPHD: 'GASBKPHD'
}
/**
* 判断是不是sample
* @param {*} dataType
* @returns
*/
export const isSample = dataType => {
return ['SAMPLEPHD', 'SPHDP', 'SPHDF'].includes(dataType)
}
export class PHDParser { export class PHDParser {
/**
* 根据Block解析出的结果集
*/
blocks = {
baseInfo: []
}
/** /**
* 数据类型 * 数据类型
*/ */
@ -30,45 +56,95 @@ export class PHDParser {
*/ */
otherFilePrefixes = [] otherFilePrefixes = []
/**
* 该文件是不是sample
*/
isSample = false
/** /**
* 构造函数 * 构造函数
* @param {string} text * @param {string} text
*/ */
constructor(text) { constructor(text) {
const getLine = this.readTextLine(text) this.splitByBlock(text)
const dataTypeLine = getLine(4) this.dataType = this.getBaseInfoByTag('DATA_TYPE')[0]
const fileTypeLine = getLine(6) this.isSample = isSample(this.dataType)
const fileNameLine = getLine(8)
const liveTimeLine = getLine(18)
this.dataType = this.getOnymousData(dataTypeLine)[0] const headerInfo = this.getBlockInfo('Header')
const fileType = this.splitLineText(fileTypeLine) const headerInfoLine1 = this.splitLineText(headerInfo[0])
this.fileType = fileType[2] this.fileType = headerInfoLine1[2]
this.qualify = fileType[4] this.qualify = headerInfoLine1[4]
const liveTime = parseFloat(this.splitLineText(liveTimeLine)[3]).toFixed(1) const liveTime = parseFloat(this.getBlockStr('Acquisition', 0, 3)).toFixed(1)
this.liveTime = liveTime.indexOf('.0') == -1 ? liveTime : liveTime.slice(0, -2) this.liveTime = liveTime.indexOf('.0') == -1 ? liveTime : liveTime.slice(0, -2)
// 如果是 Beta 谱 // 如果解析的是sample 文件,则解析相关联的文件
if (this.fileType == 'B') { if (this.isSample) {
// 如果解析的是sample 文件,则获取其他三个文件 const filePrefixes = this.getFilePrefixes(headerInfo[2])
if (this.dataType == PHD_DATA_TYPE.SAMPLEPHD) {
const filePrefixes = this.getFilePrefixes(fileNameLine)
this.sampleFilePrefix = filePrefixes.splice(0, 1)[0] this.sampleFilePrefix = filePrefixes.splice(0, 1)[0]
this.otherFilePrefixes = filePrefixes this.otherFilePrefixes = filePrefixes
} }
} }
}
/** /**
* 将文本按行分割 * 根据块类型分割
* @param {string} text * @param {string} text
* @returns { (line: number) => string }
*/ */
readTextLine(text) { splitByBlock(text) {
const splited = text.split('\n') const lines = (text = text.replace(/\r{0,1}\n/g, '\n').split('\n'))
return line => { let blockType = 'baseInfo'
return splited[line - 1] for (const line of lines) {
// 如果以#开头
if (line.startsWith('#')) {
blockType = line.slice(1)
if (blockType.startsWith('Header')) {
blockType = 'Header'
} }
this.blocks[blockType] = []
continue
}
this.blocks[blockType].push(line.trim())
}
}
/**
* 根据块名拿到块内容
* @param {string} blockName
* @returns {Array<string>}
*/
getBlockInfo(blockName) {
return this.blocks[blockName]
}
/**
* 在baseInfo中根据tag查找值
* @param {*} tag
* @returns {Array<string>}
*/
getBaseInfoByTag(tag) {
const baseInfo = this.getBlockInfo('baseInfo')
const map = new Map()
baseInfo.forEach(line => {
if (line.startsWith(tag)) {
map.set(tag, this.getOnymousData(line))
}
})
return map.get(tag)
}
/**
* 根据行号和位置在block中查找字符
* @param {string} blockName
* @param {number} lineNum
* @param {number} index
* @returns {string}
*/
getBlockStr(blockName, lineNum, index) {
const blockInfo = this.getBlockInfo(blockName)
const lineText = blockInfo[lineNum]
const splited = this.splitLineText(lineText)
return splited[index]
} }
/** /**
@ -98,19 +174,9 @@ export class PHDParser {
const filePrefixes = unHandledfilePrefixes const filePrefixes = unHandledfilePrefixes
.filter(filePrefix => filePrefix) .filter(filePrefix => filePrefix)
.map(filePrefix => { .map(filePrefix => {
filePrefix = filePrefix.replace(/(\d{4})\/(\d{2})\/(\d{2})-(\d{2}):(\d{2})/, '$1$2$3_$4$5') filePrefix = filePrefix.replace(/(\d{4})\/(\d{2})\/(\d{2})-(\d{2}):(\d{2})(:\d{2}\.\d)?/, '$1$2$3_$4$5')
return filePrefix + '_' return filePrefix + '_'
}) })
return filePrefixes return filePrefixes
} }
} }
/**
* PHD 类型
*/
export const PHD_DATA_TYPE = {
QCPHD: 'QCPHD',
DETBKPHD: 'DETBKPHD',
SAMPLEPHD: 'SAMPLEPHD',
GASBKPHD: 'GASBKPHD'
}

View File

@ -197,7 +197,7 @@ export default {
*/ */
async handleLoad() { async handleLoad() {
if (!this.selectedRowKeys.length) { if (!this.selectedRowKeys.length) {
this.$message.warn('Please Select Databases To Load') this.$message.warn('Please Select Sample To Load')
return return
} }
this.selectedRowKeys = [] this.selectedRowKeys = []

View File

@ -205,7 +205,7 @@
import { getAction, postAction } from '../../../../api/manage' import { getAction, postAction } from '../../../../api/manage'
import { FilePicker } from '@/utils/FilePicker' import { FilePicker } from '@/utils/FilePicker'
import { readFile, zipFile } from '@/utils/file' import { readFile, zipFile } from '@/utils/file'
import { PHDParser, PHD_DATA_TYPE } from '@/utils/phdHelper' import { isSample, PHDParser, PHD_DATA_TYPE } from '@/utils/phdHelper'
import ModalMixin from '@/mixins/ModalMixin' import ModalMixin from '@/mixins/ModalMixin'
const columns = [ const columns = [
@ -417,6 +417,8 @@ export default {
fileName: `${sampleFilePrefix}S_${qualify}_${liveTime}.PHD`, fileName: `${sampleFilePrefix}S_${qualify}_${liveTime}.PHD`,
} }
// Beta Gamma
if (phdParser.fileType == 'B') {
const iter = await this.directoryHanlder.values() const iter = await this.directoryHanlder.values()
const fileList = [] const fileList = []
@ -468,6 +470,13 @@ export default {
} }
} }
record.qcFileName = qcFileInfo record.qcFileName = qcFileInfo
} else {
Object.assign(record, {
gasFileName: undefined,
detFileName: undefined,
qcFileName: undefined,
})
}
} }
// sample // sample
else { else {
@ -491,8 +500,7 @@ export default {
let currDataType = '' let currDataType = ''
switch (column) { switch (column) {
case 'sampleFileName': case 'sampleFileName':
currDataType = PHD_DATA_TYPE.SAMPLEPHD return isSample(dataType)
break
case 'gasFileName': case 'gasFileName':
currDataType = PHD_DATA_TYPE.GASBKPHD currDataType = PHD_DATA_TYPE.GASBKPHD
break break
@ -628,7 +636,7 @@ export default {
} }
}) })
} }
if(!files.length) { if (!files.length) {
this.$message.warn('File is Empty ') this.$message.warn('File is Empty ')
return return
} }

View File

@ -10,7 +10,8 @@
<title-over-border title="Format"> <title-over-border title="Format">
<a-radio-group v-model="saveFormat" class="format-radio-group"> <a-radio-group v-model="saveFormat" class="format-radio-group">
<a-radio value="txt">Save as Txt</a-radio> <a-radio value="txt">Save as Txt</a-radio>
<a-radio value="excel">Save as Excel</a-radio> <a-radio value="xls">Save as Excel</a-radio>
<a-radio value="html">Save as Html</a-radio>
</a-radio-group> </a-radio-group>
</title-over-border> </title-over-border>
</div> </div>
@ -19,7 +20,6 @@
</template> </template>
<script> <script>
import { downloadFile } from '../../../../api/manage'
import TitleOverBorder from '../TitleOverBorder.vue' import TitleOverBorder from '../TitleOverBorder.vue'
export default { export default {
components: { TitleOverBorder }, components: { TitleOverBorder },
@ -41,8 +41,7 @@ export default {
}, },
handleOk() { handleOk() {
console.log('%c [ save ]-22', 'font-size:13px; background:pink; color:#bf2c9f;') this.$emit('save', this.saveFormat)
downloadFile('', 'result.' + this.saveFormat, {})
} }
}, },
computed: { computed: {
@ -73,7 +72,7 @@ export default {
} }
.format-radio-group { .format-radio-group {
.ant-radio-wrapper:first-child { .ant-radio-wrapper:not(:last-child) {
margin-bottom: 10px; margin-bottom: 10px;
} }
} }

View File

@ -74,7 +74,7 @@
<!-- Nuclide Activity and MDC 弹窗结束 --> <!-- Nuclide Activity and MDC 弹窗结束 -->
<!-- Save Setting 弹窗开始 --> <!-- Save Setting 弹窗开始 -->
<save-setting-modal v-model="saveSettingModalVisible" /> <save-setting-modal v-model="saveSettingModalVisible" @save="handleSaveResultsToFile" />
<!-- Save Setting 弹窗结束 --> <!-- Save Setting 弹窗结束 -->
<!-- 分析-设置弹窗开始 --> <!-- 分析-设置弹窗开始 -->
@ -156,10 +156,7 @@
<!-- Beta-Gamma 的Comments 结束 --> <!-- Beta-Gamma 的Comments 结束 -->
<!-- Beta-Gamma 的Energy Calibration开始 --> <!-- Beta-Gamma 的Energy Calibration开始 -->
<beta-gamma-energy-calibration-modal <beta-gamma-energy-calibration-modal v-model="betaGammaEnergyCalibrationModalVisible" @sendInfo="getCheckFlag" />
v-model="betaGammaEnergyCalibrationModalVisible"
@sendInfo="getCheckFlag"
/>
<!-- Beta-Gamma 的Energy Calibration结束 --> <!-- Beta-Gamma 的Energy Calibration结束 -->
<!-- Beta-Gamma Extrapolation 弹窗开始 --> <!-- Beta-Gamma Extrapolation 弹窗开始 -->
@ -191,7 +188,7 @@
</div> </div>
</template> </template>
<script> <script>
import { postAction } from '@/api/manage' import { downloadFile, postAction } from '@/api/manage'
import GammaAnalysis from './gamma-analysis.vue' import GammaAnalysis from './gamma-analysis.vue'
import BetaGammaAnalysis from './beta-gamma-analysis.vue' import BetaGammaAnalysis from './beta-gamma-analysis.vue'
import SpectraListInMenu from './components/SpectraListInMenu.vue' import SpectraListInMenu from './components/SpectraListInMenu.vue'
@ -460,8 +457,31 @@ export default {
}, },
// //
handleSaveResultsToFile() { async handleSaveResultsToFile(saveFormat) {
this.saveSettingModalVisible = true const url =
saveFormat == 'xls'
? '/spectrumAnalysis/saveToExcel'
: saveFormat == 'txt'
? '/spectrumAnalysis/saveToTxt'
: saveFormat == 'html'
? '/spectrumAnalysis/saveToHTML'
: ''
if (!this.resultDisplayFlag) {
this.$message.warn('Please Analyse Spectrum First')
return
}
this.resultDisplayFlag.forEach((item) => {
this.params_toDB[`${item.nuclideName.toLowerCase()}Flag`] = item.nidFlag
})
this.params_toDB.sampleFileName = this.newSampleData.inputFileName
this.params_toDB.gasFileName = this.newSampleData.gasFileName
this.params_toDB.detFileName = this.newSampleData.detFileName
this.params_toDB.qcFileName = this.newSampleData.qcFileName
this.params_toDB.dbName = this.newSampleData.dbName
downloadFile(url, `result.${saveFormat}`, this.params_toDB, 'post')
}, },
/** /**
@ -478,7 +498,7 @@ export default {
const hideLoading = this.$message.loading('Saving...', 0) const hideLoading = this.$message.loading('Saving...', 0)
try { try {
const { success, message } = await getAction('/gamma/saveToDB', { const { success, message } = await getAction('/gamma/saveToDB', {
fileName: this.sampleData.inputFileName fileName: this.sampleData.inputFileName,
}) })
if (success) { if (success) {
this.$message.success('Save Success') this.$message.success('Save Success')
@ -727,7 +747,7 @@ export default {
}, },
on: { on: {
menuClick: () => { menuClick: () => {
this.handleSaveResultsToFile() this.saveSettingModalVisible = true
}, },
submenuClick: ({ item, child }) => { submenuClick: ({ item, child }) => {
if (item.title == 'Save Results to DB') { if (item.title == 'Save Results to DB') {