Files
nCovTrack-Backend/service/statistics/statistics.go
2022-04-27 22:08:02 +08:00

61 lines
1.6 KiB
Go

package statistics
import (
"encoding/json"
"nCovTrack-Backend/global"
"nCovTrack-Backend/models"
"strings"
)
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 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{} {
checkCache()
if child {
return getEntireRedisList(rds_COUNTRY_LEVEL_CHILD_KEY)
}
return getEntireRedisList(rds_COUNTRY_LEVEL_KEY)
}
func GetChinaNCovStatistic() models.ChinaData {
checkCache()
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
}