123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package model
- import "sort"
- type RequestCaptureFilter struct {
- StartTime string `form:"queryStartDate"`
- EndTime string `form:"queryEndDate"`
- QueryType string `form:"queryType"` //类型 month月 day日
- CaptureId int `form:"captureId"` //抓拍单元
- Type int `form:"type"` //归属地时,区分查看城市 1=省份 2=城市
- }
- type ResponseCaptureVehicleTotal struct {
- CountTime string `json:"countTime"` //统一时间
- CountT int `json:"countT"` //总报警
- }
- type ResponseCaptureSuggestSpeed struct {
- ID int `json:"id"`
- CaptureDirection int `json:"captureDirection"` //方向
- WayName string `json:"wayName"` //名称
- }
- type TmpCapture struct {
- Name string `json:"name"`
- Value int `json:"value"`
- }
- type TypeList struct {
- Name1 string `json:"name1"`
- Name2 string `json:"name2"`
- Name3 string `json:"name3"`
- Name4 string `json:"name4"`
- Name5 string `json:"name5"`
- Name6 string `json:"name6"`
- Name7 string `json:"name7"`
- Name8 string `json:"name8"`
- Name9 string `json:"name9"`
- Name10 string `json:"name10"`
- Name11 string `json:"name11"`
- Value1 int `json:"value1"`
- Value2 int `json:"value2"`
- Value3 int `json:"value3"`
- Value4 int `json:"value4"`
- Value5 int `json:"value5"`
- Value6 int `json:"value6"`
- Value7 int `json:"value7"`
- Value8 int `json:"value8"`
- Value9 int `json:"value9"`
- Value10 int `json:"value10"`
- Value11 int `json:"value11"`
- }
- type TmpCaptures struct {
- TmpCapturesData []TmpCapture
- CountTime string `json:"time"`
- TypeList
- }
- type IntSlice []TmpCapture
- func (p IntSlice) Len() int { return len(p) }
- func (p IntSlice) Less(i, j int) bool { return p[i].Value < p[j].Value }
- func (p IntSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
- //渲染出10个前10的数据
- func ViewData(tmp TmpCaptures) TmpCaptures {
- tmpNew := tmp
- for i, datum := range tmpNew.TmpCapturesData {
- switch i + 1 {
- case 1:
- tmpNew.Name1 = datum.Name
- tmpNew.Value1 = datum.Value
- case 2:
- tmpNew.Name2 = datum.Name
- tmpNew.Value2 = datum.Value
- case 3:
- tmpNew.Name3 = datum.Name
- tmpNew.Value3 = datum.Value
- case 4:
- tmpNew.Name4 = datum.Name
- tmpNew.Value4 = datum.Value
- case 5:
- tmpNew.Name5 = datum.Name
- tmpNew.Value5 = datum.Value
- case 6:
- tmpNew.Name6 = datum.Name
- tmpNew.Value6 = datum.Value
- case 7:
- tmpNew.Name7 = datum.Name
- tmpNew.Value7 = datum.Value
- case 8:
- tmpNew.Name8 = datum.Name
- tmpNew.Value8 = datum.Value
- case 9:
- tmpNew.Name9 = datum.Name
- tmpNew.Value9 = datum.Value
- case 10:
- tmpNew.Name10 = datum.Name
- tmpNew.Value10 = datum.Value
- case 11:
- tmpNew.Name11 = datum.Name
- tmpNew.Value11 = datum.Value
- }
- }
- return tmpNew
- }
- //排序功能
- func RankByWordCount(wordFrequencies map[string]int) PairList {
- pl := make(PairList, len(wordFrequencies))
- i := 0
- for k, v := range wordFrequencies {
- pl[i] = TmpCapture{k, v}
- i++
- }
- //从小到大排序
- //sort.Sort(pl)
- //从大到小排序
- sort.Sort(sort.Reverse(pl))
- return pl
- }
- type PairList []TmpCapture
- func (p PairList) Len() int { return len(p) }
- func (p PairList) Less(i, j int) bool { return p[i].Value < p[j].Value }
- func (p PairList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
- func IsContain(items []string, item string) bool {
- for _, eachItem := range items {
- if eachItem == item {
- return true
- }
- }
- return false
- }
|