V1_0.java [src/java/m/wqm/wqm20_scorebar] Revision:   Date:
package m.wqm.wqm20_scorebar;

import csip.ModelDataService;
import csip.api.server.ServiceException;
import csip.annotations.Polling;
import javax.ws.rs.Path;
import csip.annotations.Description;
import csip.annotations.Name;
import org.codehaus.jettison.json.JSONException;

/**
 * WQM-20: Threshold and Mitigation Scores for WQM Scorebar
 *
 * @author RUMPAL SIDHU
 * @version 1.0
 */
@Name("WQM-20: Threshold and Mitigation Scores for WQM Scorebar (WQMScorebar)")
@Description("This service computes and compiles mitigation and threshold scores "
        + "for each WQM sediment, nutrient, and pesticide-related resource concern: "
        + "nitrogen leaching, nitrogen runoff, phosphorus runoff, sediment runoff, "
        + "pesticide leaching (human), pesticide leaching (fish), pesticide solution "
        + "runoff (human), pesticide solution runoff (fish), "
        + "pesticide adsorbed runoff (human), pesticide adsorbed runoff (fish), "
        + "pesticide drift (human), and pesticide drift (fish).")
@Path("m/wqmscorebar/1.0")
@Polling(first = 10000, next = 2000)

public class V1_0 extends ModelDataService {

    private Input aoa;

    @Override
    protected void doProcess() throws ServiceException, JSONException {
        int id = parameter().getInt("AoAId", 0);
        int nleachTS = parameter().getInt("nleach_techn_score", 0);
        int nsurfTS = parameter().getInt("nsurf_techn_score", 0);
        int psurfTS = parameter().getInt("psurf_techn_score", 0);
        int nleachPS = parameter().getInt("nleach_pract_score", 0);
        int ssurfPS = parameter().getInt("ssurf_pract_score", 0);
        int nsurfPS = parameter().getInt("nsurf_pract_score", 0);
        int psurfPS = parameter().getInt("psurf_pract_score", 0);
        int nleachAppMgtScore = parameter().getInt("nleach_app_mgt_score", 0);
        int nsurfAppMgtScore = parameter().getInt("nsurf_app_mgt_score", 0);
        int psurfAppMgtScore = parameter().getInt("psurf_app_mgt_score", 0);
        int pleachIpmScore = parameter().getInt("pleach_ipm_score", 0);
        int psolsurfIpmScore = parameter().getInt("psolsurf_ipm_score", 0);
        int padsurfIpmScore = parameter().getInt("padsurf_ipm_score", 0);
        int pdriftIpmScore = parameter().getInt("pdrift_ipm_score", 0);
        int pleachTS = parameter().getInt("pleach_technique_score", 0);
        int psolsurfTS = parameter().getInt("psolsurf_technique_score", 0);
        int padsurfTS = parameter().getInt("padsurf_technique_score", 0);
        int pdriftTS = parameter().getInt("pdrift_technique_score", 0);
        int pleachPS = parameter().getInt("pleach_practice_score", 0);
        int psolsurfPS = parameter().getInt("psolsurf_practice_score", 0);
        int padsurfPS = parameter().getInt("padsurf_practice_score", 0);
        int pdriftPS = parameter().getInt("pdrift_practice_score", 0);
        int aoaNleachThshold = parameter().getInt("aoa_nleach_threshold", 0);
        int aoaNrunThshold = parameter().getInt("aoa_nrun_threshold", 0);
        int aoaSedrunThshold = parameter().getInt("aoa_sedrun_threshold", 0);
        int aoaPrunThshold = parameter().getInt("aoa_prun_threshold", 0);
        int aoaPleachHT = parameter().getInt("aoa_pleach_human_threshold", 0);
        int aoaPleachFT = parameter().getInt("aoa_pleach_matcfish_threshold", 0);
        int aoaPsorunHT = parameter().getInt("aoa_psorun_human_threshold", 0);
        int aoaPsorunFT = parameter().getInt("aoa_psorun_matcfish_threshold", 0);
        int aoaPadrunHT = parameter().getInt("aoa_padrun_human_threshold", 0);
        int aoaPadrunFT = parameter().getInt("aoa_padrun_stvfish_threshold", 0);
        int aoaPdriftHT = parameter().getInt("aoa_pdrift_human_threshold", 0);
        int aoaPdriftFT = parameter().getInt("aoa_pdrift_fish_threshold", 0);
        aoa = new Input(id, nleachTS, nsurfTS, psurfTS, nleachPS, ssurfPS, nsurfPS, psurfPS, nleachAppMgtScore, nsurfAppMgtScore,
                psurfAppMgtScore, pleachIpmScore, psolsurfIpmScore, padsurfIpmScore, pdriftIpmScore, pleachTS, psolsurfTS,
                padsurfTS, pdriftTS, pleachPS, psolsurfPS, padsurfPS, pdriftPS, aoaNleachThshold, aoaNrunThshold, aoaSedrunThshold,
                aoaPrunThshold, aoaPleachHT, aoaPleachFT, aoaPsorunHT, aoaPsorunFT, aoaPadrunHT, aoaPadrunFT, aoaPdriftHT, aoaPdriftFT);
    }

    @Override
    protected void postProcess() throws JSONException {
        results().put("AoAId", aoa.AoAId, "Area of Analysis Identifier");
        results().put("bar_nleach_mit_score", aoa.getNleachMitScore(), "Mitigation Score for Nitrogen In Ground Water");
        results().put("bar_nleach_threshold", aoa.getNleachThreshold(), "Threshold Score for Nitrogen In Ground Water");
        results().put("bar_nsurf_mit_score", aoa.getNsurfMitScore(), "Mitigation Score for Nitrogen In Surface Water");
        results().put("bar_nsurf_threshold", aoa.getNsurfThreshold(), "Threshold Score for Nitrogen In Surface Water");
        results().put("bar_psurf_mit_score", aoa.getPsurfMitScore(), "Mitigation Score for Phosphorus In Surface Water");
        results().put("bar_psurf_threshold", aoa.getPsurfThreshold(), "Threshold Score for Phosphorus In Surface Water");
        results().put("bar_ssurf_mit_score", aoa.getSsurfMitScore(), "Mitigation Score for Sediment In Surface Water");
        results().put("bar_ssurf_threshold", aoa.getSsurfThreshold(), "Threshold Score for Sediment In Surface Water");
        results().put("bar_pleach_human_mit_score", aoa.getPleachHumanMitScore(), "Mitigation Score for Pesticide Leaching (Human)");
        results().put("bar_pleach_human_threshold", aoa.getPleachHumanThreshold(), "Threshold Score for Pesticide Leaching (Human)");
        results().put("bar_pleach_fish_mit_score", aoa.getPleachFishMitScore(), "Mitigation Score for Pesticide Leaching (Fish)");
        results().put("bar_pleach_fish_threshold", aoa.getPleachFishThreshold(), "Threshold Score for Pesticide Leaching (Fish)");
        results().put("bar_psorun_human_mit_score", aoa.getPsorunHumanMitScore(), "Mitigation Score for Pesticide Solution Runoff (Human)");
        results().put("bar_psorun_human_threshold", aoa.getPsorunHumanThreshold(), "Threshold Score for Pesticide Solution Runoff (Human)");
        results().put("bar_psorun_fish_mit_score", aoa.getPsorunFishMitScore(), "Mitigation Score for Pesticide Solution Runoff (Fish)");
        results().put("bar_psorun_fish_threshold", aoa.getPsorunFishThreshold(), "Threshold Score for Pesticide Solution Runoff (Fish)");
        results().put("bar_padrun_human_mit_score", aoa.getPadrunHumanMitScore(), "Mitigation Score for Pesticide Adsorbed Runoff (Human)");
        results().put("bar_padrun_human_threshold", aoa.getPadrunHumanThreshold(), "Threshold Score for Pesticide Adsorbed Runoff (Human)");
        results().put("bar_padrun_fish_mit_score", aoa.getPadrunFishMitScore(), "Mitigation Score for Pesticide Adsorbed Runoff (Fish)");
        results().put("bar_padrun_fish_threshold", aoa.getPadrunFishThreshold(), "Threshold Score for Pesticide Adsorbed Ruoff (Fish)");
        results().put("bar_pdrift_human_mit_score", aoa.getPdriftHumanMitScore(), "Mitigation Score for Pesticide Drift (Human)");
        results().put("bar_pdrift_human_threshold", aoa.getPdriftHumanThreshold(), "Threshold Score for Pesticide Drift (Human)");
        results().put("bar_pdrift_fish_mit_score", aoa.getPdriftFishMitScore(), "Mitigation Score for Pesticide Drift (Fish)");
        results().put("bar_pdrift_fish_threshold", aoa.getPdriftFishThreshold(), "Threshold Score for Pesticide Drift (Fish)");
    }

    static class Input {

        protected int AoAId, nleachTechnScore, nsurfTechnScore, psurfTechnScore, nleachPractScore, ssurfPractScore, nsurfPractScore,
                psurfPractScore, nleachAppMgtScore, nsurfAppMgtScore, psurfAppMgtScore, pleachIpmScore, psolsurfIpmScore, padsurfIpmScore,
                pdriftIpmScore, pleachTechniqueScore, psolsurfTechniqueScore, padsurfTechniqueScore, pdriftTechniqueScore, pleachPracticeScore,
                psolsurfPracticeScore, padsurfPracticeScore, pdriftPracticeScore;
        protected int aoaNleachThreshold, aoaNrunThreshold, aoaPleachHumanThreshold, aoaPleachMatcfishThreshold, aoaPsorunHumanThreshold,
                aoaPsorunMatcfishThreshold, aoaPadrunHumanThreshold, aoaPadrunStvfishThreshold;

        public Input(int id, int nleachTS, int nsurfTS, int psurfTS, int nleachPS, int ssurfPS, int nsurfPS, int psurfPS, int nleachAppMgtScore,
                int nsurfAppMgtScore, int psurfAppMgtScore, int pleachIpmScore, int psolsurfIpmScore, int padsurfIpmScore, int pdriftIpmScore,
                int pleachTS, int psolsurfTS, int padsurfTS, int pdriftTS, int pleachPS, int psolsurfPS, int padsurfPS, int pdriftPS,
                int aoaNleachThshold, int aoaNrunThshold, int aoaSedrunThshold, int aoaPrunThshold, int aoaPleachHT, int aoaPleachFT,
                int aoaPsorunHT, int aoaPsorunFT, int aoaPadrunHT, int aoaPadrunFT, int aoaPdriftHT, int aoaPdriftFT) {
            AoAId = id;
            nleachTechnScore = nleachTS;
            nsurfTechnScore = nsurfTS;
            psurfTechnScore = psurfTS;
            nleachPractScore = nleachPS;
            ssurfPractScore = ssurfPS;
            nsurfPractScore = nsurfPS;
            psurfPractScore = psurfPS;
            this.nleachAppMgtScore = nleachAppMgtScore;
            this.nsurfAppMgtScore = nsurfAppMgtScore;
            this.psurfAppMgtScore = psurfAppMgtScore;
            this.pleachIpmScore = pleachIpmScore;
            this.psolsurfIpmScore = psolsurfIpmScore;
            this.padsurfIpmScore = padsurfIpmScore;
            this.pdriftIpmScore = pdriftIpmScore;
            pleachTechniqueScore = pleachTS;
            psolsurfTechniqueScore = psolsurfTS;
            padsurfTechniqueScore = padsurfTS;
            pdriftTechniqueScore = pdriftTS;
            pleachPracticeScore = pleachPS;
            psolsurfPracticeScore = psolsurfPS;
            padsurfPracticeScore = padsurfPS;
            pdriftPracticeScore = pdriftPS;
            aoaNleachThreshold = aoaNleachThshold;
            aoaNrunThreshold = aoaNrunThshold;
            aoaPleachHumanThreshold = aoaPleachHT;
            aoaPleachMatcfishThreshold = aoaPleachFT;
            aoaPsorunHumanThreshold = aoaPsorunHT;
            aoaPsorunMatcfishThreshold = aoaPsorunFT;
            aoaPadrunHumanThreshold = aoaPadrunHT;
            aoaPadrunStvfishThreshold = aoaPadrunFT;
        }

        //Nitrogen in Ground Water mitigation and threshold scores
        public int getNleachMitScore() {
            return nleachTechnScore + nleachPractScore + nleachAppMgtScore;
        }

        public int getNleachThreshold() {
            return aoaNleachThreshold;
        }

        //Nitrogen in Surface Water mitigation and threshold scores
        public int getNsurfMitScore() {
            return nsurfTechnScore + nsurfPractScore + nsurfAppMgtScore;
        }

        public int getNsurfThreshold() {
            return aoaNrunThreshold;
        }

        //Phosphorus in Surface Water mitigation and threshold scores
        public int getPsurfMitScore() {
            return psurfTechnScore + psurfPractScore + psurfAppMgtScore;
        }

        public int getPsurfThreshold() {
            return aoaNrunThreshold;
        }

        //Sediment in Surface Water mitigation and threshold scores
        public int getSsurfMitScore() {
            return ssurfPractScore;
        }

        public int getSsurfThreshold() {
            return aoaNrunThreshold;
        }

        //Pesticide in Ground Water - Human mitigation and threshold scores
        public int getPleachHumanMitScore() {
            return pleachIpmScore + pleachTechniqueScore + pleachPracticeScore;
        }

        public int getPleachHumanThreshold() {
            return aoaPleachHumanThreshold;
        }

        //Pesticide in Ground Water - Fish mitigation and threshold scores
        public int getPleachFishMitScore() {
            return pleachIpmScore + pleachTechniqueScore + pleachPracticeScore;
        }

        public int getPleachFishThreshold() {
            return aoaPleachMatcfishThreshold;
        }

        //Pesticide in Solution Runoff - Human mitigation and threshold scores
        public int getPsorunHumanMitScore() {
            return psolsurfIpmScore + psolsurfTechniqueScore + psolsurfPracticeScore;
        }

        public int getPsorunHumanThreshold() {
            return aoaPsorunHumanThreshold;
        }

        //Pesticide in Solution Runoff - Fish mitigation and threshold scores
        public int getPsorunFishMitScore() {
            return psolsurfIpmScore + psolsurfTechniqueScore + psolsurfPracticeScore;
        }

        public int getPsorunFishThreshold() {
            return aoaPsorunMatcfishThreshold;
        }

        //Pesticide in Adsorbed Runoff - Human mitigation and threshold scores
        public int getPadrunHumanMitScore() {
            return padsurfIpmScore + padsurfTechniqueScore + padsurfPracticeScore;
        }

        public int getPadrunHumanThreshold() {
            return aoaPadrunHumanThreshold;
        }

        //Pesticide in Adsorbed Runoff - Fish mitigation and threshold scores
        public int getPadrunFishMitScore() {
            return padsurfIpmScore + padsurfTechniqueScore + padsurfPracticeScore;
        }

        public int getPadrunFishThreshold() {
            return aoaPadrunStvfishThreshold;
        }

        //Pesticide Drift - Human mitigation and threshold scores
        public int getPdriftHumanMitScore() {
            return pdriftIpmScore + pdriftTechniqueScore + pdriftPracticeScore;
        }

        public int getPdriftHumanThreshold() {
            return aoaPsorunHumanThreshold;
        }

        //Pesticide Drift - Fish mitigation and threshold scores
        public int getPdriftFishMitScore() {
            return pdriftIpmScore + pdriftTechniqueScore + pdriftPracticeScore;
        }

        public int getPdriftFishThreshold() {
            return aoaPsorunMatcfishThreshold;
        }
    }
}