feat: statistics: finish dev
This commit is contained in:
@@ -2,41 +2,57 @@ package statistics
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"nCovTrack-Backend/global"
|
||||
"nCovTrack-Backend/utils"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"nCovTrack-Backend/models"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetChinaNCovStatistics() func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
resp := utils.GetWhioutHeader(global.CHINA_NCOV_STATISTIC_URL)
|
||||
var nCovRes map[string]string
|
||||
json.Unmarshal([]byte(resp), &nCovRes)
|
||||
fmt.Println(nCovRes)
|
||||
var nCovResData interface{}
|
||||
json.Unmarshal([]byte(nCovRes["data"]), &nCovResData)
|
||||
c.JSON(http.StatusOK, nCovResData)
|
||||
func GetAllProvienceData(sort string) []interface{} {
|
||||
checkCache()
|
||||
if sort == SORT_TODAY_CONFIRM {
|
||||
return getEntireRedisList(rds_PROVIENCE_LEVEL_TODAY_CONFIRM_KEY)
|
||||
}
|
||||
if sort == SORT_TOTAL_CONFIRM {
|
||||
return getEntireRedisList(rds_PROVIENCE_LEVEL_TOTAL_CONFIRM_KEY)
|
||||
}
|
||||
if sort == SORT_NOW_CONFIRM {
|
||||
return getEntireRedisList(rds_PROVIENCE_LEVEL_NOW_CONFIRM_KEY)
|
||||
}
|
||||
return getEntireRedisList(rds_PROVIENCE_LEVEL_CHILD_KEY)
|
||||
}
|
||||
|
||||
func GetChinaNCovStatistic() func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
//resp := utils.GetWhioutHeader(global.CHINA_NCOV_STATISTIC_URL)
|
||||
var nCovRes map[string]string
|
||||
//err := json.Unmarshal([]byte(resp), &nCovRes)
|
||||
//fmt.Println(nCovRes)
|
||||
//if err != nil {
|
||||
// panic(err)
|
||||
//}
|
||||
//var nCovResData interface{}
|
||||
//err := json.Unmarshal([]byte(nCovRes["data"]), &nCovResData)
|
||||
//if err != nil {
|
||||
// panic(err)
|
||||
//}
|
||||
nCovRes["1"] = "1"
|
||||
c.JSON(http.StatusOK, nCovRes)
|
||||
func GetAllCityData(sort string) []interface{} {
|
||||
checkCache()
|
||||
if sort == SORT_TODAY_CONFIRM {
|
||||
return getEntireRedisList(rds_CITY_LEVEL_TODAY_CONFIRM_KEY)
|
||||
}
|
||||
if sort == SORT_TOTAL_CONFIRM {
|
||||
return getEntireRedisList(rds_CITY_LEVEL_TOTAL_CONFIRM_KEY)
|
||||
}
|
||||
if sort == SORT_NOW_CONFIRM {
|
||||
return getEntireRedisList(rds_CITY_LEVEL_NOW_CONFIRM_KEY)
|
||||
}
|
||||
return getEntireRedisList(rds_CITY_LEVEL_CHILD_KEY)
|
||||
}
|
||||
|
||||
func GetCountryData(child bool) []interface{} {
|
||||
if child {
|
||||
return getEntireRedisList(rds_COUNTRY_LEVEL_CHILD_KEY)
|
||||
}
|
||||
return getEntireRedisList(rds_COUNTRY_LEVEL_KEY)
|
||||
}
|
||||
|
||||
func GetChinaNCovStatistic() models.ChinaData {
|
||||
data := models.ChinaData{}
|
||||
json.Unmarshal([]byte(global.Redis.Get(rds_CHINA_ADD_KEY).Val()), &data.ChinaAdd)
|
||||
json.Unmarshal([]byte(global.Redis.Get(rds_CHINA_TOTAL_KEY).Val()), &data.ChinaTotal)
|
||||
return data
|
||||
}
|
||||
|
||||
func getEntireRedisList(key string) []interface{} {
|
||||
var data []interface{}
|
||||
dataStrArr := global.Redis.LRange(key, 0, -1).Val()
|
||||
dataStr := "[" + strings.Join(dataStrArr[:], ",") + "]"
|
||||
json.Unmarshal([]byte(dataStr), &data)
|
||||
return data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user