Normalise floats (don't use Inf in JSON)
This commit is contained in:
		@@ -4,6 +4,7 @@ package peppy
 | 
			
		||||
import (
 | 
			
		||||
	"database/sql"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"math"
 | 
			
		||||
 | 
			
		||||
	"git.zxq.co/ripple/ocl"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -49,5 +50,12 @@ func GetUser(c *gin.Context, db *sql.DB) {
 | 
			
		||||
	}
 | 
			
		||||
	user.Level = ocl.GetLevelPrecise(user.TotalScore)
 | 
			
		||||
 | 
			
		||||
	if math.IsInf(user.Accuracy, 0) {
 | 
			
		||||
		user.Accuracy = 0
 | 
			
		||||
	}
 | 
			
		||||
	if math.IsInf(user.Level, 0) {
 | 
			
		||||
		user.Level = 0
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	c.JSON(200, []osuapi.User{user})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@ package v1
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"database/sql"
 | 
			
		||||
	"math"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
@@ -129,6 +130,17 @@ type modeData struct {
 | 
			
		||||
	PP                    int     `json:"pp"`
 | 
			
		||||
	GlobalLeaderboardRank int     `json:"global_leaderboard_rank"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m modeData) Normalise() modeData {
 | 
			
		||||
	if math.IsInf(m.Level, 0) {
 | 
			
		||||
		m.Level = 0
 | 
			
		||||
	}
 | 
			
		||||
	if math.IsInf(m.Accuracy, 0) {
 | 
			
		||||
		m.Accuracy = 0
 | 
			
		||||
	}
 | 
			
		||||
	return m
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type userFullResponse struct {
 | 
			
		||||
	common.ResponseBase
 | 
			
		||||
	userData
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user