增强AI个性化画像分层并补回归测试
This commit is contained in:
@@ -31,8 +31,8 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
SmokeAIAdviceTypeDaily = "daily_advice"
|
||||
SmokeAIAdviceTypeNextSmoke = "next_smoke_time"
|
||||
SmokeAIAdviceTypeDaily = "daily_advice"
|
||||
SmokeAIAdviceTypeNextSmoke = "next_smoke_time"
|
||||
)
|
||||
|
||||
type SmokeAIAdviceService struct {
|
||||
@@ -70,16 +70,17 @@ type adviceSnapshot struct {
|
||||
}
|
||||
|
||||
type adviceUserProfile struct {
|
||||
BaselineCigsPerDay int `json:"baseline_cigs_per_day,omitempty"`
|
||||
SmokingYears float64 `json:"smoking_years,omitempty"`
|
||||
PackPriceCent int `json:"pack_price_cent,omitempty"`
|
||||
SmokeMotivations []string `json:"smoke_motivations,omitempty"`
|
||||
QuitMotivations []string `json:"quit_motivations,omitempty"`
|
||||
WakeUpTime string `json:"wake_up_time,omitempty"`
|
||||
SleepTime string `json:"sleep_time,omitempty"`
|
||||
AwakeMinutes int `json:"awake_minutes,omitempty"`
|
||||
BaselineIntervalMinutes int `json:"baseline_interval_minutes,omitempty"`
|
||||
OnboardingCompletedAtISO string `json:"onboarding_completed_at,omitempty"`
|
||||
BaselineCigsPerDay int `json:"baseline_cigs_per_day,omitempty"`
|
||||
SmokingYears float64 `json:"smoking_years,omitempty"`
|
||||
PackPriceCent int `json:"pack_price_cent,omitempty"`
|
||||
SmokeMotivations []string `json:"smoke_motivations,omitempty"`
|
||||
QuitMotivations []string `json:"quit_motivations,omitempty"`
|
||||
WakeUpTime string `json:"wake_up_time,omitempty"`
|
||||
SleepTime string `json:"sleep_time,omitempty"`
|
||||
AwakeMinutes int `json:"awake_minutes,omitempty"`
|
||||
BaselineIntervalMinutes int `json:"baseline_interval_minutes,omitempty"`
|
||||
UserSegment string `json:"user_segment,omitempty"`
|
||||
OnboardingCompletedAtISO string `json:"onboarding_completed_at,omitempty"`
|
||||
}
|
||||
|
||||
func (s *SmokeAIAdviceService) GetOrGenerate(ctx context.Context, user *usermodel.User, adviceDate time.Time, promptVersion string) (*smokemodel.SmokeAIAdvice, error) {
|
||||
@@ -284,9 +285,9 @@ func (s *SmokeAIAdviceService) buildSnapshot(ctx context.Context, uid int, advic
|
||||
timeLabel = t.eventAt.Format("15:04")
|
||||
}
|
||||
nodes = append(nodes, adviceSnapshotNode{
|
||||
Time: timeLabel,
|
||||
Num: t.log.Num,
|
||||
Level: t.log.Level,
|
||||
Time: timeLabel,
|
||||
Num: t.log.Num,
|
||||
Level: t.log.Level,
|
||||
Remark: t.log.Remark,
|
||||
})
|
||||
}
|
||||
@@ -334,6 +335,7 @@ func loadAdviceUserProfile(ctx context.Context, db *gorm.DB, uid int) *adviceUse
|
||||
SleepTime: sleep,
|
||||
AwakeMinutes: awake,
|
||||
BaselineIntervalMinutes: baselineIntervalMinutes(awake, profile.BaselineCigsPerDay),
|
||||
UserSegment: deriveUserSegment(profile.BaselineCigsPerDay, profile.SmokingYears),
|
||||
}
|
||||
if profile.OnboardingCompletedAt != nil {
|
||||
out.OnboardingCompletedAtISO = profile.OnboardingCompletedAt.In(time.Local).Format(time.RFC3339)
|
||||
@@ -467,3 +469,13 @@ func truncateString(s string, max int) string {
|
||||
}
|
||||
return s[:max]
|
||||
}
|
||||
|
||||
func deriveUserSegment(baselineCigsPerDay int, smokingYears float64) string {
|
||||
if baselineCigsPerDay >= 20 || smokingYears >= 10 {
|
||||
return "heavy"
|
||||
}
|
||||
if baselineCigsPerDay >= 10 || smokingYears >= 3 {
|
||||
return "moderate"
|
||||
}
|
||||
return "newbie"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user