|
@@ -1,126 +0,0 @@
|
|
|
-package api
|
|
|
-
|
|
|
-// // 具体数据库中创建
|
|
|
-// // 每个用户每个模块有多条记录,每次学习生成一条记录
|
|
|
-// func CreateLearnLog(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
-// db := c.Param("scope")
|
|
|
-// if len(db) == 0 {
|
|
|
-// return nil, errors.New("scope不能为空")
|
|
|
-// }
|
|
|
-// learnLog := &model.LearnLog{}
|
|
|
-// err := c.ShouldBindJSON(learnLog)
|
|
|
-// if err != nil {
|
|
|
-// log.Error(err)
|
|
|
-// return nil, err
|
|
|
-// }
|
|
|
-// if len(learnLog.Cid) < 1 {
|
|
|
-// return nil, errors.New("模块id不能为空")
|
|
|
-// }
|
|
|
-
|
|
|
-// // 没找到数据,创建
|
|
|
-// learnLog.Uid = apictx.User.ID
|
|
|
-// zero := 0
|
|
|
-// learnLog.LearnTime = &zero
|
|
|
-// learnLog.CreateTime = time.Now()
|
|
|
-// learnLog.UpdateTime = time.Now()
|
|
|
-// return repo.RepoAddDbDoc(apictx.CreateRepoCtx(), db, repo.CollectionLearnLog, learnLog)
|
|
|
-// }
|
|
|
-
|
|
|
-// // 每分钟记录下学习时长
|
|
|
-// // sync/time/:id/:scope
|
|
|
-// func SyncLearnTime(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
-// id := c.Param("id")
|
|
|
-// db := c.Param("scope")
|
|
|
-// objId, _ := primitive.ObjectIDFromHex(id)
|
|
|
-// if objId.IsZero() {
|
|
|
-// return nil, errors.New("id错误")
|
|
|
-// }
|
|
|
-
|
|
|
-// // 写入统计数据,每个人每个模块的总学习时长
|
|
|
-// learnLog := &model.LearnLog{}
|
|
|
-// found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
-// Db: db,
|
|
|
-// CollectName: repo.CollectionLearnLog,
|
|
|
-// Query: repo.Map{"_id": objId},
|
|
|
-// Project: []string{"cid", "uid"},
|
|
|
-// }, learnLog)
|
|
|
-// if err != nil {
|
|
|
-// log.Error(err)
|
|
|
-// return nil, err
|
|
|
-// }
|
|
|
-// if !found {
|
|
|
-// return nil, errors.New("未找到记录")
|
|
|
-// }
|
|
|
-
|
|
|
-// update := bson.M{"$inc": bson.M{"learnTime": 1}, "$set": bson.M{"updateTime": time.Now()}}
|
|
|
-
|
|
|
-// _, err = repo.RepoUpdateSetDbDocs(apictx.CreateRepoCtx(), db, repo.CollectionLearnLogStatistics, bson.M{"cid": learnLog.Cid, "uid": learnLog.Uid}, update)
|
|
|
-// if err != nil {
|
|
|
-// log.Error(err)
|
|
|
-// fmt.Println(err)
|
|
|
-// }
|
|
|
-// return repo.RepoUpdateSetDbDocProps(apictx.CreateRepoCtx(), db, repo.CollectionLearnLog, id, update)
|
|
|
-// }
|
|
|
-
|
|
|
-// func LearnLogStatistics(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
-// db := c.Param("scope")
|
|
|
-// if len(db) == 0 {
|
|
|
-// return nil, errors.New("scope不能为空")
|
|
|
-// }
|
|
|
-// // 学习模块进度
|
|
|
-// uid := c.Query("uid")
|
|
|
-// if len(uid) == 0 {
|
|
|
-// uid = apictx.User.ID
|
|
|
-// }
|
|
|
-// _, a, err := getLearnLogStatistics(apictx, db, uid)
|
|
|
-// return a, err
|
|
|
-// }
|
|
|
-
|
|
|
-// func getLearnLogStatistics(apictx *ApiSession, db string, uid string) (int, float64, error) {
|
|
|
-// learnLogStatistics := make([]*model.LearnLogStatistics, 0)
|
|
|
-// err := repo.RepoSeachDocs(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
-// Db: db,
|
|
|
-// CollectName: repo.CollectionLearnLogStatistics,
|
|
|
-// Query: repo.Map{"uid": uid},
|
|
|
-// Project: []string{"cid", "learnTime"},
|
|
|
-// }, &learnLogStatistics)
|
|
|
-// if err != nil {
|
|
|
-// log.Error(err)
|
|
|
-// return 0, 0.00, err
|
|
|
-// }
|
|
|
-// completeRate := 0.00
|
|
|
-// total := len(LearnLogSettings)
|
|
|
-// totalLearnTime := 0
|
|
|
-// if len(learnLogStatistics) > 0 {
|
|
|
-// for _, v := range learnLogStatistics {
|
|
|
-// totalLearnTime += v.LearnTime
|
|
|
-// limit, ok := LearnLogSettings[v.Cid]
|
|
|
-// if !ok {
|
|
|
-// limit = 10
|
|
|
-// }
|
|
|
-// rate := float64(v.LearnTime) / float64(limit)
|
|
|
-// if rate > 1 {
|
|
|
-// rate = 1
|
|
|
-// }
|
|
|
-// fmt.Println("pre_rate:", rate)
|
|
|
-// completeRate += rate / float64(total)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// fmt.Println("completeRate:", completeRate)
|
|
|
-// fmt.Println("uid_totalLearnTime:", totalLearnTime)
|
|
|
-// fmt.Println("----------------------------------------")
|
|
|
-// return totalLearnTime, completeRate, nil
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// var LearnLogSettings = map[string]int{
|
|
|
-// "65a8edf6a7ef2b18346edd8c": 10,
|
|
|
-// "65a8ee02a7ef2b18346edd8d": 10,
|
|
|
-// "65a8ee0da7ef2b18346edd8e": 10,
|
|
|
-// "65a8ee18a7ef2b18346edd8f": 10,
|
|
|
-// "65a8ee21a7ef2b18346edd90": 10,
|
|
|
-// "65a8ee2ba7ef2b18346edd91": 60,
|
|
|
-// "65a8ee39a7ef2b18346edd92": 10,
|
|
|
-// "65a8ee39a7ef2b18346edd93": 10,
|
|
|
-// "65a8ee39a7ef2b18346edd94": 60,
|
|
|
-// }
|