|
|
|
@ -5,8 +5,10 @@ import (
|
|
|
|
|
"dsBigData/Utils/CommonUtil"
|
|
|
|
|
"dsBigData/Utils/EsUtil"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/olivere/elastic/v7"
|
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
@ -42,14 +44,18 @@ func GetTeacherCountAggsXb(schoolId string) ([]TeacherModel.TeacherCountXb, erro
|
|
|
|
|
|
|
|
|
|
resByte, err := json.Marshal(result.Aggregations)
|
|
|
|
|
resStr := string(resByte)
|
|
|
|
|
|
|
|
|
|
totalCount := CommonUtil.ConvertInt64ToString(result.TotalHits())
|
|
|
|
|
totalCountFloat, _ := strconv.ParseFloat(totalCount, 64)
|
|
|
|
|
var teacherCountXbArr []TeacherModel.TeacherCountXb
|
|
|
|
|
resCount := gjson.Get(resStr, "xb.buckets.#")
|
|
|
|
|
for i := 0; i < int(resCount.Num); i++ {
|
|
|
|
|
var teacherCountXb TeacherModel.TeacherCountXb
|
|
|
|
|
teacherCountXb.XbName = gjson.Get(resStr, "xb.buckets."+CommonUtil.ConvertIntToString(i)+".key").Str
|
|
|
|
|
teacherCountXb.Count = int(gjson.Get(resStr, "xb.buckets."+CommonUtil.ConvertIntToString(i)+".doc_count").Num)
|
|
|
|
|
|
|
|
|
|
percent := gjson.Get(resStr, "xb.buckets."+CommonUtil.ConvertIntToString(i)+".doc_count").Num / totalCountFloat * 100
|
|
|
|
|
percentFloat, _ := strconv.ParseFloat(fmt.Sprintf("%.0f", percent), 64)
|
|
|
|
|
percentString := CommonUtil.ConverFloat64ToString(percentFloat)
|
|
|
|
|
teacherCountXb.Percent = percentString + "%"
|
|
|
|
|
teacherCountXbArr = append(teacherCountXbArr, teacherCountXb)
|
|
|
|
|
}
|
|
|
|
|
return teacherCountXbArr, nil
|
|
|
|
|