Commit a2e4ece4 authored by panos's avatar panos

DataExtraction made as a function so that it can be invoked by plugins

parent 2228519f
......@@ -16,34 +16,36 @@
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
import json
import ImportDatabase
import dream.KnowledgeExtraction.ImportDatabase as ImportDatabase
cnxn=ImportDatabase.ConnectionData(seekName='ServerData', implicitExt='txt', number_of_cursors=6)
cursor=cnxn.getCursors()
def DataExtraction(DBFilePath):
cnxn=ImportDatabase.ConnectionData(seekName='ServerData', file_path=DBFilePath,implicitExt='txt', number_of_cursors=6)
cursor=cnxn.getCursors()
#create a dictionary data
data={}
#create list inside data dictionary that holds generic order's attributes
data['orders']=[]
#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']={}
#SQL query that extracts info form operations table
b=cursor[0].execute("""
#create a dictionary data
data={}
#create list inside data dictionary that holds generic order's attributes
data['orders']=[]
#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']={}
#SQL query that extracts info form operations table
b=cursor[0].execute("""
select OperationName, description
from operations
""")
# for every operation of the operations table
for j in range(b.rowcount):
# for every operation of the operations table
for j in range(b.rowcount):
#create a dictionary order
order={}
#get the next line
ind1=b.fetchone()
process=ind1.OperationName
# status = ind0.Status
# if status == 'accepted' or status == 'in progress':
# 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
......@@ -79,30 +81,30 @@ for j in range(b.rowcount):
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("""
###### 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("""
select WP_id, Operation_Name, CapacityRequirement, EarliestStart
from sequence
""")
#create a list called capacity
capacity=[]
#for every line in sequence table
for j in range(f.rowcount):
#create a list called capacity
capacity=[]
#for every line in sequence table
for j in range(f.rowcount):
#get the next line
ind4=f.fetchone()
#insert in capacity list the capacity required by each operation
capacity.append(ind4.CapacityRequirement)
#create variable that holds the calculation of the capacity ratio between SMF and WELD
key= capacity[1]/float(capacity[0])
#create variable that holds the calculation of the capacity ratio between SMF and WELD
key= capacity[1]/float(capacity[0])
#SQL query in orders table to extract generic info referring to each order
a=cursor[3].execute("""
#SQL query in orders table to extract generic info referring to each order
a=cursor[3].execute("""
select Order_id, ProjectName, Customer, Order_date, Due_date, FloorSpaceRequired, Status
from orders
""")
#for every order in orders table
for i in range(a.rowcount):
#for every order in orders table
for i in range(a.rowcount):
#create order disctionary
order={}
ind3=a.fetchone()
......@@ -143,21 +145,21 @@ for i in range(a.rowcount):
step[process]['earliestStart']=str(ind4.EarliestStart)
order['sequence'].append(step)
#SQL query that extracts data from production_status table, joining the sequence and production_status table in WP_id attribute, in order to retrieve that WIP
e= cursor[5].execute("""
#SQL query that extracts data from production_status table, joining the sequence and production_status table in WP_id attribute, in order to retrieve that WIP
e= cursor[5].execute("""
select production_status.WP_id, sequence.WP_id, sequence.Order_id, sequence.CapacityRequirement, production_status.Capacity_left, production_status.START_DATE, production_status.END_DATE, production_status.Operation_Name
from production_status
join sequence on sequence.WP_id = production_status.WP_id
""")
#create a list that holds the performed operations
appended=[]
#initiate the following indicators
weldfinishedCap=0
cncfinishedCap=0
mchfinishedCap=0
wipList= e.fetchall()
#for every line in production_status table
for x in range(e.rowcount):
#create a list that holds the performed operations
appended=[]
#initiate the following indicators
weldfinishedCap=0
cncfinishedCap=0
mchfinishedCap=0
wipList= e.fetchall()
#for every line in production_status table
for x in range(e.rowcount):
ind5=wipList[x]
task=ind5.WP_id
orderID=ind5.Order_id
......@@ -190,8 +192,8 @@ for x in range(e.rowcount):
del data['WIP']['PPASB_id' + orderID]
except KeyError:
continue
#for every line in production_status table
for x in range(e.rowcount):
#for every line in production_status table
for x in range(e.rowcount):
ind5=wipList[x]
orderID=ind5.Order_id
task=ind5.WP_id
......@@ -268,12 +270,6 @@ for x in range(e.rowcount):
data['WIP']['PPASB_id' + orderID ]['buffered']=FinishedCap
except KeyError:
continue
# print data['WIP']
print data
# export a JSON file called DBExtraction with this data
outputJSONString=json.dumps(data, indent=5)
outputJSONFile=open('DBExtraction.json', mode='w')
outputJSONFile.write(outputJSONString)
return data
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