Displaying differences for changeset
 
display as  

src/java/m/rhem/model/RhemModel.java

@@ -13,6 +13,8 @@
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import org.apache.commons.io.FileUtils;
 import static rhem.utils.RHEMUtils.formatDouble;
 
@@ -22,11 +24,7 @@
  */
 public class RhemModel {
 
-//  String stateId;
-//  String climatestationId;
   String scenarioName;
-  String today;
-
   File workSpaceDir;
 
   String parameterFileName;
@@ -37,11 +35,9 @@
   double avgSoilLoss;
 
 
-  public RhemModel(String scenarioName,
-      String today, File workSpaceDir, String parameterFileName,
+  public RhemModel(String scenarioName, File workSpaceDir, String parameterFileName,
       String stormFileName, String runFileName, String summaryFileName) {
     this.scenarioName = scenarioName;
-    this.today = today;
     this.workSpaceDir = workSpaceDir;
     this.parameterFileName = parameterFileName;
     this.stormFileName = stormFileName;
@@ -52,8 +48,10 @@
 
   public void generateParamFile(Parameter param) throws ServiceException {
     try (PrintWriter w = new PrintWriter(new File(workSpaceDir, parameterFileName))) {
+      String now = new SimpleDateFormat("MMMM dd, YYYY, hh:mm a").format(new Date());
+
       w.println("! Parameter file for scenario: " + scenarioName);
-      w.println("! Date built: " + today + " (Version 2.3)");
+      w.println("! Date built: " + now + " (Version 2.3)");
       w.println("! Parameter units: DIAMS(mm), DENSITY(g/cc),TEMP(deg C)");
       w.println("BEGIN GLOBAL");
       w.println(String.format("        %-8s=   %s", "CLEN", param.clen));
@@ -142,8 +140,9 @@
 
   void appendInfo(File tempFile, long counter, String stateId, String climatestationId) throws ServiceException {
     try (PrintWriter writer = new PrintWriter(new File(workSpaceDir, stormFileName))) {
+      String now = new SimpleDateFormat("MMMM dd, YYYY, hh:mm a").format(new Date());
       writer.println("# Storm file for scenario: " + scenarioName);
-      writer.println("# Date built: " + today + " (Version 2.3)");
+      writer.println("# Date built: " + now + " (Version 2.3)");
       writer.println("# State: " + stateId);
       writer.println("# Climate Station: " + climatestationId);
       writer.println(counter + " # The number of rain events");

src/java/m/rhem/rhem01_runmodel/V1_0.java

@@ -139,8 +139,6 @@
 
   @Override
   public void doProcess() throws Exception {
-    SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd, YYYY, hh:mm a");
-    String today = sdf.format(new Date());
 
     String fileName = aoa.getScenarioName();
     if (fileName.length() > 15) {
@@ -158,7 +156,7 @@
       parameter.computeParameters(connection, aoa);
     }
 
-    rhemModel = new RhemModel(aoa.getScenarioName(), today, workspace().getDir(), parameterFileName,
+    rhemModel = new RhemModel(aoa.getScenarioName(), workspace().getDir(), parameterFileName,
         stormFileName, runFileName, summaryFileName);
 
     rhemModel.generateParamFile(parameter);

src/java/m/rhem/rhem01_runmodel/V2_0.java

@@ -160,8 +160,7 @@
           try (Connection con = resources().getJDBC(DBResources.CRDB)) {
             parameter.computeParameters(con, aoa);
           }
-          String now = new SimpleDateFormat("MMMM dd, YYYY, hh:mm a").format(new Date());
-          rhemModel = new RhemModel(aoa.getScenarioName(), now, workspace().getDir(), parameterFileName,
+          rhemModel = new RhemModel(aoa.getScenarioName(), workspace().getDir(), parameterFileName,
               stormFileName, runFileName, summaryFileName);
 
           rhemModel.generateParamFile(parameter);

src/java/m/rhem/rhem02_getclimatestations/V1_0.java

@@ -38,198 +38,218 @@
  */
 @Name("RHEM-02: Get Climate Stations")
 @Description("Returns a list of climate stations associated with the state "
-        + "selected by the user. Information associated with each climate "
-        + "station will be station name, latitude, longitude, number of "
-        + "years of observed data, elevation (feet) and 300 year average "
-        + "and monthly precipitation amounts (millimeters).")
+    + "selected by the user. Information associated with each climate "
+    + "station will be station name, latitude, longitude, number of "
+    + "years of observed data, elevation (feet) and 300 year average "
+    + "and monthly precipitation amounts (millimeters).")
 @Path("m/rhem/getclimatestations/1.0")
 @Polling(first = 10000, next = 2000)
 @Resource(from = DBResources.class)
 public class V1_0 extends ModelDataService {
 
-    private String stateId;
-    private ClimateStationStates climateStationStates;
+  private String stateId;
+  private ClimateStationStates climateStationStates;
 
-    @Override
-    public void preProcess() throws ServiceException {
-        stateId = parameter().getString("stateid");
+
+  @Override
+  public void preProcess() throws ServiceException {
+    stateId = parameter().getString("stateid");
+  }
+
+
+  @Override
+  public void doProcess() throws ServiceException {
+    try (Connection connection = resources().getJDBC(DBResources.CRDB);
+        Statement statement = connection.createStatement()) {
+
+      try (ResultSet resultSet = statement.executeQuery(DBResources.RHEM02Query01(stateId))) {
+        while (resultSet.next()) {
+          climateStationStates = new ClimateStationStates(stateId,
+              resultSet.getString("state_name"),
+              resultSet.getDouble("latitude"),
+              resultSet.getDouble("longitude"),
+              resultSet.getInt("zoom"));
+        }
+      }
+
+      try (ResultSet resultSet = statement.executeQuery(DBResources.RHEM02Query02(stateId))) {
+        ArrayList<ClimateStation> climateStationsList = new ArrayList();
+        while (resultSet.next()) {
+          double[] monthlyPrecip = new double[12];
+          for (int i = 0; i < 12; i++) {
+            monthlyPrecip[i] = resultSet.getDouble(MONTH_NAMES_LIST[i].toLowerCase().substring(0, 3) + "_precip_mm");
+          }
+
+          climateStationsList.add(new ClimateStation(
+              resultSet.getString("station_id"),
+              resultSet.getString("station"),
+              resultSet.getDouble("latitude"),
+              resultSet.getDouble("longitude"),
+              resultSet.getInt("years"),
+              resultSet.getInt("elevation"),
+              resultSet.getDouble("avg_yearly_precip_mm"),
+              monthlyPrecip));
+        }
+        climateStationStates.addClimateStationsList(climateStationsList);
+      }
+    } catch (SQLException se) {
+      throw new ServiceException(se);
+    }
+  }
+
+
+  @Override
+  public void postProcess() throws ServiceException {
+    try {
+      results().put("stateid", climateStationStates.getStateId(), "State abbreviation of climate station location");
+      results().put("state_name", climateStationStates.getStateName(), "State name");
+      results().put("latitude", climateStationStates.getStateLatitude(), "Central latitude of the state");
+      results().put("longitude", climateStationStates.getStateLongitude(), "Central longitude of the state");
+      results().put("zoom", climateStationStates.getZoom(), "Zoom level utilized to display state map on UI");
+
+      JSONArray climateStationArray = new JSONArray();
+      for (ClimateStation climateStation : climateStationStates.getClimateStationsList()) {
+        JSONArray innerArray = new JSONArray();
+        innerArray.put(JSONUtils.dataDesc("station_id", climateStation.getStationId(), "Climate station identification number"));
+        innerArray.put(JSONUtils.dataDesc("station_name", climateStation.getStationName(), "Climate station name"));
+        innerArray.put(JSONUtils.dataDesc("lat", climateStation.getStationLatitude(), "Climate station latitude"));
+        innerArray.put(JSONUtils.dataDesc("long", climateStation.getStationLongitude(), "Climate station longitude"));
+        innerArray.put(JSONUtils.dataDesc("year_recorded", climateStation.getYearRecorded(), "Number of years of recorded observations for climate station"));
+        innerArray.put(JSONUtils.dataDesc("elevation_ft", climateStation.getElevation(), "Climate station elevation"));
+        innerArray.put(JSONUtils.dataDesc("avg_yearly_precip_mm", RHEMUtils.roundValues(climateStation.getAvgYearlyPrecip(), 2), "300 year average annual precipitation (mm)"));
+        for (int i = 0; i < 12; i++) {
+          innerArray.put(JSONUtils.dataDesc(MONTH_NAMES_LIST[i].substring(0, 3).toLowerCase() + "_precip_mm",
+              RHEMUtils.roundValues(climateStation.getMonthlyPrecip()[i], 2), MONTH_NAMES_LIST[i] + " estimated monthly average precipitation (mm)"));
+        }
+        climateStationArray.put(JSONUtils.dataDesc("climate_stations", innerArray, "Climate station attributes"));
+      }
+      results().put("climate_station_list", climateStationArray, "Climate Station List");
+    } catch (JSONException ex) {
+      throw new ServiceException(ex);
+    }
+  }
+
+  static class ClimateStationStates {
+
+    protected String stateId;
+    protected String stateName;
+    protected double latitude;
+    protected double longitude;
+    protected int zoom;
+    protected ArrayList<ClimateStation> climateStationsList;
+
+
+    public ClimateStationStates(String stateId, String stateName, double latitude,
+        double longitude, int zoom) {
+      this.stateId = stateId;
+      this.stateName = stateName;
+      this.latitude = latitude;
+      this.longitude = longitude;
+      this.zoom = zoom;
     }
 
-    @Override
-    public void doProcess() throws ServiceException {
-        try (Connection connection = resources().getJDBC(DBResources.CRDB);
-                Statement statement = connection.createStatement()) {
 
-            try (ResultSet resultSet = statement.executeQuery(DBResources.RHEM02Query01(stateId))) {
-                while (resultSet.next()) {
-                    climateStationStates = new ClimateStationStates(stateId,
-                            resultSet.getString("state_name"),
-                            resultSet.getDouble("latitude"),
-                            resultSet.getDouble("longitude"),
-                            resultSet.getInt("zoom"));
-                }
-            }
-
-            try (ResultSet resultSet = statement.executeQuery(DBResources.RHEM02Query02(stateId))) {
-                ArrayList<ClimateStation> climateStationsList = new ArrayList();
-                while (resultSet.next()) {
-                    double[] monthlyPrecip = new double[12];
-                    for (int i = 0; i< 12; i++) {
-                        monthlyPrecip[i] = resultSet.getDouble(MONTH_NAMES_LIST[i].toLowerCase().substring(0,3) + "_precip_mm");
-                    }
-
-                    climateStationsList.add(new ClimateStation(
-                            resultSet.getString("station_id"),
-                            resultSet.getString("station"),
-                            resultSet.getDouble("latitude"),
-                            resultSet.getDouble("longitude"),
-                            resultSet.getInt("years"),
-                            resultSet.getInt("elevation"),
-                            resultSet.getDouble("avg_yearly_precip_mm"),
-                            monthlyPrecip));
-                }
-                climateStationStates.addClimateStationsList(climateStationsList);
-            }
-        } catch (SQLException se) {
-            throw new ServiceException(se);
-        }
+    public String getStateId() {
+      return this.stateId;
     }
 
-    @Override
-    public void postProcess() throws ServiceException {
-        try {
-            results().put("stateid", climateStationStates.getStateId(), "State abbreviation of climate station location");
-            results().put("state_name", climateStationStates.getStateName(), "State name");
-            results().put("latitude", climateStationStates.getStateLatitude(), "Central latitude of the state");
-            results().put("longitude", climateStationStates.getStateLongitude(), "Central longitude of the state");
-            results().put("zoom", climateStationStates.getZoom(), "Zoom level utilized to display state map on UI");
 
-            JSONArray climateStationArray = new JSONArray();
-            for (ClimateStation climateStation : climateStationStates.getClimateStationsList()) {
-                JSONArray innerArray = new JSONArray();
-                innerArray.put(JSONUtils.dataDesc("station_id", climateStation.getStationId(), "Climate station identification number"));
-                innerArray.put(JSONUtils.dataDesc("station_name", climateStation.getStationName(), "Climate station name"));
-                innerArray.put(JSONUtils.dataDesc("lat", climateStation.getStationLatitude(), "Climate station latitude"));
-                innerArray.put(JSONUtils.dataDesc("long", climateStation.getStationLongitude(), "Climate station longitude"));
-                innerArray.put(JSONUtils.dataDesc("year_recorded", climateStation.getYearRecorded(), "Number of years of recorded observations for climate station"));
-                innerArray.put(JSONUtils.dataDesc("elevation_ft", climateStation.getElevation(), "Climate station elevation"));
-                innerArray.put(JSONUtils.dataDesc("avg_yearly_precip_mm", RHEMUtils.roundValues(climateStation.getAvgYearlyPrecip(), 2), "300 year average annual precipitation (mm)"));
-                for (int i = 0; i < 12; i++) {
-                    innerArray.put(JSONUtils.dataDesc(MONTH_NAMES_LIST[i].substring(0, 3).toLowerCase() + "_precip_mm",
-                            RHEMUtils.roundValues(climateStation.getMonthlyPrecip()[i], 2), MONTH_NAMES_LIST[i] + " estimated monthly average precipitation (mm)"));
-                }
-                climateStationArray.put(JSONUtils.dataDesc("climate_stations", innerArray, "Climate station attributes"));
-            }
-            results().put("climate_station_list", climateStationArray, "Climate Station List");
-        } catch (JSONException ex) {
-            throw new ServiceException(ex);
-        }
+    public String getStateName() {
+      return this.stateName;
     }
 
-    static class ClimateStationStates {
 
-        protected String stateId;
-        protected String stateName;
-        protected double latitude;
-        protected double longitude;
-        protected int zoom;
-        protected ArrayList<ClimateStation> climateStationsList;
-
-        public ClimateStationStates(String stateId, String stateName, double latitude,
-                double longitude, int zoom) {
-            this.stateId = stateId;
-            this.stateName = stateName;
-            this.latitude = latitude;
-            this.longitude = longitude;
-            this.zoom = zoom;
-        }
-
-        public String getStateId() {
-            return this.stateId;
-        }
-
-        public String getStateName() {
-            return this.stateName;
-        }
-
-        public double getStateLatitude() {
-            return this.latitude;
-        }
-
-        public double getStateLongitude() {
-            return this.longitude;
-        }
-
-        public int getZoom() {
-            return this.zoom;
-        }
-
-        public ArrayList<ClimateStation> getClimateStationsList() {
-            return this.climateStationsList;
-        }
-
-        public void addClimateStationsList(ArrayList<ClimateStation> list) {
-            this.climateStationsList = list;
-        }
-
+    public double getStateLatitude() {
+      return this.latitude;
     }
 
-    static class ClimateStation {
 
-        protected String stationId;
-        protected String stationName;
-        protected double latitude;
-        protected double longitude;
-        protected int yearRecorded;
-        protected int elevation_ft;
-        protected double avgYearlyPrecip_mm;
-        protected double[] monthlyPrecip_mm;
+    public double getStateLongitude() {
+      return this.longitude;
+    }
 
-        public ClimateStation(String stationId, String stationName, double latitude,
-                double longitude, int yearRecorded, int elevation,
-                double avg_yearly_precip_mm, double[] monthlyPrecip_mm) {
 
-            this.stationId = stationId;
-            this.stationName = stationName;
-            this.latitude = latitude;
-            this.longitude = longitude;
-            this.yearRecorded = yearRecorded;
-            this.elevation_ft = elevation;
-            this.avgYearlyPrecip_mm = avg_yearly_precip_mm;
-            this.monthlyPrecip_mm = monthlyPrecip_mm;
-        }
+    public int getZoom() {
+      return this.zoom;
+    }
 
-        public String getStationId() {
-            return this.stationId;
-        }
 
-        public String getStationName() {
-            return this.stationName;
-        }
+    public ArrayList<ClimateStation> getClimateStationsList() {
+      return this.climateStationsList;
+    }
 
-        public double getStationLatitude() {
-            return this.latitude;
-        }
 
-        public double getStationLongitude() {
-            return this.longitude;
-        }
+    public void addClimateStationsList(ArrayList<ClimateStation> list) {
+      this.climateStationsList = list;
+    }
 
-        public int getYearRecorded() {
-            return this.yearRecorded;
-        }
+  }
 
-        public int getElevation() {
-            return this.elevation_ft;
-        }
+  static class ClimateStation {
 
-        public double getAvgYearlyPrecip() {
-            return this.avgYearlyPrecip_mm;
-        }
+    protected String stationId;
+    protected String stationName;
+    protected double latitude;
+    protected double longitude;
+    protected int yearRecorded;
+    protected int elevation_ft;
+    protected double avgYearlyPrecip_mm;
+    protected double[] monthlyPrecip_mm;
 
-        public double[] getMonthlyPrecip() {
-            return this.monthlyPrecip_mm;
-        }
 
+    public ClimateStation(String stationId, String stationName, double latitude,
+        double longitude, int yearRecorded, int elevation,
+        double avg_yearly_precip_mm, double[] monthlyPrecip_mm) {
+
+      this.stationId = stationId;
+      this.stationName = stationName;
+      this.latitude = latitude;
+      this.longitude = longitude;
+      this.yearRecorded = yearRecorded;
+      this.elevation_ft = elevation;
+      this.avgYearlyPrecip_mm = avg_yearly_precip_mm;
+      this.monthlyPrecip_mm = monthlyPrecip_mm;
     }
+
+
+    public String getStationId() {
+      return this.stationId;
+    }
+
+
+    public String getStationName() {
+      return this.stationName;
+    }
+
+
+    public double getStationLatitude() {
+      return this.latitude;
+    }
+
+
+    public double getStationLongitude() {
+      return this.longitude;
+    }
+
+
+    public int getYearRecorded() {
+      return this.yearRecorded;
+    }
+
+
+    public int getElevation() {
+      return this.elevation_ft;
+    }
+
+
+    public double getAvgYearlyPrecip() {
+      return this.avgYearlyPrecip_mm;
+    }
+
+
+    public double[] getMonthlyPrecip() {
+      return this.monthlyPrecip_mm;
+    }
+
+  }
 }

src/java/m/rhem/rhem06_riskassessment/V1_0.java

@@ -91,7 +91,7 @@
 
 
   private void generateRARunFile() throws ServiceException {
-    try (PrintWriter writer = new PrintWriter(getWorkspaceFile("risk_assessment.run"))) {
+    try (PrintWriter writer = new PrintWriter(workspace().getFile("risk_assessment.run"))) {
       writer.println(baseLineScenarioFileName);
       for (String fileName : raScenarioFilenameList) {
         writer.println(fileName);
@@ -104,7 +104,7 @@
 
   private void runRiskAssessment() throws ServiceException, IOException {
     Executable rh = resources().getExe(RHEM_RA_EXE);
-    rh.setArguments("-b", getWorkspaceFile("risk_assessment.run").toPath());
+    rh.setArguments("-b", workspace().getFile("risk_assessment.run").toPath());
     int run = rh.exec();
     if (run != 0) {
       throw new ServiceException("Problem in running risk assessment.");
@@ -117,10 +117,9 @@
     int count = -1;
     boolean check = false;
     try {
-      FileReader fileReader = new FileReader(getWorkspaceFile("risk_assessment.OUT"));
+      FileReader fileReader = new FileReader(workspace().getFile("risk_assessment.OUT"));
       try (BufferedReader bufferedReader = new BufferedReader(fileReader)) {
         String line;
-
         while ((line = bufferedReader.readLine()) != null && !check) {
           if (line.contains("FREQUENCY ANALYSIS")) {
             check = true;

src/java/m/rhem/rhem07_editparfile/V1_0.java

@@ -48,7 +48,7 @@
 @Resource(from = RhemResources.class)
 public class V1_0 extends ModelDataService {
 
-  private String cligen_db = Config.getString("rhem.cligen_db", "file:/Users/rumpal/Documents/Work/csipDocuments/RHEM/cligen");
+  private String cligen_db = Config.getString("rhem.cligen.db", "file:/Users/rumpal/Documents/Work/csipDocuments/RHEM/cligen");
 
   private String parameterFileName;
   private String stormFileName;
@@ -104,10 +104,6 @@
   @Override
   public void doProcess() throws Exception {
 
-    SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd, YYYY, hh:mm a");
-    Date now = new Date();
-    String today = sdf.format(now);
-
     String fileName = scenarioName;
     if (scenarioName.length() > 15) {
       fileName = scenarioName.substring(0, 15);
@@ -118,7 +114,7 @@
     detailedOutputFileName = "scenario_output_summary_" + fileName + ".out";
     runFileName = fileName + ".run";
 
-    RhemModel rhemModel = new RhemModel(scenarioName, today, workspace().getDir(), parameterFileName,
+    RhemModel rhemModel = new RhemModel(scenarioName, workspace().getDir(), parameterFileName,
         stormFileName, runFileName, summaryFileName);
 
     rhemModel.generateParamFile(parameter);