-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/dpinney/omf
- Loading branch information
Showing
12 changed files
with
656 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<head> | ||
{{ omfHeaders }} | ||
<script src="{{pathPrefix}}/static/highcharts4.src.js"></script> | ||
</head> | ||
<body> | ||
{{ omfModelTitle }} | ||
<p class="reportTitle">Model Input</p> | ||
<div id="input" class="content"> | ||
<form name="inputForm" action="/runModel/" onsubmit="event.preventDefault(); return isFormValid();" method="post"> | ||
<!-- Required Inputs --> | ||
<div class="shortInput"> | ||
<label>Model Type <a href="https://github.com/dpinney/omf/wiki/Models:-derConsumer" target="blank">Help?</a></label> | ||
<input type="text" id="modelType" name="modelType" value="{{modelName}}" readonly/> | ||
</div> | ||
<div class="shortInput"> | ||
<label>Model Name</label> | ||
<input type="text" id="modelName" name="modelName" value="{{allInputDataDict.modelName}}"pattern="^[\w\s\d\.-]+$" required="required"> | ||
</div> | ||
<div class="shortInput"> | ||
<label>User</label> | ||
<input type="text" id="user" name="user" value="{{allInputDataDict.user}}"readonly/> | ||
</div> | ||
<div class="shortInput"> | ||
<label>Created</label> | ||
<input type="text" id="created" name="created" value="{{allInputDataDict.created}}"readonly/> | ||
</div> | ||
<div class="shortInput"> | ||
<label>Run Time</label> | ||
<input type="text" id="runTime" name="runTime" value="{{allInputDataDict.runTime}}"readonly/> | ||
</div> | ||
<!-- Model Specific Inputs --> | ||
<div class="wideInput"> | ||
<p class="inputSectionHeader">System Parameters</p> | ||
</div> | ||
<hr> | ||
<div class="shortInput"> | ||
<label class="tooltip">Input 1<span class="classic">Enter an input of any kind.</span></label> | ||
<input type="text" id="input1" name="input1" value="{{allInputDataDict.input1}}"required="required" placeholder="abc1 Easy as..."/> | ||
</div> | ||
<div class="shortInput"> | ||
<label class="tooltip">Input 2<span class="classic">Enter an input of another kind.</span></label> | ||
<input type="text" id="input2" name="input2" value="{{allInputDataDict.input2}}"required="required" placeholder="123 Or Simple as.."/> | ||
</div> | ||
{{ omfModelButtons }} | ||
</form> | ||
</div> | ||
{{ omfRunDebugBlock }} | ||
{% if modelStatus == 'finished' %} | ||
<!-- Output tables, graphs, etc --> | ||
<div id="output"> | ||
<!-- Integer Sum Table --> | ||
<p class="reportTitle">Model Skeleton Integer Sum</p> | ||
<div id="analysisSummary" class="content"> | ||
<div class="shortInput"> | ||
<strong>Input 1</strong> | ||
<p id="input1Out">{{allInputDataDict.input1}}</p> | ||
</div> | ||
<div class="shortInput"> | ||
<strong>Input 2</strong> | ||
<p id="input2Out">{{allInputDataDict.input2}}</p> | ||
</div> | ||
<div class="shortInput"> | ||
<strong>Output</strong> | ||
<p id="sumOut">{{allOutputDataDict.output}}</p> | ||
</div> | ||
</div> | ||
{{ rawOutputFiles }} | ||
</div> | ||
{% endif %} | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
''' A model skeleton for future models: Calculates the sum of two integers. ''' | ||
|
||
import warnings | ||
# warnings.filterwarnings("ignore") | ||
|
||
import shutil, datetime | ||
from os.path import join as pJoin | ||
|
||
# OMF imports | ||
from omf import feeder | ||
from omf.models.voltageDrop import drawPlot | ||
from omf.models import __neoMetaModel__ | ||
from omf.models.__neoMetaModel__ import * | ||
|
||
# Model metadata: | ||
modelName, template = __neoMetaModel__.metadata(__file__) | ||
hidden = True | ||
|
||
def castAddInputs(val1,val2): | ||
''' Casts string inputs to appropriate type and returns their sum. | ||
If inputs are cast to floats, rounds their sum to avoid float subtraction errors.''' | ||
try: | ||
cast1 = int(val1) | ||
cast2 = int(val2) | ||
return cast1+cast2 | ||
except ValueError: | ||
try: | ||
cast1 = float(val1) | ||
cast2 = float(val2) | ||
#Find longest decimal place of the numbers and round their sum to that place to avoid float arithmetic errors | ||
decPl1 = val1.strip()[::-1].find('.') | ||
decPl2 = val2.strip()[::-1].find('.') | ||
#valX.strip() used instead of str(castX) because str(castX) may return scientific notation | ||
roundedSum = round(cast1+cast2,max(decPl1,decPl2,1)) | ||
return roundedSum | ||
except ValueError: | ||
return val1+val2 | ||
|
||
def work(modelDir, inputDict): | ||
''' Run the model in its directory. ''' | ||
# Delete output file every run if it exists | ||
outData = {} | ||
# Model operations goes here. | ||
inputOne = inputDict.get("input1", 123) | ||
inputTwo = inputDict.get("input2", 867) | ||
output = str(castAddInputs(inputOne,inputTwo)) | ||
outData["output"] = output | ||
# Model operations typically ends here. | ||
# Stdout/stderr. | ||
outData["stdout"] = "Success" | ||
outData["stderr"] = "" | ||
return outData | ||
|
||
def new(modelDir): | ||
''' Create a new instance of this model. Returns true on success, false on failure. ''' | ||
defaultInputs = { | ||
"user" : "admin", | ||
"modelType": modelName, | ||
"input1": "abc1 Easy as...", | ||
"input2": "123 Or Simple as...", | ||
"created":str(datetime.datetime.now()) | ||
} | ||
return __neoMetaModel__.new(modelDir, defaultInputs) | ||
|
||
@neoMetaModel_test_setup | ||
def _tests(): | ||
# Location | ||
modelLoc = pJoin(__neoMetaModel__._omfDir,"data","Model","admin","Automated Testing of " + modelName) | ||
# Blow away old test results if necessary. | ||
try: | ||
shutil.rmtree(modelLoc) | ||
except: | ||
# No previous test results. | ||
pass | ||
# Create New. | ||
new(modelLoc) | ||
# Pre-run. | ||
__neoMetaModel__.renderAndShow(modelLoc) | ||
# Run the model. | ||
__neoMetaModel__.runForeground(modelLoc) | ||
# Show the output. | ||
__neoMetaModel__.renderAndShow(modelLoc) | ||
|
||
if __name__ == '__main__': | ||
#_tests() | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<head> | ||
{{ omfHeaders }} | ||
<script src="{{pathPrefix}}/static/highcharts4.src.js"></script> | ||
</head> | ||
<body> | ||
{{ omfModelTitle }} | ||
<p class="reportTitle">Model Input</p> | ||
<div id="input" class="content"> | ||
<form name="inputForm" action="/runModel/" onsubmit="event.preventDefault(); return isFormValid();" method="post"> | ||
<!-- Required Inputs --> | ||
<div class="shortInput"> | ||
<label>Model Type <a href="https://github.com/dpinney/omf/wiki/Models:-derUtilityCost" target="blank">Help?</a></label> | ||
<input type="text" id="modelType" name="modelType" value="{{modelName}}" readonly/> | ||
</div> | ||
<div class="shortInput"> | ||
<label>Model Name</label> | ||
<input type="text" id="modelName" name="modelName" value="{{allInputDataDict.modelName}}"pattern="^[\w\s\d\.-]+$" required="required"> | ||
</div> | ||
<div class="shortInput"> | ||
<label>User</label> | ||
<input type="text" id="user" name="user" value="{{allInputDataDict.user}}"readonly/> | ||
</div> | ||
<div class="shortInput"> | ||
<label>Created</label> | ||
<input type="text" id="created" name="created" value="{{allInputDataDict.created}}"readonly/> | ||
</div> | ||
<div class="shortInput"> | ||
<label>Run Time</label> | ||
<input type="text" id="runTime" name="runTime" value="{{allInputDataDict.runTime}}"readonly/> | ||
</div> | ||
<!-- Model Specific Inputs --> | ||
<div class="wideInput"> | ||
<p class="inputSectionHeader">System Parameters</p> | ||
</div> | ||
<hr> | ||
<div class="shortInput"> | ||
<label class="tooltip">Input 1<span class="classic">Enter an input of any kind.</span></label> | ||
<input type="text" id="input1" name="input1" value="{{allInputDataDict.input1}}"required="required" placeholder="abc1 Easy as..."/> | ||
</div> | ||
<div class="shortInput"> | ||
<label class="tooltip">Input 2<span class="classic">Enter an input of another kind.</span></label> | ||
<input type="text" id="input2" name="input2" value="{{allInputDataDict.input2}}"required="required" placeholder="123 Or Simple as.."/> | ||
</div> | ||
{{ omfModelButtons }} | ||
</form> | ||
</div> | ||
{{ omfRunDebugBlock }} | ||
{% if modelStatus == 'finished' %} | ||
<!-- Output tables, graphs, etc --> | ||
<div id="output"> | ||
<!-- Integer Sum Table --> | ||
<p class="reportTitle">Model Skeleton Integer Sum</p> | ||
<div id="analysisSummary" class="content"> | ||
<div class="shortInput"> | ||
<strong>Input 1</strong> | ||
<p id="input1Out">{{allInputDataDict.input1}}</p> | ||
</div> | ||
<div class="shortInput"> | ||
<strong>Input 2</strong> | ||
<p id="input2Out">{{allInputDataDict.input2}}</p> | ||
</div> | ||
<div class="shortInput"> | ||
<strong>Output</strong> | ||
<p id="sumOut">{{allOutputDataDict.output}}</p> | ||
</div> | ||
</div> | ||
{{ rawOutputFiles }} | ||
</div> | ||
{% endif %} | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
''' A model skeleton for future models: Calculates the sum of two integers. ''' | ||
|
||
import warnings | ||
# warnings.filterwarnings("ignore") | ||
|
||
import shutil, datetime | ||
from os.path import join as pJoin | ||
|
||
# OMF imports | ||
from omf import feeder | ||
from omf.models.voltageDrop import drawPlot | ||
from omf.models import __neoMetaModel__ | ||
from omf.models.__neoMetaModel__ import * | ||
|
||
# Model metadata: | ||
modelName, template = __neoMetaModel__.metadata(__file__) | ||
hidden = True | ||
|
||
def castAddInputs(val1,val2): | ||
''' Casts string inputs to appropriate type and returns their sum. | ||
If inputs are cast to floats, rounds their sum to avoid float subtraction errors.''' | ||
try: | ||
cast1 = int(val1) | ||
cast2 = int(val2) | ||
return cast1+cast2 | ||
except ValueError: | ||
try: | ||
cast1 = float(val1) | ||
cast2 = float(val2) | ||
#Find longest decimal place of the numbers and round their sum to that place to avoid float arithmetic errors | ||
decPl1 = val1.strip()[::-1].find('.') | ||
decPl2 = val2.strip()[::-1].find('.') | ||
#valX.strip() used instead of str(castX) because str(castX) may return scientific notation | ||
roundedSum = round(cast1+cast2,max(decPl1,decPl2,1)) | ||
return roundedSum | ||
except ValueError: | ||
return val1+val2 | ||
|
||
def work(modelDir, inputDict): | ||
''' Run the model in its directory. ''' | ||
# Delete output file every run if it exists | ||
outData = {} | ||
# Model operations goes here. | ||
inputOne = inputDict.get("input1", 123) | ||
inputTwo = inputDict.get("input2", 867) | ||
output = str(castAddInputs(inputOne,inputTwo)) | ||
outData["output"] = output | ||
# Model operations typically ends here. | ||
# Stdout/stderr. | ||
outData["stdout"] = "Success" | ||
outData["stderr"] = "" | ||
return outData | ||
|
||
def new(modelDir): | ||
''' Create a new instance of this model. Returns true on success, false on failure. ''' | ||
defaultInputs = { | ||
"user" : "admin", | ||
"modelType": modelName, | ||
"input1": "abc1 Easy as...", | ||
"input2": "123 Or Simple as...", | ||
"created":str(datetime.datetime.now()) | ||
} | ||
return __neoMetaModel__.new(modelDir, defaultInputs) | ||
|
||
@neoMetaModel_test_setup | ||
def _tests(): | ||
# Location | ||
modelLoc = pJoin(__neoMetaModel__._omfDir,"data","Model","admin","Automated Testing of " + modelName) | ||
# Blow away old test results if necessary. | ||
try: | ||
shutil.rmtree(modelLoc) | ||
except: | ||
# No previous test results. | ||
pass | ||
# Create New. | ||
new(modelLoc) | ||
# Pre-run. | ||
__neoMetaModel__.renderAndShow(modelLoc) | ||
# Run the model. | ||
__neoMetaModel__.runForeground(modelLoc) | ||
# Show the output. | ||
__neoMetaModel__.renderAndShow(modelLoc) | ||
|
||
if __name__ == '__main__': | ||
#_tests() | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.