feat(server-go): 分子检测扩展(qPCR Ct 判读/SERS 光谱上传/光谱库,#19)
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const maxSpectrumSize = 5 << 20 // 5MB
|
||||
|
||||
// ValidDetectionMethod 检测方式枚举
|
||||
func ValidDetectionMethod(method string) bool {
|
||||
switch method {
|
||||
case "lamp", "qpcr", "sers", "hyperspectral":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// JudgeQPCR qPCR Ct 值自动判读:任一 Ct < threshold 判阳性,无 Ct 判阴性
|
||||
func JudgeQPCR(cts []float64, threshold float64) (string, string) {
|
||||
if threshold <= 0 {
|
||||
threshold = 35
|
||||
}
|
||||
if len(cts) == 0 {
|
||||
return "negative", "未检出 Ct 值,判为阴性"
|
||||
}
|
||||
for _, ct := range cts {
|
||||
if ct < threshold {
|
||||
return "positive", "存在 Ct 值低于阈值,判为阳性"
|
||||
}
|
||||
}
|
||||
return "negative", "全部 Ct 值不低于阈值,判为阴性"
|
||||
}
|
||||
|
||||
// ValidateSpectrumFile 光谱数据文件校验(csv/txt/json,≤5MB)
|
||||
func ValidateSpectrumFile(filename string, size int64) error {
|
||||
if size <= 0 || size > maxSpectrumSize {
|
||||
return errors.New("光谱文件大小需在 1B~5MB 之间")
|
||||
}
|
||||
ext := strings.ToLower(filepath.Ext(filename))
|
||||
switch ext {
|
||||
case ".csv", ".txt", ".json":
|
||||
return nil
|
||||
default:
|
||||
return errors.New("仅支持 csv/txt/json 光谱数据文件")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user