refactor: statistics.go.
This commit is contained in:
+7
-4
@@ -27,6 +27,8 @@ import (
|
||||
const (
|
||||
analysisTypeHeartRateOnly = "heart_rate_only"
|
||||
analysisTypeHeartRateWithSteps = "heart_rate_with_steps"
|
||||
sourceUpload = "upload"
|
||||
sourceCloud = "cloud"
|
||||
)
|
||||
|
||||
// readDocxContent 读取 .docx 文件并将其转换为结构化文本
|
||||
@@ -314,7 +316,7 @@ func (tc *TrainingController) AnalyzeByAI(c *gin.Context) {
|
||||
analysisType = analysisTypeHeartRateOnly
|
||||
}
|
||||
if teachingPlanSource == "" {
|
||||
teachingPlanSource = "upload"
|
||||
teachingPlanSource = sourceUpload
|
||||
}
|
||||
|
||||
if len(csvFiles) == 0 {
|
||||
@@ -391,6 +393,7 @@ func (tc *TrainingController) AnalyzeByAI(c *gin.Context) {
|
||||
record := models.AIAnalysisRecord{
|
||||
RegionID: regionID,
|
||||
SourceType: teachingPlanSource,
|
||||
AnalysisType: analysisType,
|
||||
InputTokens: analysisResult.InputTokens,
|
||||
OutputTokens: analysisResult.OutputTokens,
|
||||
InputSizeBytes: analysisResult.InputSizeBytes,
|
||||
@@ -413,14 +416,14 @@ func (tc *TrainingController) AnalyzeByAI(c *gin.Context) {
|
||||
|
||||
func resolveTeachingPlanContent(c *gin.Context, form *multipart.Form, source string) (string, int64, error) {
|
||||
switch strings.ToLower(strings.TrimSpace(source)) {
|
||||
case "upload":
|
||||
case sourceUpload:
|
||||
docxFiles := form.File["teaching_plan"]
|
||||
if len(docxFiles) == 0 {
|
||||
return "", 0, fmt.Errorf("Missing required file: teaching_plan (.docx)")
|
||||
}
|
||||
content, err := readDocxContent(docxFiles[0])
|
||||
return content, docxFiles[0].Size, err
|
||||
case "cloud":
|
||||
case sourceCloud:
|
||||
lessonPlanID := c.PostForm("lesson_plan_id")
|
||||
if strings.TrimSpace(lessonPlanID) == "" {
|
||||
return "", 0, fmt.Errorf("missing required field: lesson_plan_id")
|
||||
@@ -432,6 +435,6 @@ func resolveTeachingPlanContent(c *gin.Context, form *multipart.Form, source str
|
||||
content, err := readDocxContentFromPath(fileRecord.FilePath)
|
||||
return content, fileRecord.FileSize, err
|
||||
default:
|
||||
return "", 0, fmt.Errorf("invalid teaching_plan_source, expected upload or cloud")
|
||||
return "", 0, fmt.Errorf("invalid teaching_plan_source, expected %s or %s", sourceUpload, sourceCloud)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user