评价bug

This commit is contained in:
kk 2019-02-15 19:14:13 +08:00
parent 3ec9a23bd0
commit b8b5e16eb1
4 changed files with 13 additions and 3 deletions

BIN
db/gateway1.db Normal file

Binary file not shown.

View File

@ -92,7 +92,9 @@ func build_data(code int, data []Device) []byte {
case "其他": case "其他":
bad++ bad++
} }
satisfaction_data.SATISFACTION = good / (good + bad) var data float64
data = good / (good + bad)
satisfaction_data.SATISFACTION = Round(data, 2)
data_buf, _ := json.Marshal(R_data) data_buf, _ := json.Marshal(R_data)
return data_buf return data_buf
} }

View File

@ -13,7 +13,7 @@ type Traffic struct {
} }
type Satisfaction struct { type Satisfaction struct {
SATISFACTION float32 `json:"satisfaction"` SATISFACTION float64 `json:"satisfaction"`
} }
type Conf struct { type Conf struct {

View File

@ -4,6 +4,7 @@ import (
"github.com/gin-contrib/cors" "github.com/gin-contrib/cors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"math"
"net/http" "net/http"
"strconv" "strconv"
) )
@ -163,10 +164,17 @@ func renliu_api(c *gin.Context) {
} }
func pj_api(c *gin.Context) { func pj_api(c *gin.Context) {
satisfaction_data.SATISFACTION = good / (good + bad) var data float64
data = good / (good + bad)
satisfaction_data.SATISFACTION = Round(data, 2)
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "data": satisfaction_data}) c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "data": satisfaction_data})
} }
func Round(f float64, n int) float64 {
n10 := math.Pow10(n)
return math.Trunc((f+0.5/n10)*n10) / n10
}
type Seat_data struct { type Seat_data struct {
POSITIONLIST []interface{} `json:"positionList"` POSITIONLIST []interface{} `json:"positionList"`
HASPERSONLIST []interface{} `json:"hasPersonList"` HASPERSONLIST []interface{} `json:"hasPersonList"`