Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engage96 conversionplus #237

Open
wants to merge 12 commits into
base: calliope-c7
Choose a base branch
from
4 changes: 2 additions & 2 deletions calliope_app/api/fixtures/admin_parameter.json
Original file line number Diff line number Diff line change
Expand Up @@ -3425,7 +3425,7 @@
"is_essential": "True",
"is_carrier": "True",
"choices": "[]",
"tags": "[\"carrier\", \"essential\", \"carrier_in\", \"required_carrier\", \"units_in\"]",
"tags": "[\"carrier\", \"essential\", \"carrier_in\", \"required_carrier\", \"units_in\", \"carrier_multiselect\"]",
"index": "[]",
"dim": "[]"
},
Expand All @@ -3451,7 +3451,7 @@
"is_essential": "True",
"is_carrier": "True",
"choices": "[]",
"tags": "[\"carrier\", \"essential\", \"carrier_out\", \"required_carrier\", \"units_out\"]",
"tags": "[\"carrier\", \"essential\", \"carrier_out\", \"required_carrier\", \"units_out\", \"carrier_multiselect\"]",
"index": "[]",
"dim": "[]"
},
Expand Down
6 changes: 4 additions & 2 deletions calliope_app/api/models/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ def get_tech_params_dict(level, id, excl_ids=None, systemwide=True):
"parameter__name", parameter__pretty_name,
parameter__description, "parameter__is_essential",
"parameter__is_carrier", "parameter__units", "parameter__choices",
"parameter__timeseries_enabled"]
"parameter__timeseries_enabled", "parameter__tags"]

# Get Params based on Level
if level == '0_abstract':
Expand Down Expand Up @@ -1482,7 +1482,9 @@ def get_tech_params_dict(level, id, excl_ids=None, systemwide=True):
'timeseries_enabled': param["parameter__timeseries_enabled"],
'timeseries': param["timeseries"] if 'timeseries' in param.keys() else False,
'timeseries_meta_id': param["timeseries_meta_id"] if 'timeseries_meta_id' in param.keys() else 0,
'value': param["value"] if "value" in param.keys() else param["default_value"]}
'value': param["value"] if "value" in param.keys() else param["default_value"],
'tags': param["parameter__tags"]
}
data.append(param_dict)

return data, list(set(new_excl_ids))
Expand Down
14 changes: 8 additions & 6 deletions calliope_app/client/component_views/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,14 @@ def all_tech_params(request):
for carrier in model.carriers_old:
if carrier not in carriers.keys():
carriers[carrier] = {'rate':'kW','quantity':'kWh'}

carriers = [{'name':c,'rate':v['rate'],'quantity':v['quantity']} for c,v in carriers.items()]

for param in parameters:
param['raw_units'] = param['units']

timeseries = Timeseries_Meta.objects.filter(model=model, failure=False,
is_uploading=False)

carrier_multiselect = ParamsManager.get_tagged_params('carrier_multiselect')
print(carrier_multiselect, carriers)
# Technology Definition
context = {"technology": technology,
"essentials": essentials,
Expand All @@ -170,13 +169,14 @@ def all_tech_params(request):
"cplus_carrier_ids": ParamsManager.get_tagged_params('cplus_carrier'),
"units_in_ids": ParamsManager.get_tagged_params('units_in'),
"units_out_ids": ParamsManager.get_tagged_params('units_out'),
"can_edit": can_edit}
"carrier_multiselect": carrier_multiselect,
"can_edit": can_edit,
}
html_essentials = list(render(request,
'technology_essentials.html',
context))[0]

emissions = ParamsManager.emission_categories()

# Parameters Table
context = {
"technology": technology,
Expand All @@ -186,7 +186,9 @@ def all_tech_params(request):
"level": "1_tech",
"timeseries": timeseries,
"can_edit": can_edit,
"emissions": emissions
"emissions": emissions,
"carrier_multiselect_tuples": carrier_multiselect,

}
html_parameters = list(render(request, 'technology_parameters.html', context))[0]

Expand Down
190 changes: 96 additions & 94 deletions calliope_app/client/static/js/technologies.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,97 @@
$( document ).ready(function() {

initiate_units();

$('#master-new').removeClass('hide');

if ($("#technology option").length == 0) {
$('#tech_essentials').html('<div class="col-12 text-center"><br/><br/><h4>Create a technology by clicking the "+ New" button above!</h4></div>');
} else {
$('#technology').on('change', function() {
get_tech_parameters();
});
get_tech_parameters();
}

// Save modified parameters
$('#master-save').on('click', function() {

if (validate_params()) {

var form_data_1 = $("#form_data_1 :input").serializeJSON();
var form_data_2 = filter_param_inputs($("#form_data_2 :input")).serializeJSON();
var form_data = Object.assign({}, form_data_1, form_data_2);

$.ajax({
url: '/' + LANGUAGE_CODE + '/api/update_tech_params/',
type: 'POST',
data: {
'model_uuid': $('#header').data('model_uuid'),
'technology_id': $("#technology option:selected").data('id'),
'form_data': JSON.stringify(form_data),
'csrfmiddlewaretoken': getCookie('csrftoken'),
},
dataType: 'json',
success: function (data) {
window.onbeforeunload = null;
location.reload();
}
});

};
});

$('#master-new').on('click', function() {
var model_uuid = $('#header').data('model_uuid');
window.location = '/' + model_uuid + '/add_technologies/';
});

$('#master-cancel').on('click', function() {
window.onbeforeunload = null;
var model_uuid = $('#header').data('model_uuid');
window.location = '/' + model_uuid + '/technologies/';
});

$('#master-bulk-up').removeClass('hide');
$('#master-bulk-up').on('click', function(){
var model_uuid = $('#header').data('model_uuid');
//e.stopPropagation();
var uploadForm = document.createElement('form');
uploadForm.id = 'uploadForm';
uploadForm.method='post';
uploadForm.action='/' + LANGUAGE_CODE + '/api/upload_techs/';
uploadForm.enctype = 'multipart/form-data';
var modelInput = document.createElement('input');
modelInput.name = 'model_uuid';
modelInput.value = model_uuid;
uploadForm.appendChild(modelInput);
var csrfInput = document.createElement('input');
csrfInput.name = 'csrfmiddlewaretoken';
csrfInput.value = getCookie('csrftoken');
uploadForm.appendChild(csrfInput);
var fileInput = document.createElement('input');
var submit_outputs= document.createElement('input');
submit_outputs.type = 'submit';
submit_outputs.id = 'submit_outputs';
uploadForm.appendChild(submit_outputs);

fileInput.type = 'file';
fileInput.name = 'myfile';
fileInput.multiple = false;
fileInput.onchange = function(){

$('#submit_outputs').click();
uploadForm.remove();
};

uploadForm.appendChild(fileInput);
$(document.body.append(uploadForm));
fileInput.click();
});

$('#master-bulk-down').removeClass('hide');
$('#master-bulk-down').attr("href", function() { return $(this).attr("href")+"&file_list=technologies"});

$(document).ready(function () {
initiate_units();

$("#master-new").removeClass("hide");

if ($("#technology option").length == 0) {
$("#tech_essentials").html(
'<div class="col-12 text-center"><br/><br/><h4>Create a technology by clicking the "+ New" button above!</h4></div>'
);
} else {
$("#technology").on("change", function () {
get_tech_parameters();
});
get_tech_parameters();
}

// Save modified parameters
$("#master-save").on("click", function () {
if (validate_params()) {
var form_data_1 = $("#form_data_1 :input").serializeJSON(
(useIntKeysAsArrayIndex = true)
);
var form_data_2 = filter_param_inputs(
$("#form_data_2 :input")
).serializeJSON();
var form_data = Object.assign({}, form_data_1, form_data_2);

$.ajax({
url: "/" + LANGUAGE_CODE + "/api/update_tech_params/",
type: "POST",
data: {
model_uuid: $("#header").data("model_uuid"),
technology_id: $("#technology option:selected").data("id"),
form_data: JSON.stringify(form_data),
csrfmiddlewaretoken: getCookie("csrftoken"),
},
dataType: "json",
success: function (data) {
window.onbeforeunload = null;
location.reload();
},
});
}
});

$("#master-new").on("click", function () {
var model_uuid = $("#header").data("model_uuid");
window.location = "/" + model_uuid + "/add_technologies/";
});

$("#master-cancel").on("click", function () {
window.onbeforeunload = null;
var model_uuid = $("#header").data("model_uuid");
window.location = "/" + model_uuid + "/technologies/";
});

$("#master-bulk-up").removeClass("hide");
$("#master-bulk-up").on("click", function () {
var model_uuid = $("#header").data("model_uuid");
//e.stopPropagation();
var uploadForm = document.createElement("form");
uploadForm.id = "uploadForm";
uploadForm.method = "post";
uploadForm.action = "/" + LANGUAGE_CODE + "/api/upload_techs/";
uploadForm.enctype = "multipart/form-data";
var modelInput = document.createElement("input");
modelInput.name = "model_uuid";
modelInput.value = model_uuid;
uploadForm.appendChild(modelInput);
var csrfInput = document.createElement("input");
csrfInput.name = "csrfmiddlewaretoken";
csrfInput.value = getCookie("csrftoken");
uploadForm.appendChild(csrfInput);
var fileInput = document.createElement("input");
var submit_outputs = document.createElement("input");
submit_outputs.type = "submit";
submit_outputs.id = "submit_outputs";
uploadForm.appendChild(submit_outputs);

fileInput.type = "file";
fileInput.name = "myfile";
fileInput.multiple = false;
fileInput.onchange = function () {
$("#submit_outputs").click();
uploadForm.remove();
};

uploadForm.appendChild(fileInput);
$(document.body.append(uploadForm));
fileInput.click();
});

$("#master-bulk-down").removeClass("hide");
$("#master-bulk-down").attr("href", function () {
return $(this).attr("href") + "&file_list=technologies";
});
});
Loading