Browse Source

图表数据

v2
herenshan112 4 months ago
parent
commit
9176d52b20
  1. 10
      api/version1/customChartesing/getSearchTime.go
  2. 4
      api/version1/customChartesing/pieChart.go
  3. 182
      api/version1/customChartesing/radar.go
  4. 7
      overall/publicmethod/technique.go

10
api/version1/customChartesing/getSearchTime.go

@ -41,6 +41,7 @@ func (c *ChartInfo) JieXiSearchTime() (xAlist []string) {
starYearInt, _ := strconv.ParseInt(starYear, 10, 64) starYearInt, _ := strconv.ParseInt(starYear, 10, 64)
endYearInt, _ := strconv.ParseInt(endYear, 10, 64) endYearInt, _ := strconv.ParseInt(endYear, 10, 64)
buJinzhi := endYearInt - starYearInt buJinzhi := endYearInt - starYearInt
fmt.Printf("年度计算:%v-------->%v-------->%v\n\n", endYearInt, starYearInt, buJinzhi)
if buJinzhi == 0 { if buJinzhi == 0 {
xAlist = append(xAlist, fmt.Sprintf("%v", buJinzhi)) xAlist = append(xAlist, fmt.Sprintf("%v", buJinzhi))
} else { } else {
@ -54,27 +55,30 @@ func (c *ChartInfo) JieXiSearchTime() (xAlist []string) {
beginMonth := publicmethod.UnixTimeToDay(startTime, 17) beginMonth := publicmethod.UnixTimeToDay(startTime, 17)
endYear := publicmethod.UnixTimeToDay(endTime, 16) endYear := publicmethod.UnixTimeToDay(endTime, 16)
endMonth := publicmethod.UnixTimeToDay(endTime, 17) endMonth := publicmethod.UnixTimeToDay(endTime, 17)
// fmt.Printf("年度计算:%v-------->%v-------->%v-------->%v\n\n", starYear, beginMonth, endYear, endMonth)
if starYear == endYear && beginMonth == endMonth { if starYear == endYear && beginMonth == endMonth {
xAlist = append(xAlist, fmt.Sprintf("%v-%v", starYear, beginMonth)) xAlist = append(xAlist, fmt.Sprintf("%v-%v", starYear, beginMonth))
} else if starYear == endYear && beginMonth != endMonth { } else if starYear == endYear && beginMonth != endMonth {
beginMonthInt, _ := strconv.ParseInt(beginMonth, 10, 64) beginMonthInt, _ := strconv.ParseInt(beginMonth, 10, 64)
endMonthInt, _ := strconv.ParseInt(endMonth, 10, 64) endMonthInt, _ := strconv.ParseInt(endMonth, 10, 64)
for i := beginMonthInt; i <= endMonthInt; i++ { for i := beginMonthInt; i <= endMonthInt; i++ {
xAlist = append(xAlist, fmt.Sprintf("%v-%v", starYear, beginMonthInt+i)) xAlist = append(xAlist, fmt.Sprintf("%v-%v", starYear, i))
} }
// fmt.Printf("年度计算:%v-----1--->%v-------->%v-------->%v\n\n", starYear, beginMonthInt, endYear, xAlist)
} else { } else {
beginMonthInt, _ := strconv.ParseInt(beginMonth, 10, 64) beginMonthInt, _ := strconv.ParseInt(beginMonth, 10, 64)
endMonthInt, _ := strconv.ParseInt(endMonth, 10, 64) endMonthInt, _ := strconv.ParseInt(endMonth, 10, 64)
// fmt.Printf("年度计算:%v-----2--->%v-------->%v-------->%v\n\n", starYear, beginMonthInt, endYear, endMonthInt)
for i := beginMonthInt; i <= 12; i++ { for i := beginMonthInt; i <= 12; i++ {
xAlist = append(xAlist, fmt.Sprintf("%v-%v", starYear, beginMonthInt+i)) xAlist = append(xAlist, fmt.Sprintf("%v-%v", starYear, beginMonthInt+i))
} }
var j int64 var j int64
for j = 0; j <= endMonthInt; j++ { for j = 0; j < endMonthInt; j++ {
xAlist = append(xAlist, fmt.Sprintf("%v-%v", endYear, j)) xAlist = append(xAlist, fmt.Sprintf("%v-%v", endYear, j))
} }
} }
// fmt.Printf("年度计算:%v-----3--->%v-------->%v-------->%v\n\n", starYear, xAlist, endYear, xAlist)
case "day": case "day":
starday := publicmethod.UnixTimeToDay(startTime, 14) starday := publicmethod.UnixTimeToDay(startTime, 14)
endday := publicmethod.UnixTimeToDay(endTime, 14) endday := publicmethod.UnixTimeToDay(endTime, 14)

4
api/version1/customChartesing/pieChart.go

@ -373,14 +373,14 @@ func (c *ChartInfo) PieDataAnaly(x XAxisInfo, y []YAxisInfo, val interface{}, ch
// 处理主数据 // 处理主数据
func (s *SendPicInfo) picMasterDataAnaly(xField, keyName string, fathreName, val interface{}) { func (s *SendPicInfo) picMasterDataAnaly(xField, keyName string, fathreName, val interface{}) {
fmt.Printf("处理主数据----->%v-----------%v\n\n\n", keyName, fathreName) // fmt.Printf("处理主数据----->%v-----------%v\n\n\n", keyName, fathreName)
if yVal, isOk := val.([]map[string]interface{}); isOk { if yVal, isOk := val.([]map[string]interface{}); isOk {
jsq := 0 jsq := 0
var masterInfo PicChartInfo var masterInfo PicChartInfo
masterInfo.Name = publicmethod.TypeToInterface(fathreName) masterInfo.Name = publicmethod.TypeToInterface(fathreName)
for _, mv := range yVal { for _, mv := range yVal {
if xVal, isOk := mv[xField]; isOk { if xVal, isOk := mv[xField]; isOk {
fmt.Printf("处理主数据--2323--->%v-----------%v\n\n\n", xVal, fathreName) // fmt.Printf("处理主数据--2323--->%v-----------%v\n\n\n", xVal, fathreName)
xValStr := publicmethod.TypeToInterface(xVal) xValStr := publicmethod.TypeToInterface(xVal)
if xValStr == keyName { if xValStr == keyName {
jsq++ jsq++

182
api/version1/customChartesing/radar.go

@ -5,6 +5,7 @@ import (
"appPlatform/overall/publicmethod" "appPlatform/overall/publicmethod"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"time" "time"
) )
@ -29,13 +30,151 @@ func (c *ChartInfo) radarChart(val interface{}, untis []customerform.MasterStruc
} }
func (c *ChartInfo) RadarTimeDataAnaly(x XAxisInfo, y []YAxisInfo, val interface{}, chartType string) (charData RadarInfo) { func (c *ChartInfo) RadarTimeDataAnaly(x XAxisInfo, y []YAxisInfo, val interface{}, chartType string) (charData RadarInfo) {
tayTime := time.Now().Unix() tayTime := time.Now().Unix()
searchTime := c.JieXiSearchTime()
fmt.Printf("时间集---1-->%v\n\n", searchTime)
switch x.TimeType { switch x.TimeType {
case "year": case "year":
tayTimeing := int(time.Now().Year())
var timeList []string
// for i := 0; i <= tayTimeing; i++ {
timeList = append(timeList, fmt.Sprintf("%v", tayTimeing))
// }
if len(searchTime) > 0 {
timeList = searchTime
}
var jiSuanVal []RadarTimeInfo
fmt.Printf("时间集----->%v\n\n", timeList)
// for _, v := range y {
// charData.Legend = append(charData.Legend, v.OldTitle)
var newVal []map[string]interface{}
for _, tv := range timeList {
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01-01 00:00:00", tv))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-12-31 23:59:59", tv))
if yVal, isOk := val.([]map[string]interface{}); isOk {
for _, mv := range yVal {
if xVal, isOk := mv[x.Field]; isOk {
var begTime int64
var eldTime int64
pageTime, _ := publicmethod.StringToInt64(xVal)
if publicmethod.GetIntLength(pageTime) >= 13 {
begTime = startTime * 1000
eldTime = endTime * 1000
}
if begTime <= pageTime && pageTime <= eldTime {
// fmt.Printf("维度--3---》%v---》%v---》%v\n\n", tv, begTime <= pageTime, pageTime <= eldTime)
newVal = append(newVal, mv)
}
}
}
}
var timeData RadarTimeInfo
timeData.XName = tv
timeData.DataVal = newVal
jiSuanVal = append(jiSuanVal, timeData)
// fmt.Printf("维度--1---》%v---》%v\n\n", tv, len(newVal))
}
// jsonVal, _ := json.Marshal(jiSuanVal)
// fmt.Printf("维度-----》%v\n\n", string(jsonVal))
charData.ParsingData(jiSuanVal, y)
case "month":
var timeList []string
yearVal := publicmethod.UnixTimeToDay(tayTime, 16)
tayTimeing := int(time.Now().Month())
for i := 1; i <= tayTimeing; i++ {
timeList = append(timeList, fmt.Sprintf("%v-%v", yearVal, i))
}
if len(searchTime) > 0 {
timeList = searchTime
}
var jiSuanVal []RadarTimeInfo
// for _, v := range y {
// charData.Legend = append(charData.Legend, v.OldTitle)
var newVal []map[string]interface{}
for _, tv := range timeList {
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v-01 00:00:00", tv))
nyAry := strings.Split(tv, "-")
year, _ := strconv.Atoi(nyAry[0])
mon, _ := strconv.Atoi(nyAry[len(nyAry)-1])
endTime := publicmethod.GetDaysInMonth(year, mon)
fmt.Printf("维度--1---》%v---》%v---》%v\n\n", startTime, mon, endTime)
// endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v- 23:59:59", tv))
if yVal, isOk := val.([]map[string]interface{}); isOk {
for _, mv := range yVal {
if xVal, isOk := mv[x.Field]; isOk {
var begTime int64
var eldTime int64
pageTime, _ := publicmethod.StringToInt64(xVal)
if publicmethod.GetIntLength(pageTime) >= 13 {
begTime = startTime * 1000
eldTime = endTime.AllTime * 1000
}
if begTime <= pageTime && pageTime <= eldTime {
// fmt.Printf("维度--3---》%v---》%v---》%v\n\n", tv, begTime <= pageTime, pageTime <= eldTime)
newVal = append(newVal, mv)
}
}
}
}
var timeData RadarTimeInfo
timeData.XName = tv
timeData.DataVal = newVal
jiSuanVal = append(jiSuanVal, timeData)
// fmt.Printf("维度--1---》%v---》%v\n\n", tv, len(newVal))
}
// jsonVal, _ := json.Marshal(jiSuanVal)
// fmt.Printf("维度-----》%v\n\n", string(jsonVal))
charData.ParsingData(jiSuanVal, y)
// }y
case "day": case "day":
case "hour": tayTimeing := int(time.Now().Day())
case "minute": yearVal := publicmethod.UnixTimeToDay(tayTime, 15)
case "second": var timeList []string
case "ymdhms": for i := 1; i <= tayTimeing; i++ {
timeList = append(timeList, fmt.Sprintf("%v-%v", yearVal, i))
}
if len(searchTime) > 0 {
timeList = searchTime
}
var jiSuanVal []RadarTimeInfo
// for _, v := range y {
// charData.Legend = append(charData.Legend, v.OldTitle)
var newVal []map[string]interface{}
for _, tv := range timeList {
startTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 00:00:00", tv))
endTime := publicmethod.DateToTimeStampOld(fmt.Sprintf("%v 23:59:59", tv))
if yVal, isOk := val.([]map[string]interface{}); isOk {
for _, mv := range yVal {
if xVal, isOk := mv[x.Field]; isOk {
var begTime int64
var eldTime int64
pageTime, _ := publicmethod.StringToInt64(xVal)
if publicmethod.GetIntLength(pageTime) >= 13 {
begTime = startTime * 1000
eldTime = endTime * 1000
}
if begTime <= pageTime && pageTime <= eldTime {
fmt.Printf("维度--3---》%v---》%v---》%v\n\n", tv, begTime <= pageTime, pageTime <= eldTime)
newVal = append(newVal, mv)
}
}
}
}
var timeData RadarTimeInfo
timeData.XName = tv
timeData.DataVal = newVal
jiSuanVal = append(jiSuanVal, timeData)
fmt.Printf("维度--1---》%v---》%v\n\n", tv, len(newVal))
}
// jsonVal, _ := json.Marshal(jiSuanVal)
// fmt.Printf("维度-----》%v\n\n", string(jsonVal))
charData.ParsingData(jiSuanVal, y)
// }y
// case "hour":
// case "minute":
// case "second":
// case "ymdhms":
default: default:
yearVal := publicmethod.UnixTimeToDay(tayTime, 16) yearVal := publicmethod.UnixTimeToDay(tayTime, 16)
yearValInt, _ := strconv.Atoi(yearVal) yearValInt, _ := strconv.Atoi(yearVal)
@ -73,6 +212,23 @@ func (c *ChartInfo) RadarTimeDataAnaly(x XAxisInfo, y []YAxisInfo, val interface
return return
} }
func (r *RadarInfo) ParsingNewData(timeVal []RadarTimeInfo, y YAxisInfo) {
switch y.Method {
case 2:
r.AverageValueesTime(y, timeVal, y.Format)
case 3:
r.StatisticalQuantityesTime(y, timeVal, y.Format)
case 4:
r.RemoveDuplicateCountssTime(y, timeVal, y.Format)
case 5:
r.maxDataesTime(y, timeVal, y.Format)
case 6:
r.minDataesTime(y, timeVal, y.Format)
default:
r.sumDataesTime(y, timeVal, y.Format)
}
}
/* /*
* *
@ 作者: 秦东 @ 作者: 秦东
@ -334,7 +490,8 @@ func (r *RadarInfo) sumDataesTime(y YAxisInfo, timeVal []RadarTimeInfo, format i
if err == nil { if err == nil {
isWrite = false isWrite = false
if minVal <= sumVal { if minVal <= sumVal {
r.Indicator[ri].Max = sumVal
r.Indicator[ri].Max = sumVal + TianJiaCanshu(sumVal)
} }
} }
} }
@ -349,6 +506,21 @@ func (r *RadarInfo) sumDataesTime(y YAxisInfo, timeVal []RadarTimeInfo, format i
r.DataList = append(r.DataList, serData) r.DataList = append(r.DataList, serData)
} }
func TianJiaCanshu(val float64) float64 {
if val > 100000 {
return 100000
} else if val > 10000 {
return 10000
} else if val > 1000 {
return 1000
} else if val > 100 {
return 100
} else {
return 10
}
return 0
}
// 普通字段 // 普通字段
func (c *ChartInfo) RadarDataAnaly(x XAxisInfo, y []YAxisInfo, val interface{}, chartType string, untis []customerform.MasterStruct) (charData RadarInfo) { func (c *ChartInfo) RadarDataAnaly(x XAxisInfo, y []YAxisInfo, val interface{}, chartType string, untis []customerform.MasterStruct) (charData RadarInfo) {
var timeList []string //根据维度分组 var timeList []string //根据维度分组

7
overall/publicmethod/technique.go

@ -2997,7 +2997,12 @@ func RemoveDuplicate[T GenericityVariable](ary []T) []T {
// 获得月份最后一天,最后一秒 // 获得月份最后一天,最后一秒
func GetDaysInMonth(nextYear int, nextMonth int) DateTimeTotimes { func GetDaysInMonth(nextYear int, nextMonth int) DateTimeTotimes {
firstDayOfNextMonth := time.Date(nextYear, time.Month(nextMonth), 1, 0, 0, 0, 0, time.UTC) crueMonth := nextMonth + 1
if crueMonth > 12 {
crueMonth = crueMonth - 12
nextYear = nextYear + 1
}
firstDayOfNextMonth := time.Date(nextYear, time.Month(crueMonth), 1, 0, 0, 0, 0, time.UTC)
lastDayOfThisMonth := firstDayOfNextMonth.Add(-1 * time.Second) lastDayOfThisMonth := firstDayOfNextMonth.Add(-1 * time.Second)
// fmt.Println("本月最后一天时间:", lastDayOfThisMonth) // fmt.Println("本月最后一天时间:", lastDayOfThisMonth)
dates := lastDayOfThisMonth.Format("2006-01-02 15:04:05") dates := lastDayOfThisMonth.Format("2006-01-02 15:04:05")

Loading…
Cancel
Save