Commit 8c8ef0db authored by Dipo Olaitan's avatar Dipo Olaitan

Dates for x-axis of Utilization Charts and Cleaner code

parent a395a1d0
from dream.plugins import plugin
from dream.plugins.TimeSupport import TimeSupportMixin
from datetime import datetime, timedelta
from copy import deepcopy
class StationAllocations(plugin.OutputPreparationPlugin, TimeSupportMixin):
""" Output the queue statistics in a format compatible with Output_viewGraph, for the second widget by week.
""" Output the periodic operational capacity utilisation per project in a bar chart
"""
def postprocess(self, data):
startPeriod = datetime.strptime(data['general']['currentDate'], data['general']['dateFormat'])
for result in data['result']['result_list']:
#result = data['result']['result_list'][0]
bottleNeckUtilizationDict = result['bottleneck_utilization_by_week'] = {}
operationNames = []
byPeriod = dict((period,{}) for period in range(len(result['elementList'][10]['results']['capacityUsed'])))
for station in result['elementList']:
if station.get('family') == 'CapacityStation':
byPeriod = dict((period,{}) for period in range(len(station['results']['capacityUsed'])))
break
opNo = 0
for recd in result['elementList']:
if recd.get('family') == 'CapacityStation':
operationNames.append(recd.get('id'))
projectNames = list(set([rc['project'] for rc in recd['results']['detailedWorkPlan']]))
for prd,pln in enumerate(recd['results']['capacityUsed']):
totalCapa = max(0.01,sum([pln.setdefault(project,0) for project in projectNames]))
totalUtilization = pln["utilization"]
for station in result['elementList']:
if station.get('family') == 'CapacityStation':
operationNames.append(station.get('id'))
projectNames = list(set([rc['project'] for rc in station['results']['detailedWorkPlan']]))
for period,record in enumerate(station['results']['capacityUsed']):
totalCapa = max(0.01,sum([record.setdefault(project,0) for project in projectNames]))
totalUtilization = record["utilization"]
for pr in projectNames:
if pr in byPeriod[prd]:#byPeriod[prd]:
byPeriod[prd][pr].append([opNo,(pln.setdefault(pr,0)/totalCapa * totalUtilization)])
if pr in byPeriod[period]:
byPeriod[period][pr].append([opNo,(record.setdefault(pr,0)/totalCapa * totalUtilization)])
else:
byPeriod[prd][pr] = [[opNo,(pln.setdefault(pr,0)/totalCapa * totalUtilization)]]
byPeriod[period][pr] = [[opNo,(record.setdefault(pr,0)/totalCapa * totalUtilization)]]
opNo += 1
for pd in byPeriod:
for prd in byPeriod:
series = []
currentPeriod = str(startPeriod + timedelta(days=pd))[:10]
#ticks = [[num,oprtn] for num,oprtn in enumerate(operationNames)]
currentPeriod = str(startPeriod + timedelta(days=prd))[:10]
ticks = list(enumerate(operationNames))
options = {"xaxis": {"minTickSize": 1,"ticks": ticks},"series": {"bars": {"show": True,"barWidth": 0.10,"order": 1,"align": "center"},"stack": False}}
bottleNeckUtilizationDict[currentPeriod] = {"series": series,"options": options}
for pj in byPeriod[pd]:
series.append({"label":pj,"data": byPeriod[pd][pj]})
for pj in byPeriod[prd]:
series.append({"label":pj,"data": byPeriod[prd][pj]})
return data
......@@ -4,7 +4,7 @@ from datetime import datetime, timedelta
from copy import deepcopy
class PeriodUtilizations(plugin.OutputPreparationPlugin, TimeSupportMixin):
""" Output the queue statistics in a format compatible with Output_viewGraph, for the second widget by week.
""" Output a line plot of operational capacity utilisations.
"""
def postprocess(self, data):
......@@ -12,37 +12,21 @@ class PeriodUtilizations(plugin.OutputPreparationPlugin, TimeSupportMixin):
startPeriod = datetime.strptime(data['general']['currentDate'], data['general']['dateFormat'])
for result in data['result']['result_list']:
self.initializeTimeSupport(data)
#bottleNeckUtilizationDict = result['capacity_utilization'] = {}
operationNames = []
byPeriod = dict((period,{}) for period in range(len(result['elementList'][10]['results']['capacityUsed'])))
opNo = 0
operationUtil = {}
for recd in result['elementList']:
if recd.get('family') == 'CapacityStation':
operationNames.append(recd.get('id'))
operationUtil[recd.get('id')] = []
#projectNames = list(set([rc['project'] for rc in recd['results']['detailedWorkPlan']]))
for prd,pln in enumerate(recd['results']['capacityUsed']):
currentPeriod = str(startPeriod + timedelta(days=prd))[:10]
#totalCapa = max(0.01,sum([pln.setdefault(project,0) for project in projectNames]))
totalUtilization = pln["utilization"]
operationUtil[recd.get('id')].append([prd,pln["utilization"]])
ticks = [lb[0] for lb in operationUtil[recd.get('id')]]
currentPeriod = startPeriod + timedelta(days=prd)
timestamp = (currentPeriod - datetime(1970, 1, 1)).total_seconds()
operationUtil[recd.get('id')].append([timestamp*1000,pln["utilization"]])
series = []
options = {"xaxis": {"ticks": ticks, "minTickSize": [1, self.getTimeUnitText()]}}
options = {"xaxis": {"mode":"time", "minTickSize": [1, self.getTimeUnitText()]}}
result['capacity_utilization'] = {"series": series,"options": options}
for operation in operationUtil:
series.append({"label": operation, "data": operationUtil[operation]})
#currentPeriod = str(startPeriod + timedelta(days=pd))[:10]
#ticks = [[num,oprtn] for num,oprtn in enumerate(operationNames)]
#label = operation
#ticks = list(enumerate(operationNames))
#options = {"xaxis": {"minTickSize": 1,"ticks": ticks},"series": {"bars": {"show": True,"barWidth": 0.10,"order": 1,"align": "center"},"stack": False}}
#bottleNeckUtilizationDict = {"series": series,"options": options}
#for pj in byPeriod[pd]:
#series.append({"label":operation,"data": operationUtil[operation]})
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