Files
storage_fresco/TQUI.py
2019-06-05 09:40:06 +00:00

334 lines
16 KiB
Python

class TQUI:
def tqui (self, ret_val):
_quit = 0
DB_con = self.connections['DB']
self.log ( " DT_handler : TQUI at %(location)s box %(box_nr)s src %(src_id)s dst %(dst_id)s state %(state)s" % ret_val)
# TQUI Telegram --> update DB
# 01 Order Complete, 11 Order Complete Dummy detected
if (ret_val ['state'] == "01"):
self.message (3, ' DT_handler : TQUI -- Order complete')
if int (ret_val['box_nr'] >= 0):
if ret_val['location'] in ['RFZ1', 'RFZ2']:
DB_con.deletetransport (ret_val['location'], int (ret_val['box_nr']))
else:
self.message (3, ' DT_handler : TQUI invalid Position - IGNORE')
if ret_val['location'] in ['RFZ1', 'RFZ2']:
self.message (3, ' DT_handler : TQUI location is %(location)s for box %(box_nr)s into storage %(dst_id)s' % ret_val)
self.message (3, ' DT_handler : TQUI -- Update Box remove ghosts')
#Use Timestamp on storage moves
#Disabled Setting Insertiondate
_rfzts = None
#Other Transport
DB_con.setboxtimefillgap (ret_val['dst_id'], int (ret_val['box_nr']), _rfzts and _rfzts[0] or '')
#Box was From I-Point
if ret_val['src_id'][0:2] == 'I0':
DB_con.removebox ('Inqueue', int (ret_val['box_nr']))
ibox = None
try:
ibox = DB_con.searchbox (int (ret_val['box_nr']), 'T001')
except:
print ("Geht ned")
try:
if ibox:
ibid, ibboxnr, ibarticle, iblotnr, iblotnr2, ibduedate, ibpieces, ibx, iby, ibz, ibrfzts = ibox [0]
##DB_con.addexpressjob (ibarticle)
except:
print ("Geht ned")
else:
DB_con.removebox (ret_val['src_id'], int (ret_val['box_nr']))
if ret_val['src_id'] != 'IRFZ' and ret_val['dst_id'][0:2] == 'OP':
#Checking Transportmatrix what destination is kind of
self.message (6, ' DT_handler : TQUI for Transport to Outpoint')
DB_con.deleteoutgoingbox (int (ret_val['box_nr']), queueid = ret_val['dst_id'])
for dest, rfzNr, rfzOut, mode, prio in self.transportmatrix['dstbysrc'][ret_val['src_id']]:
if 'RFZ%d' % rfzNr == ret_val['location'] and 'OP%s' % rfzOut == ret_val['dst_id']:
#FixMe check also source
self.message (6, ' DT_handler : TQUI - Outpoint is at primary RFZ')
#In This case Check the box where to go
if 'ordering' in self.parameter and int (ret_val['dst_xx']) == int (dest[1:]) + 50:
#self.message (6, ' DT_handler : TQUI - Ordering is active add box to outqueue %s' % dest)
#DB_con.addoutgoingbox (dest, ret_val ['box_nr'], '', '', '', '', 99)
break
#Errorboxes
boxnr = int (ret_val['box_nr'])
if ret_val['dst_id'][0] == 'T':
slot = None # DB_con.finderrorslot (ret_val['dst_id'])
if slot:
_dx, _dy = slot
if int (ret_val['dst_xx']) == _dx and int (ret_val['dst_yy']) == _dy:
#NoRead Boxes
boxes = DB_con.getboxesslot (ret_val['dst_id'], int (_dx), int (_dy))
boxnr = 0
if boxes:
nrs = [int (i[1]) for i in boxes]
print nrs
for i in range (999999800, 999999900):
if i not in nrs:
boxnr = i
break
else:
boxnr = 999999800
if not boxnr:
self.log (" DT_handler couldn't find a boxNr for Errorslot")
DB_con.insertbox (ret_val['dst_id'], boxnr, int (_dx), int (_dy))
self.message (3, ' DT_handler : TQUI for Box in %s Errorslot with boxnr %s' % (ret_val['dst_id'], str (boxnr)))
else:
self.message (3, ' DT_handler : TQUI location was %s' %ret_val['location'] )
#was setboxtime
#DB_con.setboxtimefillgap (ret_val['dst_id'], ret_val['box_nr'], '')
# 02 Order Aborted
elif ret_val ['state'] == "02":
self.message (3, ' DT_handler : TQUI -- Order aborted')
#if ret_val['location'] == 'RFZ1':
#self.message (3, ' DT_handler : TQUI location was illegal')
#self.debug ()
#elif ret_val['location'] == 'RFZ2':
#self.deletetauf (ret_val['location'], ret_val['box_nr'])
#if (ret_val['dst_id'] is not 'Nota'):
# DB_con.removebox ('Puffer', ret_val['box_nr'])
# DB_con.removebox ('Pick', ret_val['box_nr'])
#if (ret_val['dst_id'] is 'Expr'):
# DB_con.removebox ('Express', ret_val['box_nr'])
# 03 Src result no crate --> getting boxes
elif ret_val ['state'] == "03":
self.message (3, ' DT_handler : TQUI -- No Crate ')
_unusableslots = DB_con.getunusableslots (ret_val['src_id'])
_x = int (ret_val['src_xx'])
_y = int (ret_val['src_yy'])
if (ret_val['src_id'], _x, _y) in _unusableslots:
self.message (3, ' DT_handler : TQUI -- No Crate from Unusable slot')
else:
self.log ( " DT_handler : TQUI No Crate %(location)s box %(box_nr)s src %(src_id)s x %(src_xx)s y %(src_yy)s dst %(dst_id)s state %(state)s" % ret_val)
# 04 Dest result occupied --> lock slot assign box --> alternative
# TAUF Prio 1
elif ret_val ['state'] == "04":
self.message (3, ' DT_handler : TQUI -- Dest Occupied')
#FixMe alternative jobs
if ret_val['location'] == 'RFZ':
self.deletetauf (ret_val['location'], ret_val['box_nr'])
DB_con.removebox ('Inqueue', ret_val['box_nr'])
_dx, _dy = DB_con.finderrorslot (_dest)
_dz = 0
self.createtauf (ret_val['box_nr'], 'RFZ1', 'RFZ1', 0, 0, 0, _dest, _dx, _dy, _dz)
self.generatetransport ('RFZ1', ret_val['box_nr'])
# 05 Wrong box loaded
elif ret_val ['state'] == "05":
crtauf = 0
self.log (' DT_handler : TQUI -- Wrong Box Loaded at %s' % ret_val['location'])
if ret_val['location'] in ['RFZ1', 'RFZ2']:
ttauf = DB_con.getmovetransport (ret_val['location'], state = 'Sent')
if ttauf:
#Tauf for RFZ exists
tboxnr, tposition, tsrc, tsrcx, tsrcy, tsrcz, tdst, tdstx, tdsty, tdstz, tstate, tts = ttauf
#Box was from Throughfeed shelf
if (tsrc[0] == 'T'):
self.message (3, " DT_handler : TQUI -- Wrong Box Loaded from %s" % tsrc)
locked = DB_con. getunusableslots (tsrc)
srcbox = DB_con.searchbox (int (ret_val['box_nr']), tsrc)
if not srcbox:
self.message (3, " DT_handler : TQUI -- Wrong Box doesnt exist in source %s" % tsrc)
#Box is not in Source so create transport to errorslot and regenerate Transport because correct box may come
if tstate == 'Sent':
DB_con.setsenttransportnew (ret_val['location'], int (tboxnr), self.dummysrc)
#check if box is anywhere else
wboxes = DB_con.searchbox (int (ret_val['box_nr']))
for wbox in wboxes:
wboxstorage, wboxnr, wboxart, wboxlotnr, wboxweight, wboxx, wboxy, wboxz, wboxts = wbox
self.message (3, " DT_handler : TQUI -- Wrong Box is in %s at x:%s y:%s z:%s" % (wboxstorage, wboxx, wboxy, wboxy))
DB_con.removebox (int (ret_val['box_nr']))
#Fixme Check if Box is in Refeed
#rfbox = DB_con.findrefeedbox (ret_val['box_nr'])
#if rfbox:
# rfknr, rfanr, rflog, rfgew, rfz, rfts = rfbox
# DB_con.deletefromrefeedatz (rfz)
DB_con.deletealltransports (ret_val['box_nr'])
if ret_val ['location'] in self.transportmatrix['errordst']:
_dst, _dstx, _dsty, _prio = self.transportmatrix['errordst'][ret_val ['location']]
_dest = _dst
_dx, _dy = _dstx, _dsty
_dz = 0
else:
self.log ( "At %(location)s: Nor Errordestination for this Position - send Takeoff Transport" % ret_val)
_dest = ret_val ['location']
_dx, _dy = 0, 0
_dz = 1
crtauf = 1
#elif True:
# print "FixMe TQUI"
else:
# Box exists in source
self.log (" Wrong loaded box exists in Source - sending Takeoff Transport")
_dest = ret_val ['location']
_dx, _dy = 0,0
_dz = 1
crtauf = 0
orgbnr = DB_con.getsenttrasnport (ret_val['location'], ret_val['src_id'], int (ret_val['src_xx']), int (ret_val['src_yy']))
try:
orgbnr = int (orgbnr[0])
except:
orgbnr = 0
if orgbnr:
#check if box is anywhere else
self.message (3, " DT_handler : TQUI -- Wrong Box will be deleted from Outqucue ")
DB_con.removebox ('Outqueue', orgbnr)
wboxes = DB_con.searchbox (orgbnr)
for wbox in wboxes:
wboxstorage, wboxnr, wboxart, wboxlotnr, wboxduedate, wboxweight, wboxx, wboxy, wboxz, wboxts = wbox
if (ret_val['src_id'] <> wboxstorage):
self.message (3, " DT_handler : TQUI -- Wrong Box exists also in %s at x:%s y:%s z:%s" % (wboxstorage, wboxx, wboxy, wboxy))
if not wboxts:
self.message (3, " DT_handler : TQUI -- Wrong Box is only reserved in other location and will be deleted ")
DB_con.removebox (wboxstorage, orgbnr)
else:
self.message (3, " DT_handler : TQUI -- Wrong Box is also in other location PROBLEM")
DB_con.deletetransport (ret_val['location'], orgbnr)
DB_con.createtransport (orgbnr, ret_val['location'], ret_val['location'], 0, 0, 0, ret_val['location'], 0, 0, 1)
self.generatetransport (ret_val['location'], orgbnr)
"""
srcboxstorage, srcboxnr, srcboxart, srcboxlotnr, srcboxweight, srcboxx, srcboxy, srcboxz, srcboxts = srcbox
if (int (tsrcx) == int (srcboxx)) and (int (tsrcy) == int (srcboxy)):
self.message (3, " DT_handler : TQUI -- Wrong Box is from same Sourceslot")
#Correct slot -1st delete Transport and box as original reservation
self.deletettransport (ret_val['location'], tboxnr)
if (int (srcboxz) > 2):
self.message (3, " DT_handler : TQUI -- Wrong Box is from same Sourceslot and z > 2 delete also previous")
#FixMecheck for Chaotic slot
#if locked.get ((pbx, pby), 'None') == 'chaotisch':
# self.message (3, ' DT_handler : TQUI -- Wrong Box is from same Pufferslot, slot was chaotic')
# find boxes, check for TAUFs and for reservations chaos is impossible
zs = range (1, int (srcboxz))
zs.reverse ()
for i in zs:
self.message (5, "DT_handler : TQUI --Wrong Box from is from same Sourceslot an z > 2 cleaning x:%d, y:%d, z:%d" \
% (int (srcboxx), int (srcboxy), i))
prebox = DB_con.getboxbycoordinates (srcboxstorage, int (srcboxx), int (srcboxy), i)
#No check - MUST NOT FAIL
prbstorage, prbknr, prbanr, prbcharge, prbweight, prbx, prby, prbz, prbts = prebox
self.message (3, ' DT_handler : TQUI -- Delete Box %s from %s x%s y%s z%s' % (prbknr, prbstorage, prbx, prby, prbz))
wbtauf = DB_con.gettransport ('RFZ2', int (prbknr))
#position, boxnr, state = ''
self.deletetauf ('RFZ2', int (prbknr))
DB_con.removepufferbox (int (prbknr))
DB_con.removepickbox (int (prbknr))
DB_con.removebox ('Express', int (prbknr)) # kill eventual reservation
rfbox = DB_con.findrefeedbox (ret_val['box_nr'])
if rfbox:
rfknr, rfanr, rflog, rfgew, rfz, rfts = rfbox
DB_con.deletefromrefeedatz (rfz)
DB_con.removepufferbox (int (tboxnr))
DB_con.removepickbox (int (tboxnr))
#Check for TAUFs on wrong box from same slot
wbtauf = DB_con.gettauf ('RFZ2', int (pbknr))
if wbtauf:
self.message (3, ' DT_handler : TQUI -- Wrong Box already has TAUF')
wbtboxnr, wbtposition, wbtsrc, wbtsrcx, wbtsrcy, wbtsrcz, wbtdst, wbtdstx, wbtdsty, wbtdstz, wbtstate, wbtts = wbtauf[0]
if (wbtdst == tdst) and (wbtdstx == tdstx) and (wbtdsty == tdsty):
#Same destination so delete Transport and generat new one
self.message (3, ' DT_handler : TQUI -- Wrong Box already has Transport destination is ok so go on')
self.deletetauf ('RFZ2', int (wbtboxnr))
_dest = wbtdst
_dx = wbtdstx
_dy = wbtdsty
_dz = wbtdstz
crtauf = 1
elif (locked.get ((pbx, pby), 'None') != 'chaotisch'):
self.message (3, ' DT_handler : TQUI -- Wrong Box doesnt have Transport try to make pickreservation because from normal slot')
stamminfo = DB_con.getschachtstammarticle (pbanr)
if stamminfo:
stx, sty, stanr, stbez, stzone = stamminfo [0]
fill = DB_con.getfilllevel ('Pick')
stz = int (fill.get ((stx, sty), 0))
if stz < int (self.parameter["Z_PI"][int (stx) -1][int (sty) - 1]):
#Pick Rerservation is ok
DB_con.reservepickbox ('RFZ2', 'RFZ2', '0', '0', '0', int (pbknr), pbanr, pbweight, pbcharge, stx, sty, str (stz + 1))
self.deletetauf ('RFZ2', int (pbknr))
_dest = 'Pick'
_dx = stx
_dy = sty
_dz = str (stz + 1)
crtauf = 1
else:
self.message (3, ' DT_handler : TQUI -- Wrong Box doesnt have Place in Pick so move to Errorslot')
_dest = 'Pick'
_dx, _dy = DB_con.finderrorslot ('Pick')
_dz = 0
crtauf = 1
else:
self.message (3, ' DT_handler : TQUI -- Wrong Box doesnt have Stamminfo so move to Errrorslot')
_dest = 'Pick'
_dx, _dy = DB_con.finderrorslot ('Pick')
_dz = 0
crtauf = 1
else:
self.message (3, ' DT_handler : TQUI -- Wrong Box doesnt have Transport and is from chaotic slot so move to Errrorslot')
_dest = 'Pick'
_dx, _dy = DB_con.finderrorslot ('Pick')
_dz = 0
crtauf = 1
else:
#Other slot
self.message (3, ' DT_handler : TQUI -- Wrong Box is from other Pufferslot x:%s y:%s instead of x:%s y:%s ' %(pbx, pby, tsrcx, tsrcy))
DB_con.removepufferbox (ret_val['box_nr'])
self.message (3, ' DT_handler : TQUI -- Wrong Box move to Errrorslot')
_dest = 'Pick'
_dx, _dy = DB_con.finderrorslot ('Pick')
_dz = 0
crtauf = 1
"""
else:
self.message (3, ' DT_handler : TQUI -- No Sent TAUF')
self.log (" Wrong box Loaded")
#raise Warning
#There is no Transport for RFZ2 in sent taufs
if crtauf:
self.message (3, ' DT_handler : TQUI -- Wrong Box create alternative job')
DB_con.createtransport (ret_val['box_nr'], ret_val['location'], ret_val['location'], 0, 0, 0, _dest, _dx, _dy, _dz)
self.generatetransport (ret_val['location'], ret_val['box_nr'])
else:
self.message (3, ' DT_handler : TQUI -- Wrong Box Loaded invalid Position')
# unknown result
else:
self.message (2, ' DT_handler : TQUI -- unknown result')
_quit = 98
self.debug()
#Return Value for Quit telegram
return _quit