This commit is contained in:
Leufolium 2024-07-19 18:31:15 +08:00
parent de756dab19
commit 2167befc4d
5 changed files with 32 additions and 16 deletions

View File

@ -58,7 +58,8 @@ const (
StreamerScoreFormulaKey = "streamer_score_formula"
HvyogoSingleDistributeChargePercentageKey = "hvyogo_single_distribute_charge_percentage"
QuestionMapKey = "question_map"
AgeScore2IQResultMap = "age_score_2_IQ_result_map"
AgeScore2IQResultMapKey = "age_score_2_IQ_result_map"
IQResultMapKey = "IQ_result_map"
)
// del_flag

View File

@ -8,8 +8,8 @@ type ApiListVO struct {
Id int64 `json:"id"` // 瑞文智商测试表id
UserId int64 `json:"user_id"` // 用户id
Age int64 `json:"age"` // 年龄
TotalScores int64 `json:"total_scores"` // 总得分
IQ float64 `json:"IQ"` // 智商值
TotalScore float64 `json:"total_score"` // 总得分
IQBlockId int64 `json:"IQ_block_id"` // 智商值
Percentile int64 `json:"percentile"` // 百分位
Description string `json:"description"` // 描述
ClassScoreList []*ApiClassSocreVO `json:"class_score_list"` // 大类得分list
@ -28,8 +28,8 @@ func (vo *ApiListVO) CopyRavenIQTest(test *dbstruct.RavenIQTest) *ApiListVO {
vo.Id = test.GetId()
vo.UserId = test.GetUserId()
vo.Age = test.GetAge()
vo.TotalScores = test.GetTotalScores()
vo.IQ = test.GetIQ()
vo.TotalScore = test.GetTotalScore()
vo.IQBlockId = test.GetIQBlockId()
vo.ClassScoreList = make([]*ApiClassSocreVO, 0)
for _, score := range test.ClassScoreList {
vo.ClassScoreList = append(vo.ClassScoreList, &ApiClassSocreVO{

View File

@ -19,5 +19,9 @@ type IQResult struct {
type AgeScore2IQResultMapCfg struct {
AgeBlockIndex2ScoreBlockListMap map[int][]float64 `json:"age_block_index_2_score_block_list_map"` // 年龄分段到分数分布区域的映射map
AgeBlockList []int64 `json:"age_block_list"` // 年龄段区域,以年龄在该年龄段中第一次出现或最后一个比他小的位置作为年龄段索引
ScoreBlockIndex2IQResultMap map[int]*IQResult `json:"score_block_index_2_IQ_result_map"` // 分数分段到IQ结果的映射map
ScoreBlockIndex2IQBlockIdMap map[int]int64 `json:"score_block_index_2_IQ_block_id_map"` // 分数分段到IQ范围id的映射map
}
type IQResultMapCfg struct {
Map map[int64]*IQResult `json:"map"`
}

View File

@ -3620,16 +3620,17 @@ func (s *Service) ApiCreateRavenIQTest(ctx *gin.Context, req *Raven_IQ_testproto
// 换算智商及百分位
cfg := apollostruct.AgeScore2IQResultMapCfg{}
err = apollo.GetJson(consts.AgeScore2IQResultMap, &cfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test"))
err = apollo.GetJson(consts.AgeScore2IQResultMapKey, &cfg, apollo.ApolloOpts().SetNamespace("Raven_IQ_test"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail
return
}
idx := util.GetLastLessOrEqualForInt64(cfg.AgeBlockList, req.GetAge())
list := cfg.AgeBlockIndex2ScoreBlockListMap[idx]
idx2 := util.GetLastLessOrEqualForFloat64(list, req.GetTotalScore())
IQResult := cfg.ScoreBlockIndex2IQResultMap[idx2]
ageBlockIdx := util.GetLastLessOrEqualForInt64(cfg.AgeBlockList, req.GetAge())
list := cfg.AgeBlockIndex2ScoreBlockListMap[ageBlockIdx]
scoreBlockIdx := util.GetLastLessOrEqualForFloat64(list, req.GetTotalScore())
IQBlockId := cfg.ScoreBlockIndex2IQBlockIdMap[scoreBlockIdx]
req.IQBlockId = goproto.Int64(IQBlockId)
err = _DefaultRavenIQTest.OpCreate(ctx, &Raven_IQ_testproto.OpCreateReq{
BaseRequest: req.BaseRequest,
@ -3663,6 +3664,16 @@ 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"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail
return
}
IQResult := cfg.Map[vo.IQBlockId]
vo.Percentile = IQResult.Percentile
vo.Description = IQResult.Description
return
}

View File

@ -5,7 +5,7 @@ type RavenIQTest struct {
UserId *int64 `json:"user_id" bson:"user_id"` // 用户id
Age *int64 `json:"age" bson:"age"` // 年龄
TotalScore *float64 `json:"total_score" bson:"total_score"` // 总得分
IQ *float64 `json:"IQ" bson:"IQ"` // 智商值
IQBlockId *int64 `json:"IQ_block_id" bson:"IQ_block_id"` // 智商值key
AnswerList []*RavenIQTestAnswer `json:"answer_list" bson:"answer_list"` // 答案list
ClassScoreList []*RavenIQTestClassScore `json:"class_score_list" bson:"class_score_list"` // 大类得分list
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
@ -51,11 +51,11 @@ func (p *RavenIQTest) GetTotalScore() float64 {
return *p.TotalScore
}
func (p *RavenIQTest) GetIQ() float64 {
if p == nil || p.IQ == nil {
func (p *RavenIQTest) GetIQBlockId() int64 {
if p == nil || p.IQBlockId == nil {
return 0
}
return *p.IQ
return *p.IQBlockId
}
func (p *RavenIQTestAnswer) GetQuestionId() int64 {