feat: mock data.
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"hr_receiver/config"
|
||||
"hr_receiver/models"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config.InitConfig()
|
||||
config.ConnectDB()
|
||||
|
||||
// 生成100条测试数据
|
||||
count := 100
|
||||
records := make([]models.AIAnalysisRecord, 0, count)
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
records = append(records, generateRecord())
|
||||
}
|
||||
|
||||
if err := config.DB.CreateInBatches(records, 50).Error; err != nil {
|
||||
panic("failed to insert mock data: " + err.Error())
|
||||
}
|
||||
|
||||
fmt.Printf("成功插入 %d 条 AI 分析记录\n", count)
|
||||
}
|
||||
|
||||
func generateRecord() models.AIAnalysisRecord {
|
||||
// regionID 为 1 或 3
|
||||
regionID := uint32(1)
|
||||
if rand.Intn(2) == 1 {
|
||||
regionID = 3
|
||||
}
|
||||
|
||||
// sourceType: upload 或 cloud
|
||||
sourceType := "upload"
|
||||
if rand.Intn(2) == 1 {
|
||||
sourceType = "cloud"
|
||||
}
|
||||
|
||||
// docx 教案原始文件大小: 50KB ~ 500KB
|
||||
docxSize := int64(rand.Intn(451*1024) + 50*1024)
|
||||
|
||||
// 心率 csv 原始文件大小: 约 80KB (70KB ~ 90KB)
|
||||
csvSize := int64(rand.Intn(20*1024) + 70*1024)
|
||||
|
||||
// 步数 csv 原始文件大小: 约 20KB ~ 40KB (heart_rate_with_steps 时才有)
|
||||
var stepCsvSize int64
|
||||
analysisType := analysisType()
|
||||
if analysisType == "heart_rate_with_steps" {
|
||||
stepCsvSize = int64(rand.Intn(20*1024) + 20*1024)
|
||||
}
|
||||
|
||||
originalFileSize := docxSize + csvSize + stepCsvSize
|
||||
|
||||
// 压缩后内容大小: csv 每4行保留1行,大约压缩为 25% + 表头;docx 提取文本后大约 30%~60%
|
||||
compressedDocx := int64(float64(docxSize) * (0.3 + rand.Float64()*0.3))
|
||||
compressedCsv := int64(float64(csvSize) * (0.22 + rand.Float64()*0.08)) // ~22%-30%
|
||||
var compressedStepCsv int64
|
||||
if stepCsvSize > 0 {
|
||||
compressedStepCsv = int64(float64(stepCsvSize) * (0.22 + rand.Float64()*0.08))
|
||||
}
|
||||
compressedContentSize := compressedDocx + compressedCsv + compressedStepCsv
|
||||
|
||||
// prompt 大小 = 压缩后内容 + 提示词模板 (~1.5KB)
|
||||
promptTemplateSize := 1500 + rand.Intn(500)
|
||||
inputSizeBytes := int(compressedContentSize) + promptTemplateSize
|
||||
|
||||
// AI 输出大小: 3KB ~ 25KB (分析报告)
|
||||
outputSizeBytes := rand.Intn(22*1024) + 3*1024
|
||||
|
||||
// token 估算: 中文混合场景,平均约 3.5 字节/token
|
||||
inputTokens := inputSizeBytes / (3 + rand.Intn(2))
|
||||
outputTokens := outputSizeBytes / (3 + rand.Intn(2))
|
||||
|
||||
// 分析时长: 主要和输出 token 数量相关,1分钟以内
|
||||
// 基础延迟 500ms + 每token约 15~40ms
|
||||
tokenLatency := int64(15 + rand.Intn(26))
|
||||
durationMs := 500 + int64(outputTokens)*tokenLatency
|
||||
if durationMs > 60000 {
|
||||
durationMs = 60000 - int64(rand.Intn(5000))
|
||||
}
|
||||
|
||||
// 上传时间: 最近 90 天内随机
|
||||
uploadTime := time.Now().Add(-time.Duration(rand.Intn(90*24)) * time.Hour).Add(-time.Duration(rand.Intn(60)) * time.Minute).UnixMilli()
|
||||
|
||||
return models.AIAnalysisRecord{
|
||||
RegionID: ®ionID,
|
||||
SourceType: sourceType,
|
||||
InputTokens: inputTokens,
|
||||
OutputTokens: outputTokens,
|
||||
InputSizeBytes: inputSizeBytes,
|
||||
OutputSizeBytes: outputSizeBytes,
|
||||
DurationMs: durationMs,
|
||||
OriginalFileSize: originalFileSize,
|
||||
CompressedContentSize: compressedContentSize,
|
||||
UploadTime: uploadTime,
|
||||
}
|
||||
}
|
||||
|
||||
func analysisType() string {
|
||||
// 约 30% 的带步数分析
|
||||
if rand.Intn(100) < 30 {
|
||||
return "heart_rate_with_steps"
|
||||
}
|
||||
return "heart_rate_only"
|
||||
}
|
||||
Reference in New Issue
Block a user