capture.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package model
  2. import "sort"
  3. type RequestCaptureFilter struct {
  4. StartTime string `form:"queryStartDate"`
  5. EndTime string `form:"queryEndDate"`
  6. QueryType string `form:"queryType"` //类型 month月 day日
  7. CaptureId int `form:"captureId"` //抓拍单元
  8. Type int `form:"type"` //归属地时,区分查看城市 1=省份 2=城市
  9. }
  10. type ResponseCaptureVehicleTotal struct {
  11. CountTime string `json:"countTime"` //统一时间
  12. CountT int `json:"countT"` //总报警
  13. }
  14. type ResponseCaptureSuggestSpeed struct {
  15. ID int `json:"id"`
  16. CaptureDirection int `json:"captureDirection"` //方向
  17. WayName string `json:"wayName"` //名称
  18. }
  19. type TmpCapture struct {
  20. Name string `json:"name"`
  21. Value int `json:"value"`
  22. }
  23. type TypeList struct {
  24. Name1 string `json:"name1"`
  25. Name2 string `json:"name2"`
  26. Name3 string `json:"name3"`
  27. Name4 string `json:"name4"`
  28. Name5 string `json:"name5"`
  29. Name6 string `json:"name6"`
  30. Name7 string `json:"name7"`
  31. Name8 string `json:"name8"`
  32. Name9 string `json:"name9"`
  33. Name10 string `json:"name10"`
  34. Name11 string `json:"name11"`
  35. Value1 int `json:"value1"`
  36. Value2 int `json:"value2"`
  37. Value3 int `json:"value3"`
  38. Value4 int `json:"value4"`
  39. Value5 int `json:"value5"`
  40. Value6 int `json:"value6"`
  41. Value7 int `json:"value7"`
  42. Value8 int `json:"value8"`
  43. Value9 int `json:"value9"`
  44. Value10 int `json:"value10"`
  45. Value11 int `json:"value11"`
  46. }
  47. type TmpCaptures struct {
  48. TmpCapturesData []TmpCapture
  49. CountTime string `json:"time"`
  50. TypeList
  51. }
  52. type IntSlice []TmpCapture
  53. func (p IntSlice) Len() int { return len(p) }
  54. func (p IntSlice) Less(i, j int) bool { return p[i].Value < p[j].Value }
  55. func (p IntSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
  56. //渲染出10个前10的数据
  57. func ViewData(tmp TmpCaptures) TmpCaptures {
  58. tmpNew := tmp
  59. for i, datum := range tmpNew.TmpCapturesData {
  60. switch i + 1 {
  61. case 1:
  62. tmpNew.Name1 = datum.Name
  63. tmpNew.Value1 = datum.Value
  64. case 2:
  65. tmpNew.Name2 = datum.Name
  66. tmpNew.Value2 = datum.Value
  67. case 3:
  68. tmpNew.Name3 = datum.Name
  69. tmpNew.Value3 = datum.Value
  70. case 4:
  71. tmpNew.Name4 = datum.Name
  72. tmpNew.Value4 = datum.Value
  73. case 5:
  74. tmpNew.Name5 = datum.Name
  75. tmpNew.Value5 = datum.Value
  76. case 6:
  77. tmpNew.Name6 = datum.Name
  78. tmpNew.Value6 = datum.Value
  79. case 7:
  80. tmpNew.Name7 = datum.Name
  81. tmpNew.Value7 = datum.Value
  82. case 8:
  83. tmpNew.Name8 = datum.Name
  84. tmpNew.Value8 = datum.Value
  85. case 9:
  86. tmpNew.Name9 = datum.Name
  87. tmpNew.Value9 = datum.Value
  88. case 10:
  89. tmpNew.Name10 = datum.Name
  90. tmpNew.Value10 = datum.Value
  91. case 11:
  92. tmpNew.Name11 = datum.Name
  93. tmpNew.Value11 = datum.Value
  94. }
  95. }
  96. return tmpNew
  97. }
  98. //排序功能
  99. func RankByWordCount(wordFrequencies map[string]int) PairList {
  100. pl := make(PairList, len(wordFrequencies))
  101. i := 0
  102. for k, v := range wordFrequencies {
  103. pl[i] = TmpCapture{k, v}
  104. i++
  105. }
  106. //从小到大排序
  107. //sort.Sort(pl)
  108. //从大到小排序
  109. sort.Sort(sort.Reverse(pl))
  110. return pl
  111. }
  112. type PairList []TmpCapture
  113. func (p PairList) Len() int { return len(p) }
  114. func (p PairList) Less(i, j int) bool { return p[i].Value < p[j].Value }
  115. func (p PairList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
  116. func IsContain(items []string, item string) bool {
  117. for _, eachItem := range items {
  118. if eachItem == item {
  119. return true
  120. }
  121. }
  122. return false
  123. }