SignificantSoil.java [src/java/d/soils/topthree] Revision: default  Date:
/*
 * $Id$
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API, and application suite.
 *
 * 2012-2019, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package d.soils.topthree;

import csip.api.server.ServiceException;
import csip.utils.JSONUtils;
import static d.soils.topthree.V1_0.MIN_ACRES;
import java.util.Arrays;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import soils.Component;
import soils.MapUnit;
import soils.db.tables.TableComponent;
import soils.db.tables.TableComponentCalculations;
import soils.db.tables.TableHorizon;
import soils.db.tables.TableHorizonCalculations;
import soils.db.tables.TableMapUnit;
import static soils.db.tables.TableMapUnit.AREASYMBOL_NAME;
import soils.db.tables.TableMapUnitCalculations;
import soils.utils.EvalResult;

/**
 *
 * @author <a href="mailto:shaun.case@colostate.edu">Shaun Case</a>
 */
public class SignificantSoil {

  MapUnit mapUnit;
  Component component;
  double area = 0.0;
  String rusle2SUID = "";
  String wepsSUID = "";
  String demSUID = "";
  double lambda = Double.NaN;
  double lsFactor = Double.NaN;




  public boolean hasGoodArea() {
    return (area >= MIN_ACRES);
  }


  public JSONArray toJSON() throws JSONException, ServiceException {
    JSONArray soilDetail = new JSONArray();
    mapUnit.outputShapes(true);

    soilDetail.put(JSONUtils.dataDesc("intersection_polygon_count", mapUnit.getIntersectionPolygons().size(),
        "An informational message describing the number of polygons that resulted "
        + "from an intersection with this SDM soil component's mapunit polygon (mupolygon) "
        + "boundary."));
    mapUnit.setOutputColumnOrdering(Arrays.asList(
        AREASYMBOL_NAME, TableMapUnit.MUKEY, TableMapUnit.MUSYM, TableMapUnit.MUNAME,
        TableMapUnitCalculations.AREA_NAME, TableMapUnitCalculations.AREA_PCT));
    mapUnit.mapUnitJSON(soilDetail);
    component.setOutputColumnOrdering(Arrays.asList(
        TableComponent.COKEY, TableComponent.COMPNAME, TableComponentCalculations.LONG_NAME,
        TableComponent.SLOPE_R_NAME, TableComponentCalculations.COMP_AREA_NAME,
        TableComponentCalculations.AREA_PCT_NAME, TableComponent.COMPPCT_R_NAME,
        TableComponent.TFACT_NAME,
        TableComponentCalculations.CLAYTOTAL_R, TableComponentCalculations.SANDTOTAL_R_NAME,
        TableComponentCalculations.KFFACT_NAME, TableComponentCalculations.LSFACT_NAME,
        TableComponentCalculations.OM_R_NAME,
        TableComponentCalculations.COARSE_FRAG_TOTAL_NAME, TableComponentCalculations.COARSE_FRAG_NAME
    ));
    component.setHorizonOutputColumnOrdering(Arrays.asList(
        TableHorizon.CHKEY_NAME, TableHorizon.HZNAME,
        TableHorizon.CACO3_R, TableHorizon.CEC7_R, TableHorizon.ECEC_R,
        TableHorizon.CLAYTOTAL_R, TableHorizon.SANDTOTAL_R_NAME, TableHorizon.SILTTOTAL_R,
        TableHorizon.HZDEPT_R_NAME, TableHorizon.HZDEPB_R_NAME, TableHorizon.HZTHK_R_NAME,
        TableHorizon.KFFACT_NAME, TableHorizon.KWFACT_NAME, TableHorizon.KSAT_R, TableHorizon.OM_R_NAME,
        TableHorizon.FRAGGT10_R,
        TableHorizonCalculations.DEPT_R_IN, TableHorizonCalculations.DEPB_R_IN,
        TableHorizonCalculations.FRAGVOL_R_NAME, TableHorizonCalculations.LSFACT_NAME
    ));
    JSONArray cArray = component.toJSON(false);
    for (int i = 0; i < cArray.length(); i++) {
      soilDetail.put(cArray.get(i));
    }

    soilDetail.put(JSONUtils.dataDesc("component_calculated_kffact", EvalResult.writeDouble(component.calculated_kffact(), "%.4f"),
        "A calculated K factor value taken from the selected Mineral Horizon of the Soil Component or adjusted based on Soils SME logic."));
    soilDetail.put(JSONUtils.data("component_calculated_claytotal", EvalResult.writeDouble(component.calculated_claytotal_r(), "%.4f"),
        "Mineral particles less than 0.002mm in equivalent diameter as a weight percentage of the less than 2.0mm fraction.", "Percent"));

    return soilDetail;
  }

}