AnalysisSystemForRadionucli.../src/utils/sampleHelper.js

58 lines
1.8 KiB
JavaScript
Raw Normal View History

/**
* 在返回的allData中查找指定的数据
* @param {Array} allData
* @param {*} name
* @param {*} group
*/
export const getLineData = (allData, name, group, isList = false) => {
const arrFunc = isList ? Array.prototype.filter : Array.prototype.find
return arrFunc.call(allData, item => item.name == name && item.group == group) || {}
}
/**
* 转换pointlist类型数据到series的data可用的数据
*/
export const transformPointListData = pointlist => {
if (!pointlist) {
return []
}
return pointlist.map(({ x, y }) => [x, y])
}
// 查找最近的峰(C++相关)
export const findNearPeak = (channel, peakList) => {
let t_bFind = false, // 是否在峰内
i = 0,
peakNum = peakList.length
for (; i < peakNum; ++i) {
const peak = peakList[i]
if (channel >= peak.left && channel <= peak.right) {
// 如果 channel 在峰的左右边界内
if (peak.multiIndex > 0 && channel > peak.peakCentroid) {
// 如果是重峰,且 channel 在重峰的第一个峰的中心道右侧
let j = i
let temp = channel - peak.peakCentroid
while (++j < peakNum && peakList[j].multiIndex == peak.multiIndex) {
if (Math.abs(peakList[j].peakCentroid - channel) < temp) {
// 找出重峰中峰中心道离 channel 最近的峰
temp = Math.abs(peakList[j].peakCentroid - channel)
i = j
}
}
}
// channel 在索引(i)对应的峰内
t_bFind = true
break
} else if (peak.left > channel) {
// channel 不在任何峰内,找离它最近的峰
if (i > 0 && channel - peakList[i - 1].peakCentroid < peak.peakCentroid - channel) i -= 1
break
}
}
if (i >= peakNum) i -= 1
return {
index: i,
find: t_bFind
}
}