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): ...@@ -31,7 +31,7 @@ def DataExtraction(DBFilePath):
#create dictionary inside data dictionary that holds the WIP #create dictionary inside data dictionary that holds the WIP
data['WIP']={} data['WIP']={}
#create dictionary inside data dictionary that holds the available weekly operation capacity #create dictionary inside data dictionary that holds the available weekly operation capacity
data['operations']={} # data['operations']={}
#SQL query that extracts info form operations table #SQL query that extracts info form operations table
b=cursor[0].execute(""" b=cursor[0].execute("""
select OperationName, description select OperationName, description
...@@ -44,43 +44,41 @@ def DataExtraction(DBFilePath): ...@@ -44,43 +44,41 @@ def DataExtraction(DBFilePath):
#get the next line #get the next line
ind1=b.fetchone() ind1=b.fetchone()
process=ind1.OperationName process=ind1.OperationName
# status = ind0.Status
# if status == 'accepted' or status == 'in progress':
#create a dictionary to insert the process sequence #create a dictionary to insert the process sequence
data['operations'][process]={} # data['operations'][process]={}
#SQL query to extract the available capacity for each of the operations # #SQL query to extract the available capacity for each of the operations
c= cursor[1].execute(""" # c= cursor[1].execute("""
select SMF, WELD, CNC, MCH, EEP, PPASB, ASBTST, PAINT # select SMF, WELD, CNC, MCH, EEP, PPASB, ASBTST, PAINT
from capacity # from capacity
""") # """)
#create a dictionary to insert the available capacity # #create a dictionary to insert the available capacity
dicta={} # dicta={}
#insert operation's name as key in the dictionary # #insert operation's name as key in the dictionary
dicta['name']=ind1.OperationName # dicta['name']=ind1.OperationName
dicta['intervalCapacity']=[] # dicta['intervalCapacity']=[]
for line in range(c.rowcount): # for line in range(c.rowcount):
ind2=c.fetchone() # ind2=c.fetchone()
#operation's name is given by the SQL quesry # #operation's name is given by the SQL quesry
operation=ind1.OperationName # operation=ind1.OperationName
#Check the operation name and insert the interval capacity # #Check the operation name and insert the interval capacity
if operation=='SMF': # if operation=='SMF':
dicta['intervalCapacity'].append(ind2.SMF) # dicta['intervalCapacity'].append(ind2.SMF)
elif operation=='WELD': # elif operation=='WELD':
dicta['intervalCapacity'].append(ind2.WELD) # dicta['intervalCapacity'].append(ind2.WELD)
elif operation=='CNC': # elif operation=='CNC':
dicta['intervalCapacity'].append(ind2.CNC) # dicta['intervalCapacity'].append(ind2.CNC)
elif operation=='MCH': # elif operation=='MCH':
dicta['intervalCapacity'].append(ind2.MCH) # dicta['intervalCapacity'].append(ind2.MCH)
elif operation=='EEP': # elif operation=='EEP':
dicta['intervalCapacity'].append(ind2.EEP) # dicta['intervalCapacity'].append(ind2.EEP)
elif operation=='PPASB': # elif operation=='PPASB':
dicta['intervalCapacity'].append(ind2.PPASB) # dicta['intervalCapacity'].append(ind2.PPASB)
elif operation=='ASBTST': # elif operation=='ASBTST':
dicta['intervalCapacity'].append(ind2.ASBTST) # dicta['intervalCapacity'].append(ind2.ASBTST)
else: # else:
dicta['intervalCapacity'].append(ind2.PAINT) # dicta['intervalCapacity'].append(ind2.PAINT)
data['operations'][process]=dicta # data['operations'][process]=dicta
#
###### Find the capacity ratio between SMF and WELD ###### ###### Find the capacity ratio between SMF and WELD ######
#SQL query in sequence table to extract the capacity required from each operation #SQL query in sequence table to extract the capacity required from each operation
f=cursor[2].execute(""" f=cursor[2].execute("""
...@@ -198,24 +196,46 @@ def DataExtraction(DBFilePath): ...@@ -198,24 +196,46 @@ def DataExtraction(DBFilePath):
data['WIP'][task]['End date']=str(ind5.END_DATE) 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 #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']: if data['WIP'][task]['operation'] in ['CNC','WELD','MCH']:
try:
data['WIP']['PPASB_id' + orderID]={} 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 #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: if data['WIP'][task]['operation']=='SMF':
try:
data['WIP']['WELD_id' + orderID]={} 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 #check capacity required for each task - if it's 0 then delete this task from WIP
if data['WIP'][task]['Capacity required'] == 0: if data['WIP'][task]['Capacity required'] == 0:
del data['WIP'][task] 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 it's SMF and capacity finished then delete the fake dictionary created to hold the WIP just before WELD
if ind5.Operation_Name == 'SMF': # if ind5.Operation_Name == 'SMF':
del data['WIP']['WELD_id' + orderID] # try:
# del data['WIP']['WELD_id' + orderID]
# except KeyError:
# continue
if ind5.Operation_Name not in appended: if ind5.Operation_Name not in appended:
appended.append(ind5.Operation_Name) 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 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: # try:
if 'CNC' and 'WELD' and 'MCH' in appended: # if 'CNC' and 'WELD' and 'MCH' in appended:
del data['WIP']['PPASB_id' + orderID] # try:
except KeyError: # del data['WIP']['PPASB_id' + orderID]
continue # except KeyError:
# continue
# except KeyError:
# continue
#for every line in production_status table #for every line in production_status table
for x in range(e.rowcount): for x in range(e.rowcount):
ind5=wipList[x] ind5=wipList[x]
...@@ -227,15 +247,21 @@ def DataExtraction(DBFilePath): ...@@ -227,15 +247,21 @@ def DataExtraction(DBFilePath):
finishedCap= ind5.CapacityRequirement - ind5.Capacity_left finishedCap= ind5.CapacityRequirement - ind5.Capacity_left
startWELD = float(key) * float(finishedCap) startWELD = float(key) * float(finishedCap)
try: try:
del data['WIP']['startBuffered.SMF_id' + orderID]
data['WIP']['WELD_id' + orderID]['operation']='WELD' data['WIP']['WELD_id' + orderID]['operation']='WELD'
data['WIP']['WELD_id' + orderID]['buffered']=startWELD data['WIP']['WELD_id' + orderID]['buffered']=startWELD
data['WIP']['WELD_id' + orderID]['order_id']=orderID data['WIP']['WELD_id' + orderID]['order_id']=orderID
except KeyError: 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 #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': if operation=='WELD':
try: try:
del data['WIP']['WELD_id' + orderID]
weldfinishedCap= ind5.CapacityRequirement - ind5.Capacity_left weldfinishedCap= ind5.CapacityRequirement - ind5.Capacity_left
data['WIP']['PPASB_id' + orderID ]['operation']='PPASB' data['WIP']['PPASB_id' + orderID ]['operation']='PPASB'
data['WIP']['PPASB_id' + orderID ]['order_id']=orderID data['WIP']['PPASB_id' + orderID ]['order_id']=orderID
...@@ -299,7 +325,32 @@ def DataExtraction(DBFilePath): ...@@ -299,7 +325,32 @@ def DataExtraction(DBFilePath):
continue continue
if operation=='EEP': if operation=='EEP':
try: 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] del data['WIP']['startBuffered.EEP_id' + orderID]
except KeyError: except KeyError:
continue 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 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