Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dpinney/omf
Browse files Browse the repository at this point in the history
  • Loading branch information
jenny-nyx committed Nov 15, 2023
2 parents a5b3272 + 6f907f0 commit fa4f2f0
Show file tree
Hide file tree
Showing 12 changed files with 656 additions and 199 deletions.
2 changes: 2 additions & 0 deletions omf/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@
from omf.models import resilientCommunity
from omf.models import microgridDesign2
from omf.models import transformerPairing
from omf.models import derConsumer
from omf.models import derUtilityCost
70 changes: 70 additions & 0 deletions omf/models/derConsumer.html
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>
86 changes: 86 additions & 0 deletions omf/models/derConsumer.py
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
70 changes: 70 additions & 0 deletions omf/models/derUtilityCost.html
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>
86 changes: 86 additions & 0 deletions omf/models/derUtilityCost.py
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
16 changes: 6 additions & 10 deletions omf/models/microgridDesign2.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
int_data = parseFloat(data); //parseInt(data);
if (!isNaN(int_data)) {
list[i].innerHTML = int_data.toLocaleString();
//added % if value is a percentage (also added 'Fraction' to applicable variable names => maybe change back)
if (id.includes("Fraction")) {
list[i].innerHTML += "%";
}
} else {
list[i].innerHTML = data;
}
Expand Down Expand Up @@ -200,7 +196,7 @@
'</tr>'+
'<tr>'+
'<th>IRR, %</th>'+
'<td id="irrFraction' + indexString + '"></td>'+
'<td id="irr' + indexString + '"></td>'+
'</tr>'+
'<tr>'+
'<th>Simple Payback Period, years</th>'+
Expand Down Expand Up @@ -301,12 +297,12 @@
//skipping CHP, steam turbine
'<tr>'+
'<th>Total optimal electricity produced (kWh/year)</th>'+
'<td id="totalEnergyProduced' + indexString + '"></td>'+
'<td id="totalElectricityProduced' + indexString + '"></td>'+
'</tr>'+
//skipping boiler, CHP, steam turbine
'<tr>'+
'<th>Percent electricity from on-site renewable resources</th>'+
'<td id="yearOnePercentRenewableFraction' + indexString + '"></td>'+
'<td id="yearOnePercentRenewable' + indexString + '"></td>'+
'</tr>'+
'<tr>'+
'<th>Percent reduction in annual electricity bill</th>'+
Expand Down Expand Up @@ -424,16 +420,16 @@
'</tr>'+
'<tr>'+
'<th>Nominal O&M cost escalation rate (%/year)</th>'+
'<td id="omCostEscalatorFraction' + indexString + '"></td>'+
'<td id="omCostEscalator' + indexString + '"></td>'+
'</tr>'+
'<tr>'+
'<th>Nominal electric utility cost escalation rate (%/year)</th>'+
'<td id="elecCostEscalatorFraction' + indexString + '"></td>'+
'<td id="elecCostEscalator' + indexString + '"></td>'+
'</tr>'+
//skipping boiler & CHP
'<tr>'+
'<th>Nominal discount rate (%/year)</th>'+
'<td id="discountRateFraction' + indexString + '"></td>'+
'<td id="discountRate' + indexString + '"></td>'+
'</tr>'+
'</table>'+
'</div>'+
Expand Down
Loading

0 comments on commit fa4f2f0

Please sign in to comment.