-
Notifications
You must be signed in to change notification settings - Fork 14
/
scenarios.py
143 lines (101 loc) · 3.34 KB
/
scenarios.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from .queries import Query
from .utils import *
import logging
logger = logging.getLogger("autoquery-scenario")
highspeed_weights = {True: 60, False: 40}
def query_and_cancel(q: Query):
if random_from_weighted(highspeed_weights):
pairs = q.query_orders(types=tuple([0, 1]))
else:
pairs = q.query_orders(types=tuple([0, 1]), query_other=True)
if not pairs:
return
# (orderId, tripId)
pair = random_from_list(pairs)
order_id = q.cancel_order(order_id=pair[0])
if not order_id:
return
logger.info(f"{order_id} queried and canceled")
def query_and_collect(q: Query):
if random_from_weighted(highspeed_weights):
pairs = q.query_orders(types=tuple([1]))
else:
pairs = q.query_orders(types=tuple([1]), query_other=True)
if not pairs:
return
# (orderId, tripId)
pair = random_from_list(pairs)
order_id = q.collect_order(order_id=pair[0])
if not order_id:
return
logger.info(f"{order_id} queried and collected")
def query_and_execute(q: Query):
if random_from_weighted(highspeed_weights):
pairs = q.query_orders(types=tuple([1]))
else:
pairs = q.query_orders(types=tuple([1]), query_other=True)
if not pairs:
return
# (orderId, tripId)
pair = random_from_list(pairs)
order_id = q.enter_station(order_id=pair[0])
if not order_id:
return
logger.info(f"{order_id} queried and entered station")
def query_and_preserve(q: Query):
start = ""
end = ""
trip_ids = []
high_speed = random_from_weighted(highspeed_weights)
if high_speed:
start = "Shang Hai"
end = "Su Zhou"
high_speed_place_pair = (start, end)
trip_ids = q.query_high_speed_ticket(place_pair=high_speed_place_pair)
else:
start = "Shang Hai"
end = "Nan Jing"
other_place_pair = (start, end)
trip_ids = q.query_normal_ticket(place_pair=other_place_pair)
_ = q.query_assurances()
q.preserve(start, end, trip_ids, high_speed)
def query_and_consign(q: Query):
if random_from_weighted(highspeed_weights):
list = q.query_orders_all_info()
else:
list = q.query_orders_all_info(query_other=True)
if not list:
return
# (orderId, tripId)
res = random_from_list(list)
order_id = q.put_consign(res)
if not order_id:
return
logger.info(f"{order_id} queried and put consign")
def query_and_pay(q: Query):
if random_from_weighted(highspeed_weights):
pairs = q.query_orders(types=tuple([0, 1]))
else:
pairs = q.query_orders(types=tuple([0, 1]), query_other=True)
if not pairs:
return
# (orderId, tripId)
pair = random_from_list(pairs)
order_id = q.pay_order(pair[0], pair[1])
if not order_id:
return
logger.info(f"{order_id} queried and paid")
def query_and_rebook(q: Query):
if random_from_weighted(highspeed_weights):
pairs = q.query_orders(types=tuple([0, 1]))
else:
pairs = q.query_orders(types=tuple([0, 1]), query_other=True)
if not pairs:
return
# (orderId, tripId)
pair = random_from_list(pairs)
order_id = q.cancel_order(order_id=pair[0])
if not order_id:
return
q.rebook_ticket(pair[0], pair[1], pair[1])
logger.info(f"{order_id} queried and rebooked")