Commit a5c2c8af authored by Georgios Dagkakis's avatar Georgios Dagkakis

Merge branch 'downloadTrace'

parents d8c8e265 337c9aea
from dream.plugins import plugin
class ParseTraceFile(plugin.OutputPreparationPlugin):
""" Output the result of demand planning in a format compatible with
Output_viewDownloadFile
"""
def postprocess(self, data):
outPutFile=None
for record in data['result']['result_list'][-1]['elementList']:
if record.get('id',None)=='TraceFile':
outPutFile=record['results']['trace']
data['result']['result_list'][-1][self.configuration_dict['output_id']] = {
'name': 'Trace.xls',
'mime_type': 'application/vnd.ms-excel',
'data': outPutFile
}
return data
......@@ -205,11 +205,23 @@
"gadget": "Output_viewSpreadsheet",
"title": "Tabular_Results",
"type": "object_view"
}
},
"view_downaload_spreadsheet": {
"configuration": {
"output_id": "trace_spreadSheet"
},
"gadget": "Output_viewDownloadFile",
"title": "Download Result Spreadsheet",
"type": "object_view"
}
},
"post_processing": {
"description": "",
"plugin_list": [
{
"_class": "dream.plugins.ParseTraceFile.ParseTraceFile",
"output_id": "trace_spreadSheet"
},
{
"_class": "dream.plugins.DefaultTabularExit.DefaultTabularExit"
}
......
......@@ -668,6 +668,10 @@ def main(argv=[], input_data=None):
#output trace to excel
if(G.trace=="Yes"):
ExcelHandler.outputTrace('trace'+str(i))
import StringIO
traceStringIO = StringIO.StringIO()
G.traceFile.save(traceStringIO)
encodedTrace=traceStringIO.getvalue().encode('base64')
ExcelHandler.resetTrace()
G.outputJSON['_class'] = 'Dream.Simulation';
......@@ -680,7 +684,17 @@ def main(argv=[], input_data=None):
#output data to JSON for every object in the topology
for object in G.ObjectResourceList + G.EntityList + G.ObjList:
object.outputResultsJSON()
# output the trace as encoded if it is set on
if G.trace=="Yes":
# XXX discuss names on this
jsonTRACE = {'_class': 'Dream.Simulation',
'id': 'TraceFile',
'results': {'trace':encodedTrace}
}
G.outputJSON['elementList'].append(jsonTRACE)
outputJSONString=json.dumps(G.outputJSON, indent=True)
if 0:
G.outputJSONFile=open('outputJSON.json', mode='w')
......
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