Commit f076c38a authored by panos's avatar panos

The Data Extraction script ammended to overcome some errors

parent 32e0a049
......@@ -31,7 +31,7 @@ def DataExtraction(DBFilePath):
#create dictionary inside data dictionary that holds the WIP
data['WIP']={}
#create dictionary inside data dictionary that holds the available weekly operation capacity
data['operations']={}
# data['operations']={}
#SQL query that extracts info form operations table
b=cursor[0].execute("""
select OperationName, description
......@@ -44,43 +44,41 @@ def DataExtraction(DBFilePath):
#get the next line
ind1=b.fetchone()
process=ind1.OperationName
# status = ind0.Status
# if status == 'accepted' or status == 'in progress':
#create a dictionary to insert the process sequence
data['operations'][process]={}
#SQL query to extract the available capacity for each of the operations
c= cursor[1].execute("""
select SMF, WELD, CNC, MCH, EEP, PPASB, ASBTST, PAINT
from capacity
""")
#create a dictionary to insert the available capacity
dicta={}
#insert operation's name as key in the dictionary
dicta['name']=ind1.OperationName
dicta['intervalCapacity']=[]
for line in range(c.rowcount):
ind2=c.fetchone()
#operation's name is given by the SQL quesry
operation=ind1.OperationName
#Check the operation name and insert the interval capacity
if operation=='SMF':
dicta['intervalCapacity'].append(ind2.SMF)
elif operation=='WELD':
dicta['intervalCapacity'].append(ind2.WELD)
elif operation=='CNC':
dicta['intervalCapacity'].append(ind2.CNC)
elif operation=='MCH':
dicta['intervalCapacity'].append(ind2.MCH)
elif operation=='EEP':
dicta['intervalCapacity'].append(ind2.EEP)
elif operation=='PPASB':
dicta['intervalCapacity'].append(ind2.PPASB)
elif operation=='ASBTST':
dicta['intervalCapacity'].append(ind2.ASBTST)
else:
dicta['intervalCapacity'].append(ind2.PAINT)
data['operations'][process]=dicta
# data['operations'][process]={}
# #SQL query to extract the available capacity for each of the operations
# c= cursor[1].execute("""
# select SMF, WELD, CNC, MCH, EEP, PPASB, ASBTST, PAINT
# from capacity
# """)
# #create a dictionary to insert the available capacity
# dicta={}
# #insert operation's name as key in the dictionary
# dicta['name']=ind1.OperationName
# dicta['intervalCapacity']=[]
# for line in range(c.rowcount):
# ind2=c.fetchone()
# #operation's name is given by the SQL quesry
# operation=ind1.OperationName
# #Check the operation name and insert the interval capacity
# if operation=='SMF':
# dicta['intervalCapacity'].append(ind2.SMF)
# elif operation=='WELD':
# dicta['intervalCapacity'].append(ind2.WELD)
# elif operation=='CNC':
# dicta['intervalCapacity'].append(ind2.CNC)
# elif operation=='MCH':
# dicta['intervalCapacity'].append(ind2.MCH)
# elif operation=='EEP':
# dicta['intervalCapacity'].append(ind2.EEP)
# elif operation=='PPASB':
# dicta['intervalCapacity'].append(ind2.PPASB)
# elif operation=='ASBTST':
# dicta['intervalCapacity'].append(ind2.ASBTST)
# else:
# dicta['intervalCapacity'].append(ind2.PAINT)
# data['operations'][process]=dicta
#
###### Find the capacity ratio between SMF and WELD ######
#SQL query in sequence table to extract the capacity required from each operation
f=cursor[2].execute("""
......@@ -198,24 +196,46 @@ def DataExtraction(DBFilePath):
data['WIP'][task]['End date']=str(ind5.END_DATE)
#check operation's name and if is one of the three in the list; create the actually non-existing dictionary that holds the WIP - buffered just before the PPASB assembly operation
if data['WIP'][task]['operation'] in ['CNC','WELD','MCH']:
data['WIP']['PPASB_id' + orderID]={}
try:
data['WIP']['PPASB_id' + orderID]={}
except KeyError:
continue
#check operation's name and if is a not yet finished SMF; create another 'fake' dict that holds the WIP buffered just before WELD
if data['WIP'][task]['operation']=='SMF' and not ind5.END_DATE:
data['WIP']['WELD_id' + orderID]={}
if data['WIP'][task]['operation']=='SMF':
try:
data['WIP']['WELD_id' + orderID]={}
except KeyError:
continue
if data['WIP'][task]['operation']=='PPASB':
try:
data['WIP']['PAINT_id' + orderID]={}
except KeyError:
continue
if data['WIP'][task]['operation']=='EEP':
try:
data['WIP']['ASBTST_id' + orderID]={}
except KeyError:
continue
#check capacity required for each task - if it's 0 then delete this task from WIP
if data['WIP'][task]['Capacity required'] == 0:
del data['WIP'][task]
#if it's SMF and capacity finished then delete the fake dictionary created to hold the WIP just before WELD
if ind5.Operation_Name == 'SMF':
del data['WIP']['WELD_id' + orderID]
# if ind5.Operation_Name == 'SMF':
# try:
# del data['WIP']['WELD_id' + orderID]
# except KeyError:
# continue
if ind5.Operation_Name not in appended:
appended.append(ind5.Operation_Name)
#try syntax to check if the operation finished is one of the following three; if yes delete the fake dictionary created to hold the WIP just before PPASB assembly station
try:
if 'CNC' and 'WELD' and 'MCH' in appended:
del data['WIP']['PPASB_id' + orderID]
except KeyError:
continue
# try:
# if 'CNC' and 'WELD' and 'MCH' in appended:
# try:
# del data['WIP']['PPASB_id' + orderID]
# except KeyError:
# continue
# except KeyError:
# continue
#for every line in production_status table
for x in range(e.rowcount):
ind5=wipList[x]
......@@ -226,16 +246,22 @@ def DataExtraction(DBFilePath):
if operation=='SMF' and not ind5.END_DATE:
finishedCap= ind5.CapacityRequirement - ind5.Capacity_left
startWELD = float(key) * float(finishedCap)
try:
del data['WIP']['startBuffered.SMF_id' + orderID]
try:
data['WIP']['WELD_id' + orderID]['operation']='WELD'
data['WIP']['WELD_id' + orderID]['buffered']=startWELD
data['WIP']['WELD_id' + orderID]['order_id']=orderID
except KeyError:
continue
continue
elif operation=='SMF' and ind5.END_DATE:
try:
del data['WIP']['startBuffered.SMF_id' + orderID]
except KeyError:
continue
#check and if operation is WELD calculate first the finished capacity and then based on the status of CNC and MCH operations, the capacity buffered before the assembly station PPASB
if operation=='WELD':
try:
del data['WIP']['WELD_id' + orderID]
weldfinishedCap= ind5.CapacityRequirement - ind5.Capacity_left
data['WIP']['PPASB_id' + orderID ]['operation']='PPASB'
data['WIP']['PPASB_id' + orderID ]['order_id']=orderID
......@@ -299,7 +325,32 @@ def DataExtraction(DBFilePath):
continue
if operation=='EEP':
try:
eepfinishedCap= ind5.CapacityRequirement - ind5.Capacity_left
data['WIP']['ASBTST_id' + orderID ]['operation']='ASBTST'
data['WIP']['ASBTST_id' + orderID ]['order_id']=orderID
data['WIP']['ASBTST_id' + orderID ]['buffered']=eepfinishedCap
del data['WIP']['startBuffered.EEP_id' + orderID]
except KeyError:
continue
return data
\ No newline at end of file
continue
if operation=='PPASB' and not ind5.END_DATE:
try:
ppasbfinishedCap= ind5.CapacityRequirement - ind5.Capacity_left
del data['WIP']['PPASB_id' + orderID ]
data['WIP']['PAINT_id' + orderID ]['operation']='PAINT'
data['WIP']['PAINT_id' + orderID ]['order_id']=orderID
data['WIP']['PAINT_id' + orderID ]['buffered']=ppasbfinishedCap
except KeyError:
continue
if operation=='PAINT' and not ind5.END_DATE:
try:
del data['WIP']['PAINT_id' + orderID]
except KeyError:
continue
if operation=='ASBTST' and not ind5.END_DATE:
try:
del data['WIP']['ASBTST_id' + orderID]
except KeyError:
continue
return data
print DataExtraction('C:\Users\Panos\Documents\DB_Approach\CapacityStations')
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment