by Robin at 20240722

This commit is contained in:
Leufolium 2024-07-22 09:17:49 +08:00
parent 2167befc4d
commit b283c34f44
5 changed files with 70 additions and 15 deletions

View File

@ -59,7 +59,9 @@ const (
HvyogoSingleDistributeChargePercentageKey = "hvyogo_single_distribute_charge_percentage"
QuestionMapKey = "question_map"
AgeScore2IQResultMapKey = "age_score_2_IQ_result_map"
ClassScore2ClassResultMapKey = "class_score_2_class_result_map"
IQResultMapKey = "IQ_result_map"
ClassResultMapKey = "class_result_map"
)
// del_flag

View File

@ -18,6 +18,7 @@ type ApiListVO struct {
type ApiClassSocreVO struct {
ClassId int64 `json:"class_id"` // 大类id
Score int64 `json:"score"` // 得分
ClassBlockId int64 `json:"class_block_id"` // 大类得分key
Suggestions string `json:"suggestions"` // 建议
}
@ -35,6 +36,7 @@ func (vo *ApiListVO) CopyRavenIQTest(test *dbstruct.RavenIQTest) *ApiListVO {
vo.ClassScoreList = append(vo.ClassScoreList, &ApiClassSocreVO{
ClassId: score.GetClassId(),
Score: score.GetScore(),
ClassBlockId: score.GetClassBlockId(),
})
}
return vo

View File

@ -22,6 +22,19 @@ type AgeScore2IQResultMapCfg struct {
ScoreBlockIndex2IQBlockIdMap map[int]int64 `json:"score_block_index_2_IQ_block_id_map"` // 分数分段到IQ范围id的映射map
}
type ClassScore2ClassResultMapCfg struct {
ClassId2ClassScoreBlockListMap map[int64][]int64 `json:"class_id_2_class_score_block_list_map" bson:"class_id_2_class_score_block_list_map"` // 大类Id到大类分数分布区域的映射map
}
type IQResultMapCfg struct {
Map map[int64]*IQResult `json:"map"`
}
type ClassResult struct {
ClassId int64 `json:"class_id"` // 大类id
Description string `json:"description"` // 描述
}
type ClassResultMapCfg struct {
Map map[int64]*ClassResult `json:"map"`
}

View File

@ -3619,17 +3619,33 @@ func (s *Service) ApiCreateRavenIQTest(ctx *gin.Context, req *Raven_IQ_testproto
req.TotalScore = goproto.Float64(totalScore)
// 换算智商及百分位
cfg := apollostruct.AgeScore2IQResultMapCfg{}
err = apollo.GetJson(consts.AgeScore2IQResultMapKey, &cfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test"))
ageScore2IQResultMapCfg := apollostruct.AgeScore2IQResultMapCfg{}
err = apollo.GetJson(consts.AgeScore2IQResultMapKey, &ageScore2IQResultMapCfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail
return
}
ageBlockIdx := util.GetLastLessOrEqualForInt64(cfg.AgeBlockList, req.GetAge())
list := cfg.AgeBlockIndex2ScoreBlockListMap[ageBlockIdx]
classScore2ClassResultMapCfg := apollostruct.ClassScore2ClassResultMapCfg{}
err = apollo.GetJson(consts.ClassScore2ClassResultMapKey, &classScore2ClassResultMapCfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail
return
}
ageBlockIdx := util.GetLastLessOrEqualForInt64(ageScore2IQResultMapCfg.AgeBlockList, req.GetAge())
list := ageScore2IQResultMapCfg.AgeBlockIndex2ScoreBlockListMap[ageBlockIdx]
scoreBlockIdx := util.GetLastLessOrEqualForFloat64(list, req.GetTotalScore())
IQBlockId := cfg.ScoreBlockIndex2IQBlockIdMap[scoreBlockIdx]
IQBlockId := ageScore2IQResultMapCfg.ScoreBlockIndex2IQBlockIdMap[scoreBlockIdx]
for _, classScore := range req.ClassScoreList {
classScoreBlockList := classScore2ClassResultMapCfg.ClassId2ClassScoreBlockListMap[classScore.GetClassId()]
classScoreBlockIdx := util.GetLastLessOrEqualForInt64(classScoreBlockList, classScore.GetScore())
classScore.ClassBlockId = goproto.Int64(int64(classScoreBlockIdx))
}
req.IQBlockId = goproto.Int64(IQBlockId)
err = _DefaultRavenIQTest.OpCreate(ctx, &Raven_IQ_testproto.OpCreateReq{
@ -3664,16 +3680,30 @@ func (s *Service) ApiGetRavenIQTestList(ctx *gin.Context, req *Raven_IQ_testprot
vo.CopyRavenIQTest(test)
// 填充业务数据
cfg := apollostruct.IQResultMapCfg{}
err = apollo.GetJson(consts.IQResultMapKey, &cfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test"))
IQResultMpcfg := apollostruct.IQResultMapCfg{}
err = apollo.GetJson(consts.IQResultMapKey, &IQResultMpcfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail
return
}
IQResult := cfg.Map[vo.IQBlockId]
classResultMpCfg := apollostruct.ClassResultMapCfg{}
err = apollo.GetJson(consts.ClassResultMapKey, &classResultMpCfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail
return
}
IQResult := IQResultMpcfg.Map[vo.IQBlockId]
vo.Percentile = IQResult.Percentile
vo.Description = IQResult.Description
for _, classScore := range vo.ClassScoreList {
classResult := classResultMpCfg.Map[classScore.ClassBlockId]
classScore.Suggestions = classResult.Description
}
return
}

View File

@ -21,6 +21,7 @@ type RavenIQTestAnswer struct {
type RavenIQTestClassScore struct {
ClassId *int64 `json:"class_id" bson:"class_id"` // 大类id
Score *int64 `json:"score" bson:"score"` // 得分
ClassBlockId *int64 `json:"class_block_id" bson:"class_block_id"` // 大类得分key
}
func (p *RavenIQTest) GetId() int64 {
@ -85,3 +86,10 @@ func (p *RavenIQTestClassScore) GetScore() int64 {
}
return *p.Score
}
func (p *RavenIQTestClassScore) GetClassBlockId() int64 {
if p == nil || p.ClassBlockId == nil {
return 0
}
return *p.ClassBlockId
}