Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
debd36f4
Commit
debd36f4
authored
Mar 24, 2015
by
panos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Data Extraction script that extracts data from the database, inserted
parent
0dd0c506
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
133 additions
and
126 deletions
+133
-126
dream/KnowledgeExtraction/PilotCases/JobShop/DataExtraction.py
.../KnowledgeExtraction/PilotCases/JobShop/DataExtraction.py
+133
-126
No files found.
dream/KnowledgeExtraction/PilotCases/JobShop/DataExtraction.py
View file @
debd36f4
...
@@ -22,36 +22,39 @@ Created on 23 March 2015
...
@@ -22,36 +22,39 @@ Created on 23 March 2015
@author: Panos
@author: Panos
'''
'''
import
ImportDatabase
import
dream.KnowledgeExtraction.ImportDatabase
as
ImportDatabase
from
datetime
import
datetime
from
datetime
import
datetime
#connect to the database providing the following data and generate six different cursor variables
import
json
cnxn
=
ImportDatabase
.
ConnectionData
(
seekName
=
'ServerData'
,
implicitExt
=
'txt'
,
number_of_cursors
=
6
)
cursor
=
cnxn
.
getCursors
()
def
DataExtraction
(
DBFilePath
):
#SQL query to extract data from orders table
#connect to the database providing the following data and generate six different cursor variables
a
=
cursor
[
0
].
execute
(
"""
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
select Order_id, ProjectName, Customer, Order_date, Due_date, ProjectManager, Status
from orders
from orders
"""
)
"""
)
#create a dictionary called data and put inside two lists (orders and stations) and a dictionary called WIP
#create a dictionary called data and put inside two lists (orders and stations) and a dictionary called WIP
data
=
{}
data
=
{}
data
[
'orders'
]
=
[]
data
[
'orders'
]
=
[]
data
[
'WIP'
]
=
{}
data
[
'WIP'
]
=
{}
data
[
'stations'
]
=
[]
data
[
'stations'
]
=
[]
order
=
{}
productionOrders
=
{}
#Another SQL query that extracts data from the machines table
#Another SQL query that extracts data from the machines table
b
=
cursor
[
1
].
execute
(
"""
b
=
cursor
[
1
].
execute
(
"""
select MachineName, description
select MachineName, description
from machines
from machines
"""
)
"""
)
# for every machine of the machines table
# for every machine of the machines table
for
j
in
range
(
b
.
rowcount
):
for
j
in
range
(
b
.
rowcount
):
#get the next line
#get the next line
ind3
=
b
.
fetchone
()
ind3
=
b
.
fetchone
()
#and insert in one of the above initiated lists
#and insert in one of the above initiated lists
data
[
'stations'
].
append
(
ind3
.
MachineName
)
data
[
'stations'
].
append
(
ind3
.
MachineName
)
# for every order of the orders table
# for every order of the orders table
for
j
in
range
(
a
.
rowcount
):
for
j
in
range
(
a
.
rowcount
):
#get the next line
#get the next line
ind0
=
a
.
fetchone
()
ind0
=
a
.
fetchone
()
#define a variable called status and holds the status of the order (extracted from orders table)
#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):
...
@@ -59,12 +62,14 @@ for j in range(a.rowcount):
#check if status is 'accepted' or 'in progress' and move in
#check if status is 'accepted' or 'in progress' and move in
if
status
==
'accepted'
or
status
==
'in progress'
:
if
status
==
'accepted'
or
status
==
'in progress'
:
#insert the following extracted data from the database in order disctionary
#insert the following extracted data from the database in order disctionary
order
[
'orderName'
]
=
ind0
.
ProjectName
productionOrders
[
'name'
]
=
ind0
.
ProjectName
order
[
'orderID'
]
=
ind0
.
Order_id
productionOrders
[
'id'
]
=
ind0
.
Order_id
order
[
'manager'
]
=
ind0
.
ProjectManager
productionOrders
[
'manager'
]
=
ind0
.
ProjectManager
order
[
'orderDate'
]
=
ind0
.
Order_date
orderDate
=
datetime
.
strptime
(
str
(
ind0
.
Order_date
),
'%Y-%m-%d'
)
order
[
'dueDate'
]
=
ind0
.
Due_date
productionOrders
[
'orderDate'
]
=
str
(
orderDate
)
order
[
'componentsList'
]
=
[]
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
#SQL query to extract data from sequence table where order data is given
c
=
cursor
[
2
].
execute
(
"""
c
=
cursor
[
2
].
execute
(
"""
select Order_id, WP_id, PartCode, PartName, Operation_Name, ProcessingTime, PersonnelCode, Quantity, step
select Order_id, WP_id, PartCode, PartName, Operation_Name, ProcessingTime, PersonnelCode, Quantity, step
...
@@ -79,10 +84,10 @@ for j in range(a.rowcount):
...
@@ -79,10 +84,10 @@ for j in range(a.rowcount):
# and get the next row
# and get the next row
ind1
=
c
.
fetchone
()
ind1
=
c
.
fetchone
()
name
=
ind1
.
PartName
name
=
ind1
.
PartName
component
[
'componentN
ame'
]
=
name
component
[
'n
ame'
]
=
name
code
=
ind1
.
PartCode
code
=
ind1
.
PartCode
WP
=
ind1
.
WP_id
WP
=
ind1
.
WP_id
component
[
'componentID
'
]
=
code
component
[
'id
'
]
=
code
component
[
'route'
]
=
[]
component
[
'route'
]
=
[]
#SQL query that extracts data from sequence table where PartCode is given
#SQL query that extracts data from sequence table where PartCode is given
d
=
cursor
[
3
].
execute
(
"""
d
=
cursor
[
3
].
execute
(
"""
...
@@ -109,15 +114,15 @@ for j in range(a.rowcount):
...
@@ -109,15 +114,15 @@ for j in range(a.rowcount):
step
[
'quantity'
]
=
ind2
.
Quantity
step
[
'quantity'
]
=
ind2
.
Quantity
ind3
=
f
.
fetchone
()
ind3
=
f
.
fetchone
()
partsNeeded
=
ind3
.
PartsNeeded
.
split
(
';'
)
partsNeeded
=
ind3
.
PartsNeeded
.
split
(
';'
)
step
[
'partsneeded
'
]
=
partsNeeded
step
[
'requiredParts
'
]
=
partsNeeded
step
[
'processingTime'
]
=
{}
step
[
'processingTime'
]
=
{}
step
[
'processingTime'
][
'distribution'
]
=
'Fixed'
step
[
'processingTime'
][
'distribution'
]
=
'Fixed'
step
[
'processingTime'
][
'mean'
]
=
ind2
.
ProcessingTime
step
[
'processingTime'
][
'mean'
]
=
ind2
.
ProcessingTime
component
[
'route'
].
append
(
step
)
component
[
'route'
].
append
(
step
)
#The following checks if the component ids have been inserted to appended
#The following checks if the component ids have been inserted to appended
if
not
component
[
'componentID
'
]
in
appended
:
if
not
component
[
'id
'
]
in
appended
:
order
[
'componentsList'
].
append
(
component
)
productionOrders
[
'componentsList'
].
append
(
component
)
appended
.
append
(
component
[
'componentID
'
])
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
#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
(
"""
e
=
cursor
[
5
].
execute
(
"""
select prod_status.WP_id, sequence.WP_id, sequence.ProcessingTime, sequence.step, MachineName, TIMEIN, TIMEOUT, prod_status.PersonnelCode
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):
...
@@ -148,6 +153,8 @@ for j in range(a.rowcount):
#in case the status is 'finished' continue to the next order
#in case the status is 'finished' continue to the next order
elif
status
==
'finished'
:
elif
status
==
'finished'
:
continue
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment