HeavyIntensityRain.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_ticker"
  4. "fmt"
  5. "sync"
  6. "time"
  7. )
  8. var (
  9. threshold float64 = 40.0
  10. apiKey = "f9d230f00d9ccdba49a97e043333d410"
  11. maxRetries = 5
  12. retryDelay = time.Second * 2
  13. )
  14. type Weather struct {
  15. WeatherID []int
  16. temperature float64
  17. humidity float64
  18. }
  19. // 定时任务触发器固定的
  20. func Topic() string {
  21. return pjisuv_ticker.TickerTopic
  22. }
  23. // ******* 禁止存在下划线_
  24. // 触发器标记
  25. func Label() string {
  26. return "HeavyIntensityRain"
  27. }
  28. func Rule(shareVars *sync.Map) {
  29. defer func() {
  30. if r := recover(); r != nil {
  31. fmt.Println("Recovered from panic:", r)
  32. }
  33. }()
  34. // 1 使用goroutine
  35. go func(shareVars *sync.Map) {
  36. // 2 定义触发器的间隔时间
  37. ticker := time.NewTicker(time.Duration(120) * time.Second)
  38. defer ticker.Stop()
  39. // 3 运行一个无限循环
  40. for {
  41. select {
  42. // 定时器触发时执行的代码
  43. case <-ticker.C:
  44. FinalCallback(shareVars)
  45. }
  46. }
  47. }(shareVars)
  48. }
  49. func FinalCallback(shareVars *sync.Map) {
  50. OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
  51. Weather2, ok2 := shareVars.Load("Weather")
  52. if ok && ok2 && OutsideWorkshopFlag.(bool) == true {
  53. NOwWeather := Weather2.(Weather)
  54. if NOwWeather.WeatherID != nil {
  55. for _, weatherid := range NOwWeather.WeatherID {
  56. if weatherid == 502 || weatherid == 503 || weatherid == 504 || weatherid == 511 || weatherid == 522 {
  57. eventLabel := "HeavyIntensityRain"
  58. fmt.Println(eventLabel)
  59. pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
  60. break
  61. }
  62. }
  63. }
  64. }
  65. }