Commit b73cc328 authored by Georgios Dagkakis's avatar Georgios Dagkakis

sample script to take DB extracted data and put it in CapacityStation configuration. WIP is missing

parent 97d48c06
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# 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
from datetime import datetime
configuration=open("PilotCases\CapacityStations\sampleConfiguration.json", "r")
# configuration=open("sampleConfiguration.json", "r")
configurationData=configuration.read()
configurationJSON=json.loads(configurationData)
db=open("PilotCases\CapacityStations\sampleDBExtraction.json", "r")
# configuration=open("sampleConfiguration.json", "r")
dbData=db.read()
dbJSON=json.loads(dbData)
operations=dbJSON.get('operations',{})
stations=configurationJSON['graph']['node']
currentDate=configurationJSON['general']['currentDate']
currentDate=datetime.strptime(currentDate, '%Y/%m/%d')
# set the interval capacity of the stations
for operationId, operation in operations.iteritems():
intervalCapacity=operation.get('intervalCapacity',[])
for stationId, station in stations.iteritems():
if stationId==operationId:
station['intervalCapacity']=intervalCapacity
orders=dbJSON.get('orders',{})
configurationJSON['input']['BOM']['productionOrders']=[]
capacityRequirementDict={}
earliestStartDict={}
for order in orders:
for operation in order['sequence']:
operationId=operation.keys()[0]
capacityRequirementDict[operationId]=operation[operationId]['requiredCapacity']
earliestStart=operation[operationId].get('earliestStart',None)
if earliestStart:
earliestStart=datetime.strptime(earliestStart, '%Y-%m-%d')
earliestStartDict[operationId]=(earliestStart-currentDate).days
assemblySpaceRequirement=order.get('floorSpaceRequired',100)
orderId=order['orderID']
dueDate=order.get('dueDate',100)
dueDate=datetime.strptime(dueDate, '%Y-%m-%d')
dueDate=(dueDate-currentDate).days
orderDate=order.get('orderDate',0)
orderDate=datetime.strptime(orderDate, '%Y-%m-%d')
orderDate=(orderDate-currentDate).days
name=order.get('orderName',orderId)
configurationJSON['input']['BOM']['productionOrders'].append({
"capacityRequirementDict":capacityRequirementDict,
"assemblySpaceRequirement":assemblySpaceRequirement,
"name":name,
"id":orderId,
"earliestStartDict":earliestStartDict,
"_class": "dream.simulation.applications.CapacityStations.CapacityProject.CapacityProject",
"dueDate":dueDate,
"orderDate":orderDate
})
updatedModelJSONString=json.dumps(configurationJSON, indent=5)
updatedModel=open('UpdatedModel.json', mode='w')
updatedModel.write(updatedModelJSONString)
# ===========================================================================
# Copyright 2013 University of Limerick
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
\ No newline at end of file
{
"operations": {
"WELD": {
"name": "WELD",
"intervalCapacity": [
250,
350,
450,
550,
650,
0,
0
]
},
"MCH": {
"name": "MCH",
"intervalCapacity": [
310,
410,
510,
610,
710,
0,
0
]
},
"EEP": {
"name": "EEP",
"intervalCapacity": [
345,
445,
545,
645,
745,
0,
0
]
},
"ASBTST": {
"name": "ASBTST",
"intervalCapacity": [
420,
350,
380,
480,
560,
0,
0
]
},
"PAINT": {
"name": "PAINT",
"intervalCapacity": [
415,
515,
615,
715,
815,
0,
0
]
},
"CNC": {
"name": "CNC",
"intervalCapacity": [
270,
370,
470,
570,
670,
0,
0
]
},
"PPASB": {
"name": "PPASB",
"intervalCapacity": [
380,
300,
580,
680,
780,
0,
0
]
},
"SMF": {
"name": "SMF",
"intervalCapacity": [
180,
300,
400,
500,
600,
0,
0
]
}
},
"orders": [
{
"orderID": "Tade",
"customer": "t1",
"floorSpaceRequired": 400,
"sequence": [
{
"SMF": {
"operation": "SMF",
"earliestStart": "2014-08-25",
"task_id": "ID-001",
"requiredCapacity": 30
}
},
{
"WELD": {
"operation": "WELD",
"earliestStart": "2014-08-26",
"task_id": "ID-002",
"requiredCapacity": 15
}
},
{
"CNC": {
"operation": "CNC",
"earliestStart": "2014-08-27",
"task_id": "ID-003",
"requiredCapacity": 45
}
},
{
"MCH": {
"operation": "MCH",
"earliestStart": "2014-08-28",
"task_id": "ID-004",
"requiredCapacity": 25
}
},
{
"EEP": {
"operation": "EEP",
"earliestStart": "2014-08-29",
"task_id": "ID-005",
"requiredCapacity": 15
}
},
{
"PPASB": {
"operation": "PPASB",
"earliestStart": "2014-08-30",
"task_id": "ID-006",
"requiredCapacity": 25
}
},
{
"PAINT": {
"operation": "PAINT",
"earliestStart": "2014-08-31",
"task_id": "ID-007",
"requiredCapacity": 35
}
},
{
"ASBTST": {
"operation": "ASBTST",
"earliestStart": "2014-09-01",
"task_id": "ID-008",
"requiredCapacity": 45
}
}
],
"dueDate": "2014-08-25",
"orderName": "italy",
"orderDate": "2014-08-19"
}
],
"WIP": {
"WELD_idTade": {
"order_id": "Tade",
"buffered": 10.0,
"operation": "WELD"
},
"ID-001": {
"End date": "None",
"Total Capacity required": 30,
"Capacity required": 10,
"order_id": "Tade",
"operation": "SMF",
"Start date": "2015-03-13"
}
}
}
\ 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