-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlive.py
182 lines (144 loc) · 3.96 KB
/
live.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from os import remove
import pyautogui as pygu
from time import sleep
import pyperclip
import json
# Anotar pedidos
## verificar se pedido já está anotado
# Preparar pedidos
# Verificar Finalizados, entrega
# Remover pedido da lista
ingredientes = [
{
"id": 1,
"nome": "Café",
"img": "assets/ing_cafe.JPG"
},
{
"id": 2,
"nome": "Açucar",
"img": "assets/ing_acucar.JPG"
},
{
"id": 3,
"nome": "Chá",
"img": "assets/ing_cha.JPG"
}
]
cardapio = [
{
"id": 1,
"nome": 'Café Simples',
"img": 'assets/cafe_simples.JPG',
"ingredientes": [1]
},
{
"id": 2,
"nome": 'Café Doce',
"img": 'assets/cafe_doce.JPG',
"ingredientes": [1,2]
},
{
"id": 3,
"nome": 'Chá Doce',
"img": 'assets/cha_doce.JPG',
"ingredientes": [3,2]
},
{
"id": 4,
"nome": 'Chá Duplo',
"img": 'assets/cha_duplo.JPG',
"ingredientes": [3,3]
},
{
"id": 5,
"nome": 'Café Duplo',
"img": 'assets/cafe_duplo.JPG',
"ingredientes": [1,1]
}
]
cafeteiras = [
{
"quantidade": 1,
"img": "assets/cafeteira.JPG"
}
]
pedidos = []
preparos = 0
def getQuantidadeCafeteira():
global cafeteiras
for c in cafeteiras:
pos = pygu.locateOnScreen(c['img'], confidence=.8)
if (pos):
return c['quantidade']
return 0
def verificarPedido(pedido, pedidos):
for p in pedidos:
if pedido == p:
return 1
return 0
def anotarPedidos(pedidos):
print("Anotar Pedidos")
for c in cardapio:
pos = pygu.locateOnScreen(c['img'], confidence=.8)
if (pos):
print('Pedido encontrado: ' + str(c['nome']))
pedido = json.dumps({"id":c['id'], "x":str(pos[0]), "y": str(pos[1])})
if(verificarPedido(pedido, pedidos) == False):
print("Adicionando pedido a lista")
pedidos.append(pedido)
def getIngrediente(id, ingredientes):
for i in ingredientes:
if i['id'] == id:
return i
return 0
def getItemCardapio(id, cardapio):
for c in cardapio:
if c['id'] == id:
return c
return 0
def prepararPedidos(pedidos, cardapio, ingredientes):
global preparos
print("Preparando Pedidos")
for p in pedidos:
qtdCafeteiras = getQuantidadeCafeteira()
if (preparos >= qtdCafeteiras): return 0
pedido = json.loads(p)
item = getItemCardapio(pedido['id'], cardapio)
if (item == False): return 0
for i in item['ingredientes']:
ing = getIngrediente(i, ingredientes)
if (ing == False): return 0
pos = pygu.locateOnScreen(ing['img'], confidence=.8)
if (pos):
print("Adicionando ingrediente: " + ing['nome'])
pygu.moveTo(pos[0]+(pos[2]/2), pos[1]+(pos[3]/2), duration=0.2)
sleep(1)
pygu.click()
pos_preparo = pygu.locateOnScreen("assets/preparo.JPG", confidence=.8)
if(pos_preparo):
pygu.moveTo(pos_preparo[0]+(pos_preparo[2]/2), pos_preparo[1]+(pos_preparo[3]/2), duration=0.2)
sleep(1)
pygu.click()
preparos+=1
def entregarFinalizados(pedidos):
global preparos
print("Entregando finalizados")
pos = pygu.locateOnScreen("assets/pronto.JPG", confidence=.8)
if(pos):
pygu.moveTo(pos[0]+(pos[2]/2), pos[1]+(pos[3]/2), duration=0.2)
sleep(1)
pygu.click()
print(pedidos)
pedidos.pop(0)
preparos-=1
print(pedidos)
sleep(1)
def removerPedido():
print("Removendo Pedido")
while 1:
anotarPedidos(pedidos)
prepararPedidos(pedidos, cardapio, ingredientes)
entregarFinalizados(pedidos)
print(pedidos)
sleep(5)