defautl plugins (pre/post-processing) added. to be invoked from __init__ of the platform.

parent 97379e0b
from dream.plugins import plugin
class GatherWIPStat(plugin.InputPreparationPlugin):
def preprocess(self, data):
"""Preprocess the data, for instance reading spreadsheet.
"""
# by default we add an event generator if using queue stats
if data["application_configuration"]["output"]["view_queue_stats"]:
for node in data["graph"]["node"].values():
if node['_class'] in ('Dream.Queue', ):
node['gatherWipStat'] = 1
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
from copy import deepcopy
import json
from zope.dottedname.resolve import resolve
from dream.simulation.LineGenerationJSON import main as simulate_line_json
# helper function to overload a property
def overloaded_property(prop, overload):
prop = deepcopy(prop)
prop.update(overload)
return prop
# helper function to return a default configuration dictionary
def getConfigurationDict(self):
"""Returns the possible nodes to use in the graph editor, and the global
configuration.
"""
return NotImplementedError
class Plugin(object):
"""Base class for pre-post processing Plugin.
"""
def __init__(self, logger=None):
self.logger = logger
class ExecutionPlugin(Plugin):
"""Plugin to handle the execution of multiple simulation runs.
"""
def run(self, data):
"""General execution plugin.
"""
raise NotImplementedError
class InputPreparationPlugin(Plugin):
def preprocess(self, data):
"""Preprocess the data before simulation run.
"""
return data
class OutputPreparationPlugin(Plugin):
def postprocess(self, data):
"""Postprocess the data after simulation run.
"""
return data
class DefaultExecutionPlugin(ExecutionPlugin):
"""Default Execution Plugin just executes one scenario.
"""
def run(self, data):
return json.loads(simulate_line_json(input_data=json.dumps(data)))
class PluginRegistry(object):
"""Registry of plugins.
"""
def __init__(self, logger,
input_preparation_class_list,
output_preparation_class_list,
execution_plugin_class):
self.input_preparation_list = tuple([resolve(name)(logger) for name in
input_preparation_class_list])
self.output_preparation_list = tuple([resolve(name)(logger) for name in
output_preparation_class_list])
self.execution_plugin = resolve(execution_plugin_class)(logger)
def run(self, data):
"""Preprocess, execute & postprocess.
"""
for input_preparation in self.input_preparation_list:
data = input_preparation.preprocess(deepcopy(data))
print 1
data["result"] = self.execution_plugin.run(data)
print 2
print data
for output_preparation in self.output_preparation_list:
data = output_preparation.postprocess(deepcopy(data))
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