Compare commits

...

1 Commits

Author SHA1 Message Date
crosstyan 9a1dedf425 v1 2026-05-09 12:00:34 +08:00
7 changed files with 35194 additions and 12 deletions
Executable
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
# docker exec hr_data_analyzer_db_1 mysqldump -uroot -proot training_db > train.sql
# docker exec hr_data_analyzer_db_1 pg_dump -U postgres training_db > train.sql
docker exec -e PGPASSWORD=root hr_data_analyzer_db_1 pg_dump \
-U postgres \
--data-only \
--inserts \
-t step_heart_rates -t step_stride_freqs -t step_train_records \
training_db > data_only.sql
-6
View File
@@ -1,6 +0,0 @@
database:
host: localhost #when use docker change to "db"
port: 5432
user: postgres
password: root
name: training_db
+41 -5
View File
@@ -14,13 +14,14 @@ import (
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"os" "os"
"strings"
) )
// 配置文件 (与 main.go 保持一致) // 配置文件 (与 main.go 保持一致)
const ( const (
BaseURL = "https://api.lkeap.cloud.tencent.com/v1" BaseURL = "https://tokenhub.tencentmaas.com/v1/"
APIKey = "sk-Y4zjnwulSuSlf60mrzwCxq2ipktHSs4jZHgWeQOArWuWJEOd" // 请替换为实际的 API Key APIKey = "sk-KJNOFMltNzhSKh2IxW3G3MKmZF3q2RrOlvSk497CfTHp1Z4u" // 请替换为实际的 API Key
Model = "deepseek-v3" Model = "deepseek-v4-flash"
) )
// readDocxContent 读取 .docx 文件并将其转换为结构化文本 // readDocxContent 读取 .docx 文件并将其转换为结构化文本
@@ -60,6 +61,8 @@ func readDocxContent(fileHeader *multipart.FileHeader) (string, error) {
// readCSVContent 读取 .csv 文件内容 // readCSVContent 读取 .csv 文件内容
// 修改为先保存临时文件再读取 // 修改为先保存临时文件再读取
// readCSVContent 读取 .csv 文件内容
// 修改为先保存临时文件再读取,并增加了数据压缩逻辑以解决 token 超长问题
func readCSVContent(fileHeader *multipart.FileHeader) (string, error) { func readCSVContent(fileHeader *multipart.FileHeader) (string, error) {
// 1. 创建临时文件 // 1. 创建临时文件
tempFile, err := os.CreateTemp("", "upload_*.csv") tempFile, err := os.CreateTemp("", "upload_*.csv")
@@ -88,7 +91,35 @@ func readCSVContent(fileHeader *multipart.FileHeader) (string, error) {
return "", fmt.Errorf("failed to read CSV content from temporary file: %w", err) return "", fmt.Errorf("failed to read CSV content from temporary file: %w", err)
} }
return string(content), nil lines := strings.Split(string(content), "\n")
var compressedLines []string
for i, line := range lines {
// 1. 必须保留第一行(表头),让 AI 知道每一列是什么
if i == 0 {
compressedLines = append(compressedLines, line)
continue
}
// 2. 跳过空行
if strings.TrimSpace(line) == "" {
continue
}
// 3. 抽样逻辑:每 4 行保留 1 行
// i=1 是数据第1行i=2 是数据第2行...
// (i-1)%4 == 0 意味着数据第1, 5, 9, 13... 行会被保留
if (i-1)%4 == 0 {
compressedLines = append(compressedLines, line)
}
}
// --- 修改逻辑结束 ---
// 将处理后的行重新组合成字符串
resultContent := strings.Join(compressedLines, "\n")
// --- 新增逻辑结束 ---
return resultContent, nil
} }
// buildAnalysisPrompt 构建发送给 AI 的提示词 // buildAnalysisPrompt 构建发送给 AI 的提示词
@@ -138,11 +169,16 @@ func buildAnalysisPrompt(teachingPlanContent, heartRateContent string) string {
| **结束部分** | 社会性及情感目标游戏 | | | | | 4 | | **结束部分** | 社会性及情感目标游戏 | | | | | 4 |
| | 整理放松 | | | | | 2 | | | 整理放松 | | | | | 2 |
请以专业体育教师的视角,提供详细的数据分析和教学建议。`, teachingPlanContent, heartRateContent) 请以专业体育教师的视角,提供详细的数据分析和教学建议。请直接输出报告内容,不要包含“好的”、“收到”、“作为一名...”等任何开场白或客套话。`, teachingPlanContent, heartRateContent)
} }
// callAIForAnalysis 调用大模型进行分析 // callAIForAnalysis 调用大模型进行分析
func callAIForAnalysis(prompt string) (string, error) { func callAIForAnalysis(prompt string) (string, error) {
sizeInBytes := len(prompt)
sizeInKB := float64(sizeInBytes) / 1024.0
// 在日志中打印大小,保留两位小数
log.Printf("=== 发送给 AI 的内容大小: %.2f KB (%d 字节) ===", sizeInKB, sizeInBytes)
config := openai.DefaultConfig(APIKey) config := openai.DefaultConfig(APIKey)
config.BaseURL = BaseURL config.BaseURL = BaseURL
client := openai.NewClientWithConfig(config) client := openai.NewClientWithConfig(config)
+7951
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -4,7 +4,7 @@ services:
app: app:
build: . build: .
ports: ports:
- "8180:8080" - "127.0.0.1:8180:8080"
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy
Regular → Executable
View File
+27191
View File
File diff suppressed because it is too large Load Diff