@Test public void TestMinersRule() { String inputStr = null; try { inputStr = getFileAsString("src/test/resources/minersRuleIn.json"); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } byte[] model = null; try { model = getFileAsByteArray("src/test/resources/minersRuleModel.txt"); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } Map<String, byte[]> models = new HashMap<String, byte[]>(); models.put(MinersRule.STRESS_LIMITS_MODEL_NAME, model); MinersRule minersRule = new MinersRule(); String jsonOut = null; try { jsonOut = minersRule.computeCDM(inputStr, models); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } String expectedOut = null; try { expectedOut = getFileAsString("src/test/resources/minersRuleOut.json"); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } Assert.assertEquals(expectedOut, jsonOut); }
public String computeCDM(String jsonStr, Map<String, byte[]> inputModels) throws Exception { Input input = null; try { input = mapper.readValue(jsonStr, Input.class); } catch (Exception e) { throw new Exception("Trying to read the json input:"+jsonStr, e); } CDM_TimeSeries currentCDM = input.getCurrent_cdm(); StressesTimeSeries recentStresses = input.getRecentStresses(); if (inputModels == null || !inputModels.containsKey(STRESS_LIMITS_MODEL_NAME)) { throw new Exception(STRESS_LIMITS_MODEL_NAME+" model not found in the input model map"); } byte[] stressLimitsModel = inputModels.get(STRESS_LIMITS_MODEL_NAME); if (stressLimitsModel == null) { throw new Exception("Model is null."); } List<Double> lifeLimits = convertToDoubleList(stressLimitsModel); verifyInput(recentStresses, lifeLimits); computeMinersCDM(currentCDM, recentStresses, lifeLimits); Response output = new Response(); CDM_TimeSeries cdm_timeSeries = new CDM_TimeSeries(); cdm_timeSeries.setTime_stamp(currentCDM.getTime_stamp()); cdm_timeSeries.setCdm_values(currentCDM.getCdm_values()); output.setUpdatedCDM(cdm_timeSeries); return mapper.writeValueAsString(output); }
MinersRule { public String computeCDM(String jsonStr, Map<String, byte[]> inputModels) throws Exception { Input input = null; try { input = mapper.readValue(jsonStr, Input.class); } catch (Exception e) { throw new Exception("Trying to read the json input:"+jsonStr, e); } CDM_TimeSeries currentCDM = input.getCurrent_cdm(); StressesTimeSeries recentStresses = input.getRecentStresses(); if (inputModels == null || !inputModels.containsKey(STRESS_LIMITS_MODEL_NAME)) { throw new Exception(STRESS_LIMITS_MODEL_NAME+" model not found in the input model map"); } byte[] stressLimitsModel = inputModels.get(STRESS_LIMITS_MODEL_NAME); if (stressLimitsModel == null) { throw new Exception("Model is null."); } List<Double> lifeLimits = convertToDoubleList(stressLimitsModel); verifyInput(recentStresses, lifeLimits); computeMinersCDM(currentCDM, recentStresses, lifeLimits); Response output = new Response(); CDM_TimeSeries cdm_timeSeries = new CDM_TimeSeries(); cdm_timeSeries.setTime_stamp(currentCDM.getTime_stamp()); cdm_timeSeries.setCdm_values(currentCDM.getCdm_values()); output.setUpdatedCDM(cdm_timeSeries); return mapper.writeValueAsString(output); } }
MinersRule { public String computeCDM(String jsonStr, Map<String, byte[]> inputModels) throws Exception { Input input = null; try { input = mapper.readValue(jsonStr, Input.class); } catch (Exception e) { throw new Exception("Trying to read the json input:"+jsonStr, e); } CDM_TimeSeries currentCDM = input.getCurrent_cdm(); StressesTimeSeries recentStresses = input.getRecentStresses(); if (inputModels == null || !inputModels.containsKey(STRESS_LIMITS_MODEL_NAME)) { throw new Exception(STRESS_LIMITS_MODEL_NAME+" model not found in the input model map"); } byte[] stressLimitsModel = inputModels.get(STRESS_LIMITS_MODEL_NAME); if (stressLimitsModel == null) { throw new Exception("Model is null."); } List<Double> lifeLimits = convertToDoubleList(stressLimitsModel); verifyInput(recentStresses, lifeLimits); computeMinersCDM(currentCDM, recentStresses, lifeLimits); Response output = new Response(); CDM_TimeSeries cdm_timeSeries = new CDM_TimeSeries(); cdm_timeSeries.setTime_stamp(currentCDM.getTime_stamp()); cdm_timeSeries.setCdm_values(currentCDM.getCdm_values()); output.setUpdatedCDM(cdm_timeSeries); return mapper.writeValueAsString(output); }  }
MinersRule { public String computeCDM(String jsonStr, Map<String, byte[]> inputModels) throws Exception { Input input = null; try { input = mapper.readValue(jsonStr, Input.class); } catch (Exception e) { throw new Exception("Trying to read the json input:"+jsonStr, e); } CDM_TimeSeries currentCDM = input.getCurrent_cdm(); StressesTimeSeries recentStresses = input.getRecentStresses(); if (inputModels == null || !inputModels.containsKey(STRESS_LIMITS_MODEL_NAME)) { throw new Exception(STRESS_LIMITS_MODEL_NAME+" model not found in the input model map"); } byte[] stressLimitsModel = inputModels.get(STRESS_LIMITS_MODEL_NAME); if (stressLimitsModel == null) { throw new Exception("Model is null."); } List<Double> lifeLimits = convertToDoubleList(stressLimitsModel); verifyInput(recentStresses, lifeLimits); computeMinersCDM(currentCDM, recentStresses, lifeLimits); Response output = new Response(); CDM_TimeSeries cdm_timeSeries = new CDM_TimeSeries(); cdm_timeSeries.setTime_stamp(currentCDM.getTime_stamp()); cdm_timeSeries.setCdm_values(currentCDM.getCdm_values()); output.setUpdatedCDM(cdm_timeSeries); return mapper.writeValueAsString(output); }  String computeCDM(String jsonStr, Map<String, byte[]> inputModels); }
MinersRule { public String computeCDM(String jsonStr, Map<String, byte[]> inputModels) throws Exception { Input input = null; try { input = mapper.readValue(jsonStr, Input.class); } catch (Exception e) { throw new Exception("Trying to read the json input:"+jsonStr, e); } CDM_TimeSeries currentCDM = input.getCurrent_cdm(); StressesTimeSeries recentStresses = input.getRecentStresses(); if (inputModels == null || !inputModels.containsKey(STRESS_LIMITS_MODEL_NAME)) { throw new Exception(STRESS_LIMITS_MODEL_NAME+" model not found in the input model map"); } byte[] stressLimitsModel = inputModels.get(STRESS_LIMITS_MODEL_NAME); if (stressLimitsModel == null) { throw new Exception("Model is null."); } List<Double> lifeLimits = convertToDoubleList(stressLimitsModel); verifyInput(recentStresses, lifeLimits); computeMinersCDM(currentCDM, recentStresses, lifeLimits); Response output = new Response(); CDM_TimeSeries cdm_timeSeries = new CDM_TimeSeries(); cdm_timeSeries.setTime_stamp(currentCDM.getTime_stamp()); cdm_timeSeries.setCdm_values(currentCDM.getCdm_values()); output.setUpdatedCDM(cdm_timeSeries); return mapper.writeValueAsString(output); }  String computeCDM(String jsonStr, Map<String, byte[]> inputModels); static final String STRESS_LIMITS_MODEL_NAME; }