예제 #1
0
파일: user.go 프로젝트: tokams/autograder
// IncScoreBy increases the total score with given amount.
func (u *User) IncScoreBy(score int) {
	u.lock.Lock()
	defer u.lock.Unlock()
	u.TotalScore += int64(score)
	u.Level = levels.FindLevel(u.TotalScore) // How to tackle level up notification?

	_, week := time.Now().ISOWeek()
	month := time.Now().Month()

	// updates weekly
	u.WeeklyScore[week] += int64(score)
	// updated monthly
	u.MonthlyScore[month] += int64(score)
}
예제 #2
0
파일: user.go 프로젝트: tokams/autograder
// DecScoreBy descreases the total score with given amount.
func (u *User) DecScoreBy(score int) {
	u.lock.Lock()
	defer u.lock.Unlock()
	if u.TotalScore-int64(score) > 0 {
		u.TotalScore -= int64(score)
	} else {
		u.TotalScore = 0
	}

	u.Level = levels.FindLevel(u.TotalScore)

	_, week := time.Now().ISOWeek()
	month := time.Now().Month()

	// updates weekly
	u.WeeklyScore[week] -= int64(score)
	// updated monthly
	u.MonthlyScore[month] -= int64(score)
}