-
Notifications
You must be signed in to change notification settings - Fork 3
/
schedule.go
107 lines (89 loc) · 2.51 KB
/
schedule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"time"
"github.com/aubm/interval"
)
func isTargetBusPassed(routeID string, stationID string, plateNo string) {
var currentPlateNo string
if currentPlateNo = getFirstPlateNo(routeID, stationID); currentPlateNo[len(currentPlateNo)-4:] == plateNo {
addDriverStop(StopInput{routeID, stationID}, GetOff)
isGetOutBusPassed(routeID, stationID, plateNo)
return
}
stop := interval.Start(func() {
currentPlateNo = getFirstPlateNo(routeID, stationID)
}, 6*time.Second)
ticker := time.Tick(2 * time.Second)
for range ticker {
if currentPlateNo[len(currentPlateNo)-4:] == plateNo {
addDriverStop(StopInput{routeID, stationID}, GetOff)
isGetOutBusPassed(routeID, stationID, plateNo)
stop()
}
}
}
func isGetOutBusPassed(routeID string, stationID string, plateNo string) {
var prePlateNo, currentPlateNo string
isAlert := false
stop := interval.Start(func() {
currentPlateNo = getFirstPlateNo(routeID, stationID)
}, 6*time.Second)
ticker := time.Tick(2 * time.Second)
for range ticker {
if prePlateNo == "" {
prePlateNo = currentPlateNo
continue
}
arrivalItem := GetBusArrivalOnlyOne(routeID, stationID)
if (arrivalItem.PredictTime1 <= 2) && (!isAlert) && (currentPlateNo[len(currentPlateNo)-4:] == plateNo) {
isAlert = true
GetOutAlert(routeID, stationID, plateNo)
deleteGetOut(routeID, stationID, plateNo[len(plateNo)-4:])
}
if prePlateNo != currentPlateNo {
deleteDriverStop(routeID, stationID)
stop()
break
}
}
}
func isBusPassed(routeID string, stationID string) {
var prePlateNo, currentPlateNo string
stop := interval.Start(func() {
currentPlateNo = getFirstPlateNo(routeID, stationID)
}, 10*time.Second)
ticker := time.Tick(5 * time.Second)
for range ticker {
if prePlateNo == "" {
prePlateNo = currentPlateNo
continue
}
if prePlateNo != currentPlateNo {
deleteDriverStop(routeID, stationID)
stop()
break
}
}
}
func getFirstPlateNo(routeID string, stationID string) string {
return GetBusArrivalOnlyOne(routeID, stationID).PlateNo1
}
func TargetObserver(routeID string, stationID string) {
isSuccess := false
stop := interval.Start(func() {
isSuccess = Observer(routeID, stationID)
}, 10*time.Second)
ticker := time.Tick(5 * time.Second)
for range ticker {
if isSuccess {
GetInAlert(routeID, stationID)
deleteGetIn(routeID, stationID)
stop()
break
}
}
}
func Observer(routeID string, stationID string) bool {
arrivalItem := GetBusArrivalOnlyOne(routeID, stationID)
return arrivalItem.PredictTime1 <= 2
}