@@ -5,7 +5,7 @@ |
* @author RUMPAL SIDHU |
*/ |
import csip.ModelDataService; |
-import static csip.ModelDataService.EXEC_OK; |
+import csip.annotations.Polling; |
import csip.utils.JSONUtils; |
import java.util.ArrayList; |
import java.util.Map; |
@@ -18,18 +18,20 @@ |
@Name("WQM-20") |
@Description("Threshold and Mitigation Scores for WQM Scorebar") |
@Path("m/wqmscorebar/1.0") |
+@Polling(first = 10000, next = 2000) |
|
public class V1_0 extends ModelDataService { |
|
- ArrayList<m.wqm.scorebar.Input> components = new ArrayList<>(); // store the set of all input soilcomponents as objects |
- ArrayList<m.wqm.scorebar.Result> result = new ArrayList<>(); // store the result as objects |
+ //Request |
+ private ArrayList<Input> components; |
+ //Response |
+ private ArrayList<Result> result; |
|
@Override |
// reading the inputs from the json file into input object and placing it in the arraylist |
protected void preProcess() throws Exception { |
- |
+ components = new ArrayList<>(); |
JSONArray groups = getJSONArrayParam("components"); |
- |
for (int i = 0; i < groups.length(); i++) { |
Map<String, JSONObject> group = JSONUtils.preprocess(groups.getJSONArray(i)); |
int AoAId = JSONUtils.getIntParam(group, "AoAId", 0); |
@@ -68,67 +70,57 @@ |
int aoa_pdrift_human_threshold = JSONUtils.getIntParam(group, "aoa_pdrift_human_threshold", 0); |
int aoa_pdrift_fish_threshold = JSONUtils.getIntParam(group, "aoa_pdrift_fish_threshold", 0); |
|
- m.wqm.scorebar.Input input = new m.wqm.scorebar.Input(AoAId, nleach_techn_score, nsurf_techn_score, psurf_techn_score, nleach_pract_score, ssurf_pract_score, nsurf_pract_score, psurf_pract_score, nleach_app_mgt_score, nsurf_app_mgt_score, psurf_app_mgt_score, pleach_ipm_score, psolsurf_ipm_score, padsurf_ipm_score, pdrift_ipm_score, pleach_technique_score, psolsurf_technique_score, padsurf_technique_score, pdrift_technique_score, pleach_practice_score, psolsurf_practice_score, padsurf_practice_score, pdrift_practice_score, aoa_nleach_threshold, aoa_nrun_threshold, aoa_sedrun_threshold, aoa_prun_threshold, aoa_pleach_human_threshold, aoa_pleach_matcfish_threshold, aoa_psorun_human_threshold, aoa_psorun_matcfish_threshold, aoa_padrun_human_threshold, aoa_padrun_stvfish_threshold, aoa_pdrift_human_threshold, aoa_pdrift_fish_threshold); |
+ Input input = new Input(AoAId, nleach_techn_score, nsurf_techn_score, psurf_techn_score, nleach_pract_score, ssurf_pract_score, nsurf_pract_score, psurf_pract_score, nleach_app_mgt_score, nsurf_app_mgt_score, psurf_app_mgt_score, pleach_ipm_score, psolsurf_ipm_score, padsurf_ipm_score, pdrift_ipm_score, pleach_technique_score, psolsurf_technique_score, padsurf_technique_score, pdrift_technique_score, pleach_practice_score, psolsurf_practice_score, padsurf_practice_score, pdrift_practice_score, aoa_nleach_threshold, aoa_nrun_threshold, aoa_sedrun_threshold, aoa_prun_threshold, aoa_pleach_human_threshold, aoa_pleach_matcfish_threshold, aoa_psorun_human_threshold, aoa_psorun_matcfish_threshold, aoa_padrun_human_threshold, aoa_padrun_stvfish_threshold, aoa_pdrift_human_threshold, aoa_pdrift_fish_threshold); |
components.add(input); |
} |
} |
|
@Override |
protected String process() throws Exception { |
+ result = new ArrayList<>(); |
|
- for (m.wqm.scorebar.Input ip : components) { |
- |
+ components.stream().map((ip) -> { |
//Nitrogen in Ground Water mitigation and threshold scores |
int bar_nleach_mit_score = ip.nleach_techn_score + ip.nleach_pract_score + ip.nleach_app_mgt_score; |
int bar_nleach_threshold = ip.aoa_nleach_threshold; |
- |
//Nitrogen in Surface Water mitigation and threshold scores |
int bar_nsurf_mit_score = ip.nsurf_techn_score + ip.nsurf_pract_score + ip.nsurf_app_mgt_score; |
int bar_nsurf_threshold = ip.aoa_nrun_threshold; |
- |
//Phosphorus in Surface Water mitigation and threshold scores |
int bar_psurf_mit_score = ip.psurf_techn_score + ip.psurf_pract_score + ip.psurf_app_mgt_score; |
int bar_psurf_threshold = ip.aoa_nrun_threshold; |
- |
//Sediment in Surface Water mitigation and threshold scores |
int bar_ssurf_mit_score = ip.ssurf_pract_score; |
int bar_ssurf_threshold = ip.aoa_nrun_threshold; |
- |
//Pesticide in Ground Water - Human mitigation and threshold scores |
int bar_pleach_human_mit_score = ip.pleach_ipm_score + ip.pleach_technique_score + ip.pleach_practice_score; |
int bar_pleach_human_threshold = ip.aoa_pleach_human_threshold; |
- |
//Pesticide in Ground Water - Fish mitigation and threshold scores |
int bar_pleach_fish_mit_score = ip.pleach_ipm_score + ip.pleach_technique_score + ip.pleach_practice_score; |
int bar_pleach_fish_threshold = ip.aoa_pleach_matcfish_threshold; |
- |
//Pesticide in Solution Runoff - Human mitigation and threshold scores |
int bar_psorun_human_mit_score = ip.psolsurf_ipm_score + ip.psolsurf_technique_score + ip.psolsurf_practice_score; |
int bar_psorun_human_threshold = ip.aoa_psorun_human_threshold; |
- |
//Pesticide in Solution Runoff - Fish mitigation and threshold scores |
int bar_psorun_fish_mit_score = ip.psolsurf_ipm_score + ip.psolsurf_technique_score + ip.psolsurf_practice_score; |
int bar_psorun_fish_threshold = ip.aoa_psorun_matcfish_threshold; |
- |
//Pesticide in Adsorbed Runoff - Human mitigation and threshold scores |
int bar_padrun_human_mit_score = ip.padsurf_ipm_score + ip.padsurf_technique_score + ip.padsurf_practice_score; |
int bar_padrun_human_threshold = ip.aoa_padrun_human_threshold; |
- |
//Pesticide in Adsorbed Runoff - Fish mitigation and threshold scores |
int bar_padrun_fish_mit_score = ip.padsurf_ipm_score + ip.padsurf_technique_score + ip.padsurf_practice_score; |
int bar_padrun_fish_threshold = ip.aoa_padrun_stvfish_threshold; |
- |
//Pesticide Drift - Human mitigation and threshold scores |
int bar_pdrift_human_mit_score = ip.pdrift_ipm_score + ip.pdrift_technique_score + ip.pdrift_practice_score; |
int bar_pdrift_human_threshold = ip.aoa_psorun_human_threshold; |
- |
//Pesticide Drift - Fish mitigation and threshold scores |
int bar_pdrift_fish_mit_score = ip.pdrift_ipm_score + ip.pdrift_technique_score + ip.pdrift_practice_score; |
int bar_pdrift_fish_threshold = ip.aoa_psorun_matcfish_threshold; |
- |
- m.wqm.scorebar.Result result1 = new m.wqm.scorebar.Result(ip.AoAId, bar_nleach_mit_score, bar_nleach_threshold, bar_nsurf_mit_score, bar_nsurf_threshold, bar_psurf_mit_score, bar_psurf_threshold, bar_ssurf_mit_score, bar_ssurf_threshold, bar_pleach_human_mit_score, bar_pleach_human_threshold, bar_pleach_fish_mit_score, bar_pleach_fish_threshold, bar_psorun_human_mit_score, bar_psorun_human_threshold, bar_psorun_fish_mit_score, bar_psorun_fish_threshold, bar_padrun_human_mit_score, bar_padrun_human_threshold, bar_padrun_fish_mit_score, bar_padrun_fish_threshold, bar_pdrift_human_mit_score, bar_pdrift_human_threshold, bar_pdrift_fish_mit_score, bar_pdrift_fish_threshold); |
+ Result result1 = new Result(ip.AoAId, bar_nleach_mit_score, bar_nleach_threshold, bar_nsurf_mit_score, bar_nsurf_threshold, bar_psurf_mit_score, bar_psurf_threshold, bar_ssurf_mit_score, bar_ssurf_threshold, bar_pleach_human_mit_score, bar_pleach_human_threshold, bar_pleach_fish_mit_score, bar_pleach_fish_threshold, bar_psorun_human_mit_score, bar_psorun_human_threshold, bar_psorun_fish_mit_score, bar_psorun_fish_threshold, bar_padrun_human_mit_score, bar_padrun_human_threshold, bar_padrun_fish_mit_score, bar_padrun_fish_threshold, bar_pdrift_human_mit_score, bar_pdrift_human_threshold, bar_pdrift_fish_mit_score, bar_pdrift_fish_threshold); |
+ return result1; |
+ }).forEach((result1) -> { |
result.add(result1); |
- } |
+ }); |
return EXEC_OK; |
} |
|
@@ -136,7 +128,7 @@ |
//writing the results back to JSON |
protected void postProcess() throws Exception { |
JSONArray resultArr = new JSONArray(); |
- for (m.wqm.scorebar.Result rs1 : result) { |
+ for (Result rs1 : result) { |
JSONArray tmpArr = new JSONArray(); |
tmpArr.put(JSONUtils.dataDesc("AoAId", rs1.AoAId, "Area of Analysis Identifier")); |
tmpArr.put(JSONUtils.dataDesc("bar_nleach_mit_score", rs1.bar_nleach_mit_score, "Mitigation Score for Nitrogen In Ground Water")); |