Commit 646dc69a authored by Jérome Perrin's avatar Jérome Perrin

example plugin to read a spreadsheet attached in the json ( with Input_viewAttachDocument )

parent 0303aa51
from copy import copy
import json
import time
import random
import operator
import StringIO
import xlrd
from dream.plugins import plugin
class ExampleReadAttachedSpreadsheet(plugin.OutputPreparationPlugin):
""" Example on how to read an excel spreadsheet
"""
def preprocess(self, data):
""" Example showing how to read an attached file
"""
# Attachement is encoded in data uri, ie data:application/excel;base64,***
data_uri_encoded_input_data = data['input'][self.configuration_dict['input_id']]
mime_type, attachement_data = data_uri_encoded_input_data[len('data:'):].split(';base64,', 1)
attachement_data = attachement_data.decode('base64')
workbook = xlrd.open_workbook(file_contents=attachement_data)
print "This spreadsheet contains sheets:", workbook.sheet_names()
raise ValueError(workbook.sheet_names())
return data
\ No newline at end of file
{
"application_configuration": {
"general": {
"properties": {
"confidenceLevel": {
"default": 0.95,
"description": "Confidence level for statistical analysis of stochastic experiments",
"name": "Confidence level",
"type": "number"
},
"currentDate": {
"default": "2014/10/01",
"description": "The day the experiment starts, in YYYY/MM/DD format",
"name": "Simulation start time",
"type": "string"
},
"distributorURL": {
"default": "",
"description": "URL of distributor",
"name": "Distributor URL",
"type": "string"
},
"maxSimTime": {
"default": 100,
"description": "Length of the simulation run",
"name": "Length of experiment",
"type": "number"
},
"max_slave_count": {
"description": "Maximum number of nodes to use",
"name": "Number of simulation nodes",
"type": "number"
},
"name": {
"default": "",
"description": "The name that will appear in the interface",
"name": "Name of the Scenario",
"type": "string"
},
"numberOfAntsPerGenerations": {
"default": 20,
"description": "Number of ants per generation",
"name": "Number of ants per generation",
"type": "number"
},
"numberOfGenerations": {
"default": 10,
"description": "The number of generations",
"name": "Number of generations",
"type": "number"
},
"numberOfReplications": {
"default": 10,
"description": "Number of replications to run",
"name": "Number of replications",
"type": "number"
},
"numberOfSolutions": {
"default": 4,
"description": "Number of solutions",
"name": "Number of solutions",
"type": "number"
},
"processTimeout": {
"default": 10,
"description": "Number of seconds before the calculation process is interrupted",
"name": "Process timeout",
"type": "number"
},
"seed": {
"default": "",
"description": "When using the same seed, the random number generator produce the same sequence of numbers",
"name": "Seed for random number generator",
"type": "string"
},
"timeUnitPerDay": {
"default": 24,
"description": "Used for input and reporting widgets. Forexample, 24 means that simulation clock time unit is one hour.",
"name": "Number of time units per day",
"type": "number"
},
"trace": {
"default": false,
"description": "Create an excel trace file (true or false)",
"name": "Output trace",
"type": "boolean"
}
}
},
"input": {
"debug": {
"gadget": "Input_viewDebugJson",
"title": "Debug JSON",
"type": "object_view"
},
"view": {
"gadget": "Input_viewProductionLine",
"title": "Production Line",
"type": "object_view"
},
"view_attach_spreadsheet": {
"gadget": "Input_viewAttachDocument",
"input_id": "attached_document",
"title": "Attach Document",
"type": "object_view"
},
"view_management": {
"gadget": "Input_viewDocumentManagement",
"title": "Manage document",
"type": "object_view"
},
"view_result": {
"gadget": "Input_viewResultList",
"title": "Results",
"type": "object_view"
},
"view_run_simulation": {
"gadget": "Input_viewSimulation",
"title": "Run Simulation",
"type": "object_view"
}
},
"output": {
"view_component_gantt": {
"configuration": {
"properties": {}
},
"gadget": "Output_viewJobGantt",
"title": "Component Gantt",
"type": "object_view"
},
"view_component_schedule_spreadsheet": {
"configuration": {
"columns": [
{
"format": "date-time",
"name": "Component ID",
"type": "string"
},
{
"name": "Sequence",
"type": "string"
},
{
"name": "Station",
"type": "string"
},
{
"format": "date-time",
"name": "Entry",
"type": "string"
},
{
"format": "date-time",
"name": "Exit",
"type": "string"
}
]
},
"gadget": "Output_viewJobScheduleSpreadsheet",
"title": "Component Schedule",
"type": "object_view"
},
"view_exit_stats": {
"configuration": {
"properties": {
"lifespan": {
"type": "number"
},
"taktTime": {
"type": "number"
},
"throughput": {
"type": "number"
}
}
},
"gadget": "Output_viewExitStatistics",
"title": "Exit Statistics",
"type": "object_view"
},
"view_operator_gantt": {
"configuration": {
"properties": {}
},
"gadget": "Output_viewJobGantt",
"title": "Operator Gantt",
"type": "object_view"
},
"view_station_utilization": {
"configuration": {
"columns": []
},
"gadget": "Output_viewStationUtilisationGraph",
"title": "Station Utilization",
"type": "object_view"
}
},
"post_processing_plugin_list": [],
"pre_processing_plugin_list": [
{
"_class": "dream.plugins.Debug.Debug",
"argument": "Argument Value"
},
{
"_class": "dream.plugins.ExampleReadAttachedSpreadsheet.ExampleReadAttachedSpreadsheet",
"input_id": "attached_document"
}
],
"processing_plugin": {
"_class": "dream.plugins.ACO.ACO"
}
},
"class_definition": {
"Dream.ConditionalBuffer": {
"_class": "node",
"allOf": [
{
"$ref": "#/node"
},
{
"properties": {
"capacity": {
"$ref": "#/definitions/_capacity",
"required": true
},
"id": {
"default": "B",
"type": "string"
},
"name": {
"default": "Cam Queue",
"type": "string"
},
"schedulingRule": {
"$ref": "#/definitions/_schedulingRule",
"required": true
}
},
"type": "object"
}
],
"css": {
"backgroundColor": "#eff",
"backgroundImage": "linear-gradient(to bottom, #eff 0%, #dee 100%)",
"border": "1px solid #bcc"
},
"description": "A buffer where entities can be hold until the next station is ready to process them and a certain condition is met",
"name": "Cam Queue"
},
"Dream.Edge": {
"_class": "edge",
"allOf": [
{
"$ref": "#/edge"
}
],
"description": "Connect stations together"
},
"Dream.ExitJobShop": {
"_class": "node",
"allOf": [
{
"$ref": "#/node"
},
{
"properties": {
"id": {
"default": "E",
"required": true
},
"name": {
"default": "Exit",
"type": "string"
}
},
"type": "object"
}
],
"css": {
"backgroundColor": "#eef",
"backgroundImage": "linear-gradient(to bottom, #eef 0%, #dde 100%)",
"border": "1px solid #ccb"
},
"description": "A station where entities exits from the system",
"name": "Exit",
"shape": "rectangle"
},
"Dream.MachineJobShop": {
"_class": "node",
"allOf": [
{
"$ref": "#/node"
},
{
"properties": {
"id": {
"default": "M",
"required": true,
"type": "string"
},
"name": {
"default": "Machine",
"type": "string"
},
"operationType": {
"$ref": "#/definitions/_operationType",
"required": true
}
},
"type": "object"
}
],
"css": {
"backgroundColor": "#fef",
"backgroundImage": "linear-gradient(to bottom, #fef 0%, #ede 100%)",
"border": "1px solid #cbc"
},
"description": "A station processing items for some time given by a distribution provided by the entities that are processed",
"name": "Machine"
},
"Dream.MouldAssembly": {
"_class": "node",
"allOf": [
{
"$ref": "#/Dream.MachineJobShop"
},
{
"id": {
"default": "MA",
"type": "string"
},
"name": {
"default": "Assembly",
"type": "string"
}
}
],
"css": {
"backgroundColor": "#fef",
"backgroundImage": "linear-gradient(to bottom, #fef 0%, #ede 100%)",
"border": "1px solid #cbc"
},
"description": "A station that assembles different components of the same production order into a single entity",
"name": "Assembly"
},
"Dream.MouldAssemblyBuffer": {
"_class": "node",
"allOf": [
{
"$ref": "#/Dream.ConditionalBuffer"
},
{
"properties": {
"id": {
"default": "AB",
"type": "string"
},
"name": {
"default": "Assembly Queue",
"type": "string"
}
},
"type": "object"
}
],
"css": {
"backgroundColor": "#eff",
"backgroundImage": "linear-gradient(to bottom, #eff 0%, #dee 100%)",
"border": "1px solid #bcc"
},
"description": "A buffer where entities can be hold until the next assembly is ready to process all the entities from the same production-order",
"name": "Assembly Queue"
},
"Dream.OperatorManagedJob": {
"_class": "node",
"allOf": [
{
"$ref": "#/node"
},
{
"properties": {
"id": {
"default": "PM",
"required": true,
"type": "string"
},
"name": {
"default": "Operator",
"type": "string"
},
"schedulingRule": {
"$ref": "#/definitions/_schedulingRule",
"default": "WT",
"required": true
}
},
"type": "object"
}
],
"css": {
"backgroundColor": "#fdd",
"backgroundImage": "linear-gradient(to bottom, #fdd 0%, #dcc 100%)",
"border": "1px solid #cbb"
},
"description": "A resource that operates stations",
"name": "Operator"
},
"Dream.OrderDecomposition": {
"_class": "node",
"allOf": [
{
"$ref": "#/node"
},
{
"id": {
"default": "D",
"type": "string"
},
"name": {
"default": "Decomposition",
"type": "string"
}
}
],
"css": {
"backgroundColor": "#eff",
"backgroundImage": "linear-gradient(to bottom, #eff 0%, #dee 100%)",
"border": "1px solid #bcc"
},
"description": "A station where production-orders are decomposed into components ",
"name": "Decomposition"
},
"Dream.QueueJobShop": {
"_class": "node",
"allOf": [
{
"$ref": "#/node"
},
{
"properties": {
"capacity": {
"$ref": "#/definitions/_capacity",
"required": true
},
"id": {
"default": "Q",
"type": "string"
},
"name": {
"default": "Queue",
"type": "string"
},
"schedulingRule": {
"$ref": "#/definitions/_schedulingRule",
"required": true
}
},
"type": "object"
}
],
"css": {
"backgroundColor": "#eff",
"backgroundImage": "linear-gradient(to bottom, #eff 0%, #dee 100%)",
"border": "1px solid #bcc"
},
"description": "A queue for jobs",
"name": "Queue"
},
"definitions": {
"_capacity": {
"default": 1,
"description": "capacity of the queue. -1 means infinite",
"oneOf": [
{
"enum": [
-1
]
},
{
"multipleOf": 1
}
],
"type": "number"
},
"_dist": {
"allOf": [
{
"properties": {
"distribution": {
"default": "Fixed",
"enum": [
"Fixed",
"Exp",
"Normal",
"Lognormal",
"Binomial",
"Poisson",
"Logistic",
"Caucy",
"Geometric",
"Gama",
"Weibull"
],
"type": "string"
}
},
"type": "object"
},
{
"oneOf": [
{
"$ref": "#/definitions/distributionTypes/_fixed"
},
{
"$ref": "#/definitions/distributionTypes/_exp"
},
{
"$ref": "#/definitions/distributionTypes/_normal"
},
{
"$ref": "#/definitions/distributionTypes/_lognormal"
},
{
"$ref": "#/definitions/distributionTypes/_binomial"
},
{
"$ref": "#/definitions/distributionTypes/_poisson"
},
{
"$ref": "#/definitions/distributionTypes/_logistic"
},
{
"$ref": "#/definitions/distributionTypes/_caucy"
},
{
"$ref": "#/definitions/distributionTypes/_geometric"
},
{
"$ref": "#/definitions/distributionTypes/_gama"
},
{
"$ref": "#/definitions/distributionTypes/_weibull"
}
]
}
]
},
"_failureDist": {
"allOf": [
{
"properties": {
"failureDistribution": {
"default": "No",
"enum": [
"No",
"Fixed",
"Availability"
],
"type": "string"
}
},
"type": "object"
},
{
"oneOf": [
{
"$ref": "#/definitions/distributionTypes/_fixedFailure"
},
{
"$ref": "#/definitions/distributionTypes/_no"
},
{
"$ref": "#/definitions/distributionTypes/_availability"
}
]
}
]
},
"_operationType": {
"description": "the type of operations that are performed manually in the machine",
"id": "operationType",
"name": "Operation type",
"properties": {
"operationType": {
"enum": [
"MT-Load",
"MT-Load-Setup",
"MT-Load-Setup-Processing"
],
"type": "string"
}
}
},
"_schedulingRule": {
"default": "FIFO",
"description": "Scheduling Rule, one of FIFO Priority EDD EOD NumStages RPC LPT SPT MS WINQ",
"enum": [
"FIFO",
"Priority",
"EDD",
"EOD",
"NumStages",
"RPC",
"LPT",
"SPT",
"MS",
"WINQ",
"WT"
],
"type": "string"
},
"distributionTypes": {
"_availability": {
"description": "Availability",
"name": "Availability",
"properties": {
"MTTF": {
"default": 40,
"description": "Mean Time To Failure",
"required": true,
"type": "number"
},
"MTTR": {
"default": 10,
"description": "Mean Time To Failure",
"required": true,
"type": "number"
},
"availability": {
"default": 0,
"required": true,
"type": "number"
},
"repairman": {
"description": "Repairman",
"required": true,
"type": "string"
}
},
"type": "object"
},
"_binomial": {
"description": "Binomial",
"name": "Binomial",
"properties": {
"mean": {
"default": 0,
"type": "number"
},
"size": {
"default": 0,
"type": "number"
}
},
"type": "object"
},
"_caucy": {
"description": "Caucy",
"name": "Caucy",
"properties": {
"location": {
"default": 0,
"type": "number"
},
"scale": {
"default": 0,
"type": "number"
}
},
"type": "object"
},
"_exp": {
"description": "Exponential",
"name": "Exp",
"properties": {
"mean": {
"default": 0,
"required": true,
"type": "number"
}
},
"type": "object"
},
"_fixed": {
"description": "Fixed",
"name": "Fixed",
"properties": {
"mean": {
"default": 0.75,
"required": true,
"type": "number"
}
},
"type": "object"
},
"_fixedFailure": {
"description": "Fixed",
"name": "Fixed",
"properties": {
"MTTF": {
"default": 40,
"description": "Mean Time To Failure",
"required": true,
"type": "number"
},
"MTTR": {
"default": 10,
"description": "Mean Time To Repair",
"required": true,
"type": "number"
},
"repairman": {
"description": "Repairman",
"required": true,
"type": "string"
}
},
"type": "object"
},
"_gama": {
"description": "Gama",
"name": "Gama",
"properties": {
"rate": {
"default": 0,
"required": true,
"type": "number"
},
"shape": {
"default": 0,
"required": true,
"type": "number"
}
},
"type": "object"
},
"_geometric": {
"description": "Geometric",
"name": "Geometric",
"properties": {
"probability": {
"default": 0,
"required": true,
"type": "number"
}
},
"type": "object"
},
"_logistic": {
"description": "Logistic",
"name": "Logistic",
"properties": {
"location": {
"default": 0,
"required": true,
"type": "number"
},
"scale": {
"default": 0,
"required": true,
"type": "number"
}
},
"type": "object"
},
"_lognormal": {
"description": "Lognormal",
"name": "Lognormal",
"properties": {
"mean": {
"default": 0,
"name": "Mean",
"type": "number"
},
"stdev": {
"default": 0,
"name": "Standard Deviation",
"type": "number"
}
},
"type": "object"
},
"_no": {
"description": "None",
"name": "No",
"type": "string"
},
"_normal": {
"description": "Normal",
"name": "Normal",
"properties": {
"mean": {
"default": 0,
"required": true,
"type": "number"
},
"stdev": {
"default": 0,
"required": true,
"type": "number"
}
},
"type": "object"
},
"_poisson": {
"description": "Poisson",
"name": "Poisson",
"properties": {
"lambda": {
"default": 0,
"type": "number"
}
},
"type": "object"
},
"_weibull": {
"description": "Weibull",
"name": "Weibull",
"properties": {
"scale": {
"default": 0,
"required": true,
"type": "number"
},
"shape": {
"default": 0,
"required": true,
"type": "number"
}
},
"type": "object"
}
}
},
"edge": {
"description": "Base definition for edge",
"properties": {
"_class": {
"type": "string"
},
"destination": {
"type": "string"
},
"name": {
"type": "string"
},
"source": {
"type": "string"
}
},
"required": [
"_class",
"source",
"destination"
],
"type": "object"
},
"node": {
"description": "Base definition for node",
"properties": {
"_class": {
"type": "string"
},
"capacity": {
"$ref": "#/definitions/_capacity",
"required": true
},
"coordinate": {
"properties": {
"left": "number",
"top": "number"
},
"type": "object"
},
"id": {
"default": "M",
"required": true,
"type": "string"
},
"name": {
"default": "Machine",
"type": "string"
},
"operationType": {
"$ref": "#/definitions/_operationType",
"required": true
},
"schedulingRule": {
"$ref": "#/definitions/_schedulingRule",
"required": true
}
},
"required": [
"name",
"_class"
],
"type": "object"
}
},
"constraints": {},
"general": {
"confidenceLevel": 0.95,
"currentDate": "2015/01/01",
"distributorURL": "",
"maxSimTime": -1,
"max_slave_count": 1,
"name": "dream(4).json",
"numberOfAntsPerGenerations": 20,
"numberOfGenerations": 1,
"numberOfReplications": 1,
"numberOfSolutions": 10,
"processTimeout": 60,
"seed": "",
"timeUnitPerDay": 24,
"trace": "false"
},
"graph": {
"edge": {},
"node": {}
},
"input": {},
"result": {}
}
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