def renderTemplate(template, fs, modelDir="", absolutePaths=False, datastoreNames={}): ''' Render the model template to an HTML string. By default render a blank one for new input. If modelDir is valid, render results post-model-run. If absolutePaths, the HTML can be opened without a server. ''' # Our HTML template for the interface: with fs.open("models/solarEngineering.html") as tempFile: template = Template(tempFile.read()) try: inJson = json.load(fs.open(pJoin(modelDir, "allInputData.json"))) modelPath, modelName = pSplit(modelDir) deepPath, user = pSplit(modelPath) inJson["modelName"] = modelName inJson["user"] = user allInputData = json.dumps(inJson) except (IOError, HdfsFileNotFoundException): allInputData = None try: allOutputData = fs.open(pJoin(modelDir, "allOutputData.json")).read() except (HdfsFileNotFoundException, IOError): allOutputData = None if absolutePaths: # Parent of current folder. pathPrefix = __metaModel__._omfDir else: pathPrefix = "" try: inputDict = json.load(fs.open(pJoin(modelDir, "allInputData.json"))) except (IOError, HdfsFileNotFoundException): pass return template.render(allInputData=allInputData, allOutputData=allOutputData, modelStatus=getStatus(modelDir, fs), pathPrefix=pathPrefix, datastoreNames=datastoreNames)
def renderTemplate(template, fs, modelDir="", absolutePaths=False, datastoreNames={}): """ Render the model template to an HTML string. By default render a blank one for new input. If modelDir is valid, render results post-model-run. If absolutePaths, the HTML can be opened without a server. """ # Our HTML template for the interface: with fs.open("models/gridlabMulti.html") as tempFile: template = Template(tempFile.read()) try: inJson = json.load(fs.open(pJoin(modelDir, "allInputData.json"))) modelPath, modelName = pSplit(modelDir) deepPath, user = pSplit(modelPath) inJson["modelName"] = modelName inJson["user"] = user allInputData = json.dumps(inJson) except HdfsFileNotFoundException: allInputData = None except IOError: allInputData = None try: allOutputData = fs.open(pJoin(modelDir, "allOutputData.json")).read() except HdfsFileNotFoundException: allOutputData = None except IOError: allOutputData = None if absolutePaths: # Parent of current folder. pathPrefix = __metaModel__._omfDir else: pathPrefix = "" feederList = [] feederIDs = [] try: inputDict = json.load(fs.open(pJoin(modelDir, "allInputData.json"))) for key in inputDict: if key.startswith("feederName"): feederIDs.append(key) feederList.append(inputDict[key]) except HdfsFileNotFoundException: pass except IOError: pass with open("templates/footer.html", "r") as footer_file: footer = footer_file.read() return template.render( allInputData=allInputData, allOutputData=allOutputData, modelStatus=getStatus(modelDir, fs), pathPrefix=pathPrefix, datastoreNames=datastoreNames, feederIDs=feederIDs, feederList=feederList, footer=footer, )