Commit a374dd32 authored by Georgios Dagkakis's avatar Georgios Dagkakis

gantt of stations also added in capacity instance

parent 074486df
......@@ -7,57 +7,61 @@ from dream.plugins.TimeSupport import TimeSupportMixin
class CapacityStationGantt(plugin.OutputPreparationPlugin, TimeSupportMixin):
def _generateRandomTaskList(self):
"""Generate some random tasks for the example.
Take care of not using reserved id '0'
"""
for order_id in range(3):
for order_line_id in range(random.randint(1, 6)):
start_time = random.random() * 10
duration = random.random() * 10
yield dict(id='%s_%s' % (order_id, order_line_id),
order_id="O%s" % order_id,
start_time=start_time,
duration=duration)
def postprocess(self, data):
print 2
"""Post process the data for Gantt gadget
"""
return data
# self.initializeTimeSupport(data)
#
# date_format = '%d-%m-%Y %H:%M'
#
# task_dict = {}
# for task in self._generateRandomTaskList():
#
# # Add the order if not already present
# if task['order_id'] not in task_dict:
# task_dict[task['order_id']] = dict(
# id=task['order_id'],
# text='Order %s' % task['order_id'],
# type='project',
# open=True)
#
# task_dict[task['id']] = dict(
# id=task['id'],
# parent=task['order_id'],
# text='Task %s' % task['id'],
# start_date=self.convertToRealWorldTime(
# task['start_time']).strftime(date_format),
# stop_date=self.convertToRealWorldTime(
# task['start_time'] + task['duration']).strftime(date_format),
# open=True,
# duration=task['duration'])
#
# result = data['result']['result_list'][-1]
# result[self.configuration_dict['output_id']] = dict(
# time_unit=self.getTimeUnitText(),
# task_list=sorted(task_dict.values(),
# key=lambda task: (task.get('order_id'),
# task.get('type') == 'project',
# task.get('start_date'))))
#
# return data
# in this instance there is not need to define start time
data['general']['dateFormat']='%Y/%m/%d'
self.initializeTimeSupport(data)
date_format = '%d-%m-%Y %H:%M'
resultElements=data['result']['result_list'][-1]['elementList']
task_dict = {}
# loop in the results to find CapacityProjects
for element in resultElements:
if element['_class']=="Dream.CapacityStation":
# add the project in the task_dict
task_dict[element['id']] = dict(
id=element['id'],
text='Station %s' % element['id'],
type='station',
open=False)
# loop in the project schedule to create the sub-tasks
detailedWorkPlan=element['results'].get('detailedWorkPlan',{})
projectIds=[]
for record in detailedWorkPlan:
if record['project'] not in projectIds:
projectIds.append(record['project'])
for projectId in projectIds:
timesInStation=[]
for record in detailedWorkPlan:
if record['project']==projectId:
timesInStation.append(float(record['time']))
entranceTime=int(min(timesInStation))
exitTime=int(max(timesInStation)+1)
task_dict[element['id']+projectId] = dict(
id=element['id']+projectId,
parent=element['id'],
text=projectId,
start_date=self.convertToRealWorldTime(entranceTime).strftime(date_format),
stop_date=self.convertToRealWorldTime(exitTime).strftime(date_format),
open=False,
duration=exitTime-entranceTime,
entranceTime=entranceTime
)
import json
outputJSONString=json.dumps(task_dict, indent=5)
outputJSONFile=open('taskDict.json', mode='w')
outputJSONFile.write(outputJSONString)
# return the result to the gadget
result = data['result']['result_list'][-1]
result[self.configuration_dict['output_id']] = dict(
time_unit=self.getTimeUnitText(),
task_list=sorted(task_dict.values(),
key=lambda task: (task.get('parent'),
task.get('type') == 'station',
task.get('entranceTime'),
task.get('id'))))
return 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