Skip to content

Commit

Permalink
Modifications to web.py and omf.js to support new file input system
Browse files Browse the repository at this point in the history
  • Loading branch information
jenny-nyx committed Feb 15, 2024
1 parent 3d73869 commit 6e8202a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
47 changes: 18 additions & 29 deletions omf/models/transformerPairing.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,19 @@
<script src="{{pathPrefix}}/static/highcharts4.src.js"></script>
<script src="https://cdn.plot.ly/plotly-1.50.1.min.js"></script>

<style>
#customerLatLong { display: none; }
</style>
<!--
file_upload('voltageDataFile', 'userInputVoltage', 'voltageDataFileName')
input for the actual file
the name of the file the user is using/inputting in
allInputDataDict[voltageDataFileName] = .csv name
<script>
function toggleFileInput() {
var algorithm = document.getElementById("algorithm").value;

if (algorithm === "customerLatLong") {
document.getElementById("customerLatLong").style.display = "block";
document.getElementById("reactivePower").style.display = "none";
}
else if (algorithm === "reactivePower") {
document.getElementById("reactivePower").style.display = "block";
document.getElementById("customerLatLong").style.display = "none";
}
}
</script>

{% macro file_upload(fileInputID, displayNameID) -%}
<input type="file" id="{{fileInputID}}" name="{{fileInputID}}" accept=".csv" class="fileButton" onchange="updateFileNameDisplay('{{fileInputID}}', '{{displayNameID}}')" style="display:none"><br>
<label for="{{fileInputID}}" class="fileButton">Choose File</label>
<input id="{{displayNameID}}" name="{{displayNameID}}" value="{{ allInputDataDict[displayNameID] }}" readonly class="uploadFileName">
{%- endmacro %}
-->
{% macro file_upload(fileInputID, displayNameID, fileNameID) -%}
<input type="file" id="{{fileInputID}}" name="{{ allInputDataDict[fileNameID] }}" accept=".csv" class="fileButton" onchange="updateFileNameDisplay('{{fileInputID}}', '{{displayNameID}}', '{{fileNameID}}')" style="display:none"><br>
<label for="{{fileInputID}}" class="fileButton">Choose File</label>
<input id="{{displayNameID}}" name="{{displayNameID}}" value="{{ allInputDataDict[fileNameID] }}" readonly class="uploadFileName">
<input id="{{fileNameID}}" name= {{fileNameID}} type="hidden" value="{{ allInputDataDict[fileNameID] }}">
{% endmacro %}

</style>
</head>
Expand Down Expand Up @@ -62,32 +51,32 @@
<br>
<div class="shortInput">
<label class="tooltip">Voltage AMI - Data Input File <span class="classic">File type: .csv</span></label>
<div>{{ file_upload('voltageDataFile','voltageDataFileName') }}</div>
<div>{{ file_upload('voltageDataFile', 'userInputVoltage', 'voltageDataFileName' )}}</div>
</div>
<div class="shortInput">
<label class="tooltip">Real Power - AMI Data Input File <span class="classic">File type: .csv</span></label>
<div>{{ file_upload('realPowerDataFile','realPowerDataFileName') }}</div>
<div>{{ file_upload('realPowerDataFile', 'userInputReal', 'realPowerDataFileName') }}</div>
</div>
<div class="shortInput">
<label class="tooltip">Customer ID Data - AMI Data Input File <span class="classic">File type: .csv</span></label>
<div>{{ file_upload('customerIDDataFile','customerIDDataFileName') }}</div>
<div>{{ file_upload('customerIDDataFile', 'userInputCustID', 'customerIDDataFileName') }}</div>
</div>
<br>
<div class="shortInput">
<label class="tooltip">Choose Algorithm: Customer Distance Based or Reactive Power Based</label>
<select id="algorithm" name="algorithm" value="{{allInputDataDict.algorithm}}" required onchange="toggleFileInput()">
<select id="algorithm" name="algorithm" value="{{allInputDataDict.algorithm}}" required>
<option value="reactivePower" {% if allInputDataDict.algorithm == 'reactivePower' %}selected{% endif %}>Reactive Power</option>
<option value="customerLatLong" {% if allInputDataDict.algorithm == 'customerLatLong' %}selected{% endif %}>Customer LatLong</option>
</select>
</div>
<br>
<div class="shortInput" id="customerLatLong">
<label class="tooltip">Customer Latitude & Longitutde - AMI Data Input File <span class="classic">File type: .csv</span></label>
<div>{{ file_upload('customerLatLongDataFile','customerLatLongDataFileName') }}</div>
<div>{{ file_upload('customerLatLongDataFile', 'userInputCustLatLong', 'customerLatLongDataFileName') }}</div>
</div>
<div class="shortInput" id="reactivePower">
<label class="tooltip">Reactive Power - AMI Data Input File <span class="classic">File type: .csv</span></label>
<div>{{ file_upload('reactivePowerDataFile','reactivePowerDataFileName') }}</div>
<div>{{ file_upload('reactivePowerDataFile', 'userInputReactive', 'reactivePowerDataFileName') }}</div>
</div>
<hr>
{{ omfModelButtons }}
Expand Down
6 changes: 3 additions & 3 deletions omf/static/omf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ function post_to_url(path, params, method) {
form.submit()
}

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

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

Expand Down
6 changes: 3 additions & 3 deletions omf/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,11 @@ def runModel():
# File upload handling
# print('FILES?', len(request.files), request.files)
if len( request.files ) > 0:
for file_name, file in request.files.items():
for file_field, file in request.files.items():
if file.filename != '':
file.save(os.path.join(modelDir, file.filename))
file.save(os.path.join(modelDir, file_field))
else:
print( "File not found: ", file.filename)
print( "File not found: ", file_field, "file info: ", file)
# Get existing model viewers and add them to pData if they exist, then write pData to update allInputData.json
filepath = os.path.join(modelDir, "allInputData.json")
with locked_open(filepath, 'r+') as f:
Expand Down

0 comments on commit 6e8202a

Please sign in to comment.