Commit debd36f4 authored by panos's avatar panos

Data Extraction script that extracts data from the database, inserted

parent 0dd0c506
......@@ -22,36 +22,39 @@ Created on 23 March 2015
@author: Panos
'''
import ImportDatabase
import dream.KnowledgeExtraction.ImportDatabase as ImportDatabase
from datetime import datetime
#connect to the database providing the following data and generate six different cursor variables
cnxn=ImportDatabase.ConnectionData(seekName='ServerData', implicitExt='txt', number_of_cursors=6)
cursor=cnxn.getCursors()
#SQL query to extract data from orders table
a=cursor[0].execute("""
import json
def DataExtraction(DBFilePath):
#connect to the database providing the following data and generate six different cursor variables
cnxn=ImportDatabase.ConnectionData(seekName='ServerData', file_path=DBFilePath, implicitExt='txt', number_of_cursors=6)
cursor=cnxn.getCursors()
#SQL query to extract data from orders table
a=cursor[0].execute("""
select Order_id, ProjectName, Customer, Order_date, Due_date, ProjectManager, Status
from orders
""")
#create a dictionary called data and put inside two lists (orders and stations) and a dictionary called WIP
data={}
data['orders']=[]
data['WIP']={}
data['stations']=[]
order={}
#Another SQL query that extracts data from the machines table
b=cursor[1].execute("""
#create a dictionary called data and put inside two lists (orders and stations) and a dictionary called WIP
data={}
data['orders']=[]
data['WIP']={}
data['stations']=[]
productionOrders={}
#Another SQL query that extracts data from the machines table
b=cursor[1].execute("""
select MachineName, description
from machines
""")
# for every machine of the machines table
for j in range(b.rowcount):
# for every machine of the machines table
for j in range(b.rowcount):
#get the next line
ind3=b.fetchone()
#and insert in one of the above initiated lists
data['stations'].append(ind3.MachineName)
# for every order of the orders table
for j in range(a.rowcount):
# for every order of the orders table
for j in range(a.rowcount):
#get the next line
ind0=a.fetchone()
#define a variable called status and holds the status of the order (extracted from orders table)
......@@ -59,12 +62,14 @@ for j in range(a.rowcount):
#check if status is 'accepted' or 'in progress' and move in
if status == 'accepted' or status == 'in progress':
#insert the following extracted data from the database in order disctionary
order['orderName']=ind0.ProjectName
order['orderID']=ind0.Order_id
order['manager']=ind0.ProjectManager
order['orderDate']=ind0.Order_date
order['dueDate']=ind0.Due_date
order['componentsList']=[]
productionOrders['name']=ind0.ProjectName
productionOrders['id']=ind0.Order_id
productionOrders['manager']=ind0.ProjectManager
orderDate=datetime.strptime(str(ind0.Order_date), '%Y-%m-%d')
productionOrders['orderDate']=str(orderDate)
dueDate=datetime.strptime(str(ind0.Due_date), '%Y-%m-%d')
productionOrders['dueDate']=str(dueDate)
productionOrders['componentsList']=[]
#SQL query to extract data from sequence table where order data is given
c=cursor[2].execute("""
select Order_id, WP_id, PartCode, PartName, Operation_Name, ProcessingTime, PersonnelCode, Quantity, step
......@@ -79,10 +84,10 @@ for j in range(a.rowcount):
# and get the next row
ind1=c.fetchone()
name=ind1.PartName
component['componentName']=name
component['name']=name
code=ind1.PartCode
WP=ind1.WP_id
component['componentID']=code
component['id']=code
component['route']=[]
#SQL query that extracts data from sequence table where PartCode is given
d=cursor[3].execute("""
......@@ -109,15 +114,15 @@ for j in range(a.rowcount):
step['quantity']=ind2.Quantity
ind3=f.fetchone()
partsNeeded = ind3.PartsNeeded.split(';')
step['partsneeded']=partsNeeded
step['requiredParts']=partsNeeded
step['processingTime']={}
step['processingTime']['distribution']='Fixed'
step['processingTime']['mean']=ind2.ProcessingTime
component['route'].append(step)
#The following checks if the component ids have been inserted to appended
if not component['componentID'] in appended:
order['componentsList'].append(component)
appended.append(component['componentID'])
if not component['id'] in appended:
productionOrders['componentsList'].append(component)
appended.append(component['id'])
#SQL query to extract WIP data from the prod_status table when sequence and prod_status are joined together and PartCode is given
e= cursor[5].execute("""
select prod_status.WP_id, sequence.WP_id, sequence.ProcessingTime, sequence.step, MachineName, TIMEIN, TIMEOUT, prod_status.PersonnelCode
......@@ -148,6 +153,8 @@ for j in range(a.rowcount):
#in case the status is 'finished' continue to the next order
elif status == 'finished':
continue
data['orders'].append(order.copy())
data['orders'].append(productionOrders.copy())
print data
return data
\ No newline at end of file
print data
\ 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