Unverified Commit 44c339db authored by Julien Veyssier's avatar Julien Veyssier
Browse files

add 2 generic communication modules to set/add value to any attribute for HRU/REACH


Signed-off-by: default avatarJulien Veyssier <eneiluj@posteo.net>
No related merge requests found
Showing with 214 additions and 1 deletion
+214 -1
...@@ -609,12 +609,14 @@ public class CouplingCommunication extends JAMSComponent { ...@@ -609,12 +609,14 @@ public class CouplingCommunication extends JAMSComponent {
if ("i".equals(key)) { if ("i".equals(key)) {
mi = jsonPayload.getInt("value"); mi = jsonPayload.getInt("value");
} }
// we accept any key (a specific module OR CouplingHruVariableChanger will handle it)
else if ("aspersion".equals(key) || else if ("aspersion".equals(key) ||
"drip".equals(key) || "drip".equals(key) ||
"surface".equals(key) || "surface".equals(key) ||
"infiltration".equals(key) || "infiltration".equals(key) ||
"reachin".equals(key) || "reachin".equals(key) ||
"reachout".equals(key) "reachout".equals(key) ||
true
) { ) {
JSONObject values = (JSONObject)jsonPayload.get("value"); JSONObject values = (JSONObject)jsonPayload.get("value");
setTableValues(key, values); setTableValues(key, values);
......
/*
* IrrigationApplication.java
* Created on 13.08.2015, 17:42:55
*
* This file is part of JAMS
* Copyright (C) FSU Jena
*
* JAMS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* JAMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JAMS. If not, see <http://www.gnu.org/licenses/>.
*
*/
package cowattools;
import jams.data.*;
import jams.model.*;
//import cowattools.CouplingCommunication;
/**
*
* @author Sven Kralisch <sven.kralisch at uni-jena.de>
*/
@JAMSComponentDescription(
title = "CouplingHruVariableChanger",
author = "Julien Veyssier",
description = "Change a variable value for current HRU according to external coupling orders",
date = "2020-05-13",
version = "0.1"
)
@VersionComments(entries = {
@VersionComments.Entry(version = "0.1", comment = "Initial version")
})
public class CouplingHruVariableChanger extends JAMSComponent {
/*
* Component attributes
*/
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READ,
description = "HRUs list"
)
public Attribute.EntityCollection hrus;
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READ,
description = "Module name. This is the name you need to use when using j2kSet communication command"
)
public Attribute.String moduleName;
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READWRITE,
description = "HRU attribute you want to change"
)
public Attribute.Double attribute;
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READ,
description = "Do you want to set (0) or add (1) something to the attribute?"
)
public Attribute.Long setOrAdd;
/*
* Component run stages
*/
@Override
public void run() {
// get current HRU ID
if (hrus == null) {
System.out.println("HRUSSSS is null");
return;
}
Attribute.Entity hru = hrus.getCurrent();
Double hruId = hru.getDouble("ID");
String sHruId = String.valueOf(hruId.intValue());
// ask communication module what's the value
String strModuleName = moduleName.getValue();
//String strAttributeName = attribute.getId();
Long setOrAddValue = setOrAdd.getValue();
double extValue = CouplingCommunication.getTableValue(strModuleName, String.valueOf(sHruId));
if (setOrAddValue == 0) {
//hru.setDouble(strAttributeName, extValue);
attribute.setValue(extValue);
System.out.println("["+strModuleName+"] [HRU "+sHruId+"] set attribute = "+extValue);
} else {
if (extValue > 0.0) {
Double attributeCurrentValue = attribute.getValue();
attribute.setValue(attributeCurrentValue + extValue);
System.out.println("["+strModuleName+"] [HRU "+sHruId+"] add "+extValue+" to attribute");
}
}
}
}
/*
* IrrigationApplication.java
* Created on 13.08.2015, 17:42:55
*
* This file is part of JAMS
* Copyright (C) FSU Jena
*
* JAMS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* JAMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JAMS. If not, see <http://www.gnu.org/licenses/>.
*
*/
package cowattools;
import jams.data.*;
import jams.model.*;
//import cowattools.CouplingCommunication;
/**
*
* @author Sven Kralisch <sven.kralisch at uni-jena.de>
*/
@JAMSComponentDescription(
title = "CouplingReachVariableChanger",
author = "Julien Veyssier",
description = "Change a variable value for current Reach according to external coupling orders",
date = "2020-05-13",
version = "0.1"
)
@VersionComments(entries = {
@VersionComments.Entry(version = "0.1", comment = "Initial version")
})
public class CouplingReachVariableChanger extends JAMSComponent {
/*
* Component attributes
*/
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READ,
description = "The reach collection"
)
public Attribute.EntityCollection reachs;
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READ,
description = "Module name. This is the name you need to use when using j2kSet communication command"
)
public Attribute.String moduleName;
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READWRITE,
description = "Reach attribute you want to change"
)
public Attribute.Double attribute;
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READ,
description = "Do you want to set (0) or add (1) something to the attribute?"
)
public Attribute.Long setOrAdd;
/*
* Component run stages
*/
@Override
public void run() {
// get reach ID
Attribute.Entity reach = reachs.getCurrent();
Double reachId = reach.getDouble("ID");
int iReachId = reachId.intValue();
String sReachId = String.valueOf(iReachId);
// ask communication module what's the value
String strModuleName = moduleName.getValue();
//String strAttributeName = attributeName.getValue();
Long setOrAddValue = setOrAdd.getValue();
double extValue = CouplingCommunication.getTableValue(strModuleName, String.valueOf(sReachId));
if (setOrAddValue == 0) {
attribute.setValue(extValue);
System.out.println("["+strModuleName+"] [REACH "+sReachId+"] set attribute = "+extValue);
} else {
if (extValue > 0.0) {
Double attributeCurrentValue = attribute.getValue();
attribute.setValue(attributeCurrentValue + extValue);
System.out.println("["+strModuleName+"] [REACH "+sReachId+"] add "+extValue+" to attribute");
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment