Commit bc10b985 authored by Georgios Dagkakis's avatar Georgios Dagkakis

DemandPlanning plugins moved to separate folder

parent 5241294f
from copy import copy
import json
import time
import random
import operator
import datetime
from dream.plugins import plugin
class AddDemandPlannerGenerator(plugin.InputPreparationPlugin):
""" Input preparation
adds an EventGenerator that will call the Demand Planning algorithm once
"""
def preprocess(self, data):
nodes=data['graph']['node']
data_uri_encoded_input_data = data['input'].get(self.configuration_dict['input_id'], {})
algorithmAttributes=copy(data['general'])
nodes['DPG']={
"name": "DemandPlannerGenerator",
"prioritizeIfCanFinish": 1,
"interval": 1,
"start": 0,
"stop": 0.5,
"_class": "dream.simulation.EventGenerator.EventGenerator",
"method": "dream.simulation.applications.DemandPlanning.executor_ACO.main",
"argumentDict": {'input':data_uri_encoded_input_data, 'algorithmAttributes':algorithmAttributes}
}
#print nodes
return data
\ No newline at end of file
from dream.plugins import plugin
from dream.plugins.TimeSupport import TimeSupportMixin
from datetime import datetime
class DemandPlanningLine(plugin.OutputPreparationPlugin, TimeSupportMixin):
""" Output the queue statistics in a format compatible with Output_viewGraph
"""
def postprocess(self, data):
from dream.simulation.applications.DemandPlanning.Globals import G
utilisation=G.Utilisation
# XXX current implementation for one bottleneck
for bottleneck in ['BE_A_VF78_DSO_3','BE_A_VK18_DKO_5']:
bottleNeckUtilization=G.Utilisation[bottleneck]
dateList=[]
# get the current date from the data
for record_id,record in bottleNeckUtilization.iteritems():
year=str(record_id)[0:4]
week=str(record_id)[4:]
fullDate=datetime.strptime(year+'-'+week+'-0', '%Y-%W-%w')
dateList.append(fullDate)
currentDate=str(min(dateList))
currentDate=currentDate.replace('-', '/')
data['general']['currentDate']=currentDate
data['general']['timeUnit']='week'
self.initializeTimeSupport(data)
result = data['result']['result_list'][-1]
series = []
options = {
"xaxis": {
"mode": "time",
"minTickSize": [1, self.getTimeUnitText()],
}
}
result[bottleneck] = {
"series": series,
"options": options
}
# create the 3 lines
for utilizationType in ['averageUtilization','minUtilization','maxUtilization']:
utilizationList=[]
for record_id,record in bottleNeckUtilization.iteritems():
year=str(record_id)[0:4]
week=str(record_id)[4:]
fullDate=datetime.strptime(year+'-'+week+'-0', '%Y-%W-%w')
utilizationList.append([fullDate,record[utilizationType]])
utilizationList.sort(key=lambda x: x[0], reverse=True)
series.append({
"label": utilizationType,
"data": [((time-datetime(1970, 1, 1)).total_seconds()*1000, value) for (time, value) in utilizationList]
})
return data
from dream.plugins import plugin
class PostProcessDemandPlanning(plugin.OutputPreparationPlugin):
""" Output the result of demand planning in a format compatible with
Output_viewDownloadFile
"""
def postprocess(self, data):
# XXX the event generator should store its result in data and not in global
# variable.
from dream.simulation.applications.DemandPlanning.Globals import G
data['result']['result_list'][-1][self.configuration_dict['output_id']] = {
'name': 'Result.xlsx',
'mime_type': 'application/vnd.ms-excel',
'data': G.reportResults.xlsx.encode('base64')
}
return data
# ===========================================================================
# 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
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