123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package main
- import (
- "cicv-data-closedloop/pjisuv_ticker"
- "fmt"
- "sync"
- "time"
- )
- var (
- threshold float64 = 0.4
- )
- // 定时任务触发器固定的
- func Topic() string {
- return pjisuv_ticker.TickerTopic
- }
- // ******* 禁止存在下划线_
- // 触发器标记
- func Label() string {
- return "Cadence"
- }
- func Rule(shareVars *sync.Map) {
- defer func() {
- if r := recover(); r != nil {
- fmt.Println("Recovered from panic:", r)
- }
- }()
- // 1 使用goroutine
- go func(shareVars *sync.Map) {
- // 2 定义触发器的间隔时间
- ticker := time.NewTicker(time.Duration(2) * time.Second)
- defer ticker.Stop()
- // 3 运行一个无限循环
- for {
- select {
- // 定时器触发时执行的代码
- case <-ticker.C:
- FinalCallback(shareVars)
- }
- }
- }(shareVars)
- }
- func countChanges(slice []float64) int {
- count := 0
- lable1:
- for i := 0; i < len(slice); {
- if slice[i] <= -threshold || slice[i] > threshold {
- for j := 0; j < len(slice)-i-1; j++ {
- if (slice[i] <= -threshold && slice[1+i+j] >= threshold) || (slice[i] >= threshold && slice[1+i+j] <= -threshold) {
- count++
- i = i + j + 1
- continue lable1
- }
- }
- break lable1
- } else {
- i++
- }
- }
- return count
- }
- func FinalCallback(shareVars *sync.Map) {
- OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag")
- AccelXSlice, ok1 := shareVars.Load("AccelXSlice")
- if ok && ok1 && OutsideWorkshopFlag.(bool) == true {
- count := countChanges(AccelXSlice.([]float64))
- if count >= 3 {
- event_lable := "Cadence"
- fmt.Println(event_lable)
- pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()}
- }
- if len(AccelXSlice.([]float64)) >= 500 {
- AccelXSlice = []float64{}
- shareVars.Store("AccelXSlice", AccelXSlice)
- }
- }
- }
|