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" StreamerScoreFormulaKey = "streamer_score_formula"
HvyogoSingleDistributeChargePercentageKey = "hvyogo_single_distribute_charge_percentage" HvyogoSingleDistributeChargePercentageKey = "hvyogo_single_distribute_charge_percentage"
QuestionMapKey = "question_map" QuestionMapKey = "question_map"
AgeScore2IQResultMap = "age_score_2_IQ_result_map" AgeScore2IQResultMapKey = "age_score_2_IQ_result_map"
IQResultMapKey = "IQ_result_map"
) )
// del_flag // del_flag

View File

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

View File

@ -19,5 +19,9 @@ type IQResult struct {
type AgeScore2IQResultMapCfg struct { type AgeScore2IQResultMapCfg struct {
AgeBlockIndex2ScoreBlockListMap map[int][]float64 `json:"age_block_index_2_score_block_list_map"` // 年龄分段到分数分布区域的映射map AgeBlockIndex2ScoreBlockListMap map[int][]float64 `json:"age_block_index_2_score_block_list_map"` // 年龄分段到分数分布区域的映射map
AgeBlockList []int64 `json:"age_block_list"` // 年龄段区域,以年龄在该年龄段中第一次出现或最后一个比他小的位置作为年龄段索引 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{} 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 { if err != nil {
logger.Error("Apollo read failed : %v", err) logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail ec = errcode.ErrCodeApolloReadFail
return return
} }
idx := util.GetLastLessOrEqualForInt64(cfg.AgeBlockList, req.GetAge()) ageBlockIdx := util.GetLastLessOrEqualForInt64(cfg.AgeBlockList, req.GetAge())
list := cfg.AgeBlockIndex2ScoreBlockListMap[idx] list := cfg.AgeBlockIndex2ScoreBlockListMap[ageBlockIdx]
idx2 := util.GetLastLessOrEqualForFloat64(list, req.GetTotalScore()) scoreBlockIdx := util.GetLastLessOrEqualForFloat64(list, req.GetTotalScore())
IQResult := cfg.ScoreBlockIndex2IQResultMap[idx2] IQBlockId := cfg.ScoreBlockIndex2IQBlockIdMap[scoreBlockIdx]
req.IQBlockId = goproto.Int64(IQBlockId)
err = _DefaultRavenIQTest.OpCreate(ctx, &Raven_IQ_testproto.OpCreateReq{ err = _DefaultRavenIQTest.OpCreate(ctx, &Raven_IQ_testproto.OpCreateReq{
BaseRequest: req.BaseRequest, BaseRequest: req.BaseRequest,
@ -3663,6 +3664,16 @@ func (s *Service) ApiGetRavenIQTestList(ctx *gin.Context, req *Raven_IQ_testprot
vo.CopyRavenIQTest(test) 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 return
} }

View File

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