diff --git a/db/gateway1.db b/db/gateway1.db new file mode 100644 index 0000000..b26e007 Binary files /dev/null and b/db/gateway1.db differ diff --git a/do_send_data.go b/do_send_data.go index e69527a..f8eae47 100644 --- a/do_send_data.go +++ b/do_send_data.go @@ -92,7 +92,9 @@ func build_data(code int, data []Device) []byte { case "其他": 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) return data_buf } diff --git a/loadconfig.go b/loadconfig.go index 6e5310d..9d1fbb8 100644 --- a/loadconfig.go +++ b/loadconfig.go @@ -13,7 +13,7 @@ type Traffic struct { } type Satisfaction struct { - SATISFACTION float32 `json:"satisfaction"` + SATISFACTION float64 `json:"satisfaction"` } type Conf struct { diff --git a/router.go b/router.go index 1e0935e..7b2c414 100644 --- a/router.go +++ b/router.go @@ -4,6 +4,7 @@ import ( "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" _ "github.com/mattn/go-sqlite3" + "math" "net/http" "strconv" ) @@ -163,10 +164,17 @@ func renliu_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}) } +func Round(f float64, n int) float64 { + n10 := math.Pow10(n) + return math.Trunc((f+0.5/n10)*n10) / n10 +} + type Seat_data struct { POSITIONLIST []interface{} `json:"positionList"` HASPERSONLIST []interface{} `json:"hasPersonList"`