Skip to content

Commit

Permalink
Hosting Capacity works w new file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jenny-nyx committed Feb 29, 2024
1 parent 3983cc6 commit b64d3fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
27 changes: 17 additions & 10 deletions omf/models/hostingCapacity.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
<!-- Library Imports -->
<script src="{{pathPrefix}}/static/highcharts4.src.js"></script>
<script src="https://cdn.plot.ly/plotly-1.50.1.min.js"></script>
{% macro insert_file_upload_block(fileName, dataVariableName) -%}
<input id="{{dataVariableName}}Handler" type="file" style="display:none" onchange="handle_files(this.files,'{{dataVariableName}}','{{fileName}}')">
<input id="{{dataVariableName}}" name="{{dataVariableName}}" value="{{allInputDataDict[dataVariableName]}}" type="hidden">
<div>
<label for="{{dataVariableName}}Handler" class="fileButton">Choose File</label>
<input id="{{fileName}}" name="{{fileName}}" value="{{allInputDataDict[fileName]}}" readonly class="uploadFileName">
</div>
{%- endmacro %}

<!--
file_upload('fileInputID', 'userInputVoltage', 'voltageDataFileName')
line 1: input for the actual file. There should be no value in inputDict that matches this one.
line 2: button for file upload, that's it.
line 3: the name of the file the user is using/inputting in. We wanna save this for display. Originally it's set as the default.
line 4: This is hidden. This is the name of the file we want always = .csv name <- default naming convention
-->
{% macro file_upload(fileInputID, userFileDisplayNameID, dataFileNameID) -%}
<input type="file" id="{{fileInputID}}" name="{{ allInputDataDict[dataFileNameID] }}" accept=".csv" class="fileButton" onchange="updateFileNameDisplay('{{fileInputID}}', '{{userFileDisplayNameID}}', '{{dataFileNameID}}')" style="display:none"><br>
<label for="{{fileInputID}}" class="fileButton">Choose File</label>
<input id="{{userFileDisplayNameID}}" name="{{userFileDisplayNameID}}" value="{{ allInputDataDict[userFileDisplayNameID] }}" readonly class="uploadFileName">
<input id="{{dataFileNameID}}" name= {{dataFileNameID}} type="hidden" value="{{ allInputDataDict[dataFileNameID] }}">
{% endmacro %}

</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">
<form name="inputForm" action="/runModel/" onsubmit="event.preventDefault(); return isFormValid();" method="post" enctype="multipart/form-data">
<div class="shortInput">
<label>Model Type <a href="https://github.com/dpinney/omf/wiki/Models-~-hostingCapacity" target="blank">Help?</a></label>
<input type="text" id="modelType" name="modelType" value="{{modelName}}" readonly/>
Expand Down Expand Up @@ -52,7 +59,7 @@
</div>
<div class="shortInput">
<label class="tooltip">Meter Data Input File <span class="classic">Import a .csv file that includes the meter data. Format for input columns: busname, datetime, v_reading, kw_reading, kvar_reading. Optional input columns: latitude, longitude, service_tx_name, phase_count (1, 3)</span></label>
<div>{{ insert_file_upload_block('inputDataFileName','inputDataFileContent') }}</div>
<div>{{ file_upload('AMIDataFile', 'userAMIDisplayFileName', 'AMIDataFileName') }}</div>
</div>
<div class="shortInput">
<label>Algorithm</label>
Expand Down
14 changes: 7 additions & 7 deletions omf/models/hostingCapacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ def work(modelDir, inputDict):

def run_ami_algorithm(modelDir, inputDict, outData):
# mohca data-driven hosting capacity
with open(Path(modelDir,inputDict['inputDataFileName']),'w', newline='') as pv_stream:
pv_stream.write(inputDict['inputDataFileContent'])
inputPath = Path(modelDir, inputDict['inputDataFileName'])
inputPath = Path(modelDir, inputDict['AMIDataFileName'])
inputAsString = inputPath.read_text()
try:
csvValidateAndLoad(inputDict['inputDataFileContent'], modelDir=modelDir, header=0, nrows=None, ncols=5, dtypes=[str, pd.to_datetime, float, float, float], return_type='df', ignore_nans=False, save_file=None, ignore_errors=False )
csvValidateAndLoad(inputAsString, modelDir=modelDir, header=0, nrows=None, ncols=5, dtypes=[str, pd.to_datetime, float, float, float], return_type='df', ignore_nans=False, save_file=None, ignore_errors=False )
except:
errorMessage = "AMI-Data CSV file is incorrect format. Please see valid format definition at <a target='_blank' href='https://github.com/dpinney/omf/wiki/Models-~-hostingCapacity#meter-data-input-csv-file-format'>OMF Wiki hostingCapacity</a>"
raise Exception(errorMessage)
Expand Down Expand Up @@ -148,12 +147,12 @@ def new(modelDir):
''' Create a new instance of this model. Returns true on success, false on failure. '''
meter_file_name = 'mohcaInputCustom.csv'
meter_file_path = Path(omf.omfDir,'static','testFiles', 'hostingCapacity', meter_file_name)
meter_file_contents = open(meter_file_path).read()
# meter_file_contents = open(meter_file_path).read()
defaultInputs = {
"modelType": modelName,
"algorithm": 'sandia1',
"inputDataFileName": meter_file_name,
"inputDataFileContent": meter_file_contents,
"AMIDataFileName": meter_file_name,
"userAMIDisplayFileName": meter_file_name,
"feederName1": 'iowa240.clean.dss',
"optionalCircuitFile": 'on',
"traditionalHCMaxTestkw": 50000,
Expand All @@ -164,6 +163,7 @@ def new(modelDir):
shutil.copyfile(
Path(__neoMetaModel__._omfDir, "static", "publicFeeders", defaultInputs["feederName1"]+'.omd'),
Path(modelDir, defaultInputs["feederName1"]+'.omd'))
shutil.copyfile( meter_file_path, Path(modelDir, meter_file_name) )
except:
return False
return creationCode
Expand Down
8 changes: 2 additions & 6 deletions omf/static/omf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ function post_to_url(path, params, method) {
form.submit()
}

function updateFileNameDisplay(fileInputID, displayID, fileNameID) {
// the fileNameID has to be = the allInputDataDict value
function updateFileNameDisplay(fileInputID, userFileDisplayNameID, dataFileNameID) {
var fileInput = document.getElementById(fileInputID);
var displayInput = document.getElementById(displayID);
var displayInput = document.getElementById(userFileDisplayNameID);

if ( fileInput.files.length > 0 ) {
displayInput.value = fileInput.files[0].name;
}
else {
displayInput.value = "{{ allInputDataDict[fileNameID] }}";
}
}

function handle_files(files, contentsId, nameId) {
Expand Down

0 comments on commit b64d3fd

Please sign in to comment.