@@ -19,6 +19,7 @@ |
import java.util.Collection; |
import java.util.HashMap; |
import java.util.LinkedList; |
+import java.util.Map; |
import java.util.concurrent.Callable; |
import java.util.logging.Level; |
import javax.ws.rs.Path; |
@@ -36,6 +37,7 @@ |
import org.apache.http.client.methods.HttpUriRequest; |
import org.apache.http.impl.client.DefaultHttpClient; |
import org.codehaus.jettison.json.JSONArray; |
+import org.codehaus.jettison.json.JSONException; |
import org.codehaus.jettison.json.JSONObject; |
import usda.weru.weps.reports.query.WepsConnection; |
import util.ErosionConst; |
@@ -862,15 +864,7 @@ |
if (wo.bNaN) |
appendMetainfoWarning(ErosionConst.WEPS_FOUND_NAN_IN_OUTPUT); |
|
- FileReader fr2 = new FileReader(sessionWorkDir +"/gui1_data.out"); |
- BufferedReader bfr2 = new BufferedReader(fr2); |
- String guiString = ""; |
- while(bfr2.ready()){ |
- guiString += bfr2.readLine(); |
- } |
- bfr2.close(); |
- fr2.close(); |
- GUI1Parser.parseGUI1(guiString, wo); |
+ getAdvancedOutput(wo); |
|
// Special unit conversions for Phacil |
double dieselEnergy_gallonsPerAcre = Double.parseDouble(wo.dieselEnergy) * CONV_LITERHECTATRE_TO_GALLONACRE; |
@@ -898,6 +892,39 @@ |
return results; |
} |
|
+ private void getAdvancedOutput(WepsOutput wOutput) throws JSONException, Exception{ |
+ JSONArray reportItems = new JSONArray(); |
+ JSONObject item = new JSONObject(); |
+ JSONArray report; |
+ Map<String,JSONObject> reportValues; |
+ JSONArray suspen; |
+ JSONArray salt; |
+ JSONArray pm10; |
+ |
+ item.put("name","output.suspen"); |
+ reportItems.put(item); |
+ |
+ item = new JSONObject(); |
+ item.put("name", "output.crp_salt"); |
+ reportItems.put(item); |
+ |
+ item = new JSONObject(); |
+ item.put("name", "output.pm10"); |
+ reportItems.put(item); |
+ |
+ report = createReport(reportItems); |
+ |
+ reportValues = JSONUtils.preprocess(report); |
+ |
+ suspen = JSONUtils.getJSONArrayParam(reportValues, "output.suspen"); |
+ salt = JSONUtils.getJSONArrayParam(reportValues, "output.salt"); |
+ pm10 = JSONUtils.getJSONArrayParam(reportValues, "output.pm10"); |
+ |
+ wo.suspension = suspen.getString(suspen.length()-1); |
+ wo.saltation = salt.getString(salt.length() -1); |
+ wo.pm10 = pm10.getString(pm10.length() - 1); |
+ } |
+ |
// @Override |
// public String getModelName() { |
// return "weps/1.2"; |
@@ -1003,4 +1030,88 @@ |
//LOG.info("Updated Report JSON obj=" + reportObj.toString()); |
return reportItems; |
} |
+ |
+ /** |
+ * This is an overloaded method for createReport that allows you to only query a set of item in a report |
+ * @param reportItems items you want returned in the report |
+ * @return The report data |
+ * @throws Exception |
+ */ |
+ private JSONArray createReport(JSONArray reportItems) throws Exception { |
+ |
+ |
+ String workDir = getWorkspaceDir().toString(); |
+ File reportTemplate = new File(workDir + "/" + REPORT_JSON_FILENAME); |
+ String sReportJSON = FileUtils.readFileToString(reportTemplate); |
+ //JSONObject reportObj = new JSONObject(sReportJSON); |
+ //JSONArray reportItems = reportObj.getJSONArray("WEPSreport"); |
+ if(reportItems == null || reportItems.length() == 0) |
+ reportItems = new JSONArray(sReportJSON); |
+ |
+ WepsConnection con = new WepsConnection(); |
+ |
+ // Create an instance of this class to do the actual loading. |
+ WepsReportData reportdata = new WepsReportData(con); |
+ |
+ // Set the location of the folder to translate files in. |
+ String sInputDirectory = workDir; |
+ if (!reportdata.setInputDirectory(sInputDirectory)) { |
+ // Print a usage message and quit |
+ LOG.severe("error: WEPS reports input directory doesn't exist."); |
+ throw new ServiceException("Error create WEPS reports. Report directory does not exist."); |
+ } |
+ |
+ // @todo set configuration options. |
+ reportdata.m_sUnits = "US"; |
+ |
+ // Load the file data. |
+ LOG.info("WorkingDir: "+ getWorkspaceDir().toString()); |
+ |
+ reportdata.loadFiles(getWorkspaceDir().toString()); |
+ |
+ // // Dump the loaded data as text for debugging purposes. |
+ // LOG.info("hash map output=" + con.toString()); |
+ // |
+ // LOG.info("Original Report JSON obj=" + reportObj.toString()); |
+ HashMap<String, ArrayList<Object>> m_reportdata = con.getParamValues(); |
+ for (int i = 0; i < reportItems.length(); i++) { |
+ JSONObject obj = (JSONObject) reportItems.get(i); |
+ String itemName = obj.getString(REPORT_NAME); |
+ //LOG.info("COMPARISON for scalars: itemname='" + itemName + "'"); |
+ //if (itemName.length() >= 5) LOG.info("COMPARISON for scalars: itemname 0,5='" + itemName.substring(0,5) + "'"); |
+ //if (itemName.length() >= 11) LOG.info("COMPARISON for scalars: itemname 0,11='" + itemName.substring(0,11) + "'"); |
+ if ((itemName != null) && ((((itemName.length()) >= 5) && (itemName.substring(0, 5).contentEquals("runs."))) |
+ || (((itemName.length()) >= 11) && (itemName.substring(0, 11).contentEquals("sci_energy."))))) { |
+ // Scalar values |
+ //LOG.info("look up " + itemName + " in report hash table for scalar output."); |
+ ArrayList<Object> scalar = m_reportdata.get(itemName); |
+ if (scalar != null) { |
+ //LOG.info("putting to jsonobj=" + scalar.get(0)); |
+ obj.put(REPORT_VALUE, scalar.get(0)); |
+ reportItems.put(i, obj); |
+ } else { |
+ LOG.warning("WEPS report generatioin: Scalar parameter has no data in hashmap=" + itemName); |
+ } |
+ } else { |
+ // Array values |
+ //LOG.info("look up " + itemName + " in report hash table for array output."); |
+ LinkedList coll = new LinkedList(); |
+ ArrayList<Object> array = m_reportdata.get(itemName); |
+ if (array != null) { |
+ for (int j = 0; j < array.size(); j++) { |
+ coll.add(array.get(j)); |
+ } |
+ |
+ obj.put(REPORT_VALUE, (Collection) coll); |
+ reportItems.put(i, obj); |
+ } else { |
+ LOG.warning("WEPS report generation: Array parameter has no data in hashmap=" + itemName); |
+ } |
+ } |
+ obj.remove(REPORT_TYPE); |
+ |
+ } |
+ //LOG.info("Updated Report JSON obj=" + reportObj.toString()); |
+ return reportItems; |
+ } |
} |