| | |
| | | JSONObject jsonObject = new JSONObject(templetStr); |
| | | JSONArray jsonArray = jsonObject.getJSONArray("cells"); |
| | | |
| | | this.getPetsInfo(); |
| | | JSONObject jsonObject3 = new JSONObject(templetStr); |
| | | JSONArray jsonArray3 = jsonObject3.getJSONArray("cells"); |
| | | |
| | | String modelStr2 = this.getPetsInfo(); |
| | | double x1 = 0; |
| | | double x2 = 0; |
| | | int y = -10; |
| | |
| | | jsonArray.add(lineJson); |
| | | } |
| | | lineArray.add(statusDtoList); |
| | | |
| | | JSONObject textJson = new JSONObject(templetsStrMap.get("text")); |
| | | JsonUtils2.setJsonValueByPath(textJson, "id".split("/"), UUIDUtil.generateId().toString()); |
| | | JsonUtils2.setJsonValueByPath(textJson, "attrs/label/textWrap/text".split("/"), dto.getName()); |
| | | JsonUtils2.setJsonValueByPath(textJson, "position/x".split("/"), 20); |
| | | JsonUtils2.setJsonValueByPath(textJson, "position/y".split("/"), y - 15); |
| | | jsonArray.add(textJson); |
| | | jsonArray3.add(textJson); |
| | | } |
| | | |
| | | //阶段模型及刻度 |
| | |
| | | } |
| | | parentStatusDtoList.add(new TimeDiagramStatusDto(x1, x2, lastStatus)); |
| | | |
| | | JSONObject jsonObject2 = new JSONObject(templetStr); |
| | | JSONObject jsonObject2 = new JSONObject(modelStr2); |
| | | JSONArray jsonArray2 = jsonObject2.getJSONArray("cells"); |
| | | List<List<TimeDiagramStatusDto>> smallStatusDtoList = new ArrayList<>(); |
| | | smallStatusDtoList.add(parentStatusDtoList); |
| | |
| | | for (int i = 0; i < smallStatusDtoList.size(); i++) { |
| | | for (TimeDiagramStatusDto status : smallStatusDtoList.get(i)) { |
| | | JSONObject lineJson = new JSONObject(templetsStrMap2.get(status.getStatus())); |
| | | setlineXy(lineJson, status.getX1(), y, status.getX2()+5, y, ""); |
| | | setlineXy(lineJson, status.getX1(), y, status.getX2() + 5, y, ""); |
| | | JsonUtils2.setJsonValueByPath(lineJson, "data/status".split("/"), status.getStatus()); |
| | | JsonUtils2.setJsonValueByPath(lineJson, "id".split("/"), UUIDUtil.generateId().toString()); |
| | | jsonArray2.add(lineJson); |
| | | } |
| | | y = y + 10; |
| | | y = y + 25; |
| | | } |
| | | |
| | | //图例 |
| | | int spaceWitdth = 80; |
| | | x1 = 0; |
| | | x2 = spaceWitdth - 11; |
| | | y = 60; |
| | | String[] tlArr = "O,F,I,S,M".split(","); |
| | | for (String s : tlArr) { |
| | | JSONObject f = templetsMap.get(s); |
| | | x1 = x1 + spaceWitdth; |
| | | x2 = x2 + spaceWitdth; |
| | | setlineXy(f, x1, y+10, x2, y+10, null); |
| | | setlineXy(f, x1, y, x2, y, null); |
| | | jsonArray2.add(f); |
| | | } |
| | | timeDiagramDto.setDiagramJson(jsonObject.toString()); |
| | | timeDiagramDto.setSmallDiagramJson(jsonObject2.toString()); |
| | | timeDiagramDto.setTextDiagramJson(jsonObject3.toString()); |
| | | |
| | | return timeDiagramDto; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public void getPetsInfo() { |
| | | public String getPetsInfo() { |
| | | Map<String, Object> params = new HashMap<String, Object>(); |
| | | params.put("projectId", 10000); |
| | | params.put("diagramId", 10000); |
| | | String modelStr2 = ""; |
| | | List<TimeDiagram> list_style = baseDao.getTimeDiagram(params); |
| | | if (list_style.size() > 0) { |
| | | modelStr2 = list_style.get(0).getContent2(); |
| | | String modelStr = list_style.get(0).getContent(); |
| | | JSONObject modelJson = new JSONObject(modelStr); |
| | | JSONArray modelJsonArray = modelJson.getJSONArray("cells"); |
| | |
| | | } |
| | | } |
| | | } |
| | | return modelStr2; |
| | | } |
| | | |
| | | public List<ProductStatusDto> getStatusData(Long productId, Long taskId) { |
| | |
| | | List<TaskModelCheckResultDto> chkResult = taskService.checkTaskModel(simulatAssess.getProductId(), |
| | | simulatAssess.getTaskModelId()); |
| | | if (chkResult.size() > 0) { |
| | | result = Result.error("模型不完整,请检查模型定义及参数配置。"); |
| | | result = Result.ok(chkResult); |
| | | return result; |
| | | } |
| | | |
| | |
| | | InputStream is = null; |
| | | BufferedReader br = null; |
| | | try { |
| | | setParamToRedis(simulatAssess); |
| | | try { |
| | | setParamToRedis(simulatAssess); |
| | | } catch (Exception e) { |
| | | throw new RenException("访问Redis失败。请检查Redis是否已启动。"); |
| | | } |
| | | |
| | | Process process = null; |
| | | String command = "python " + reliaSimMain; |
| | |
| | | } else if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1) { |
| | | process = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", command}); |
| | | } else { |
| | | throw new Exception("暂不支持该操作系统,进行启动算法库计算!"); |
| | | throw new RenException("暂不支持该操作系统,进行启动算法库计算!"); |
| | | } |
| | | is = process.getInputStream(); |
| | | // 以命令行方式调用算法库时,接口约定返回的结果是utf-8编码 |
| | |
| | | if (line != null) { |
| | | ReliaSimLibResult rtn = com.alibaba.fastjson.JSONObject.parseObject(line, ReliaSimLibResult.class); |
| | | if ("0".equals(rtn.getCode())) { |
| | | logger.info("启动算法库成功。"); |
| | | logger.info("启动可靠性仿真评估算法库成功。"); |
| | | result = Result.ok(); |
| | | } else { |
| | | String errorMsg = rtn.getErrorMsg(); |
| | | throw new RuntimeException("启动算法库失败: errorMsg=" + errorMsg); |
| | | throw new RenException("启动可靠性仿真评估算法库失败: errorMsg=" + errorMsg); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("启动算法库仿真时发生Exception:", e); |
| | | } catch (IOException e) { |
| | | logger.error("启动可靠性仿真评估算法库仿真时发生Exception:", e); |
| | | e.printStackTrace(); |
| | | result = Result.error(e.getMessage()); |
| | | throw new RenException("启动可靠性仿真评估算法库失败: errorMsg=" + e.getMessage()); |
| | | } finally { |
| | | if (is != null) { |
| | | try { |
| | |
| | | insert(simulatAssess); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("组装算法库仿真计算用模型XML失败: " + e.getMessage()); |
| | | throw new RenException("组装算法库仿真计算用模型XML失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | failureModels, repairModels); |
| | | } else if ("5".equals(product.getProductType())) { |
| | | // 设备 |
| | | Integer deviceNo = node.getDeviceNo(); |
| | | Element nodeTag = parent.addElement("node"); |
| | | nodeTag.addAttribute("name", dataId.toString()); |
| | | nodeTag.addAttribute("real_name", product.getName()); |
| | | nodeTag.addAttribute("name", deviceNo == 0 ? dataId.toString() : dataId.toString()+"-"+deviceNo); |
| | | nodeTag.addAttribute("real_name", deviceNo == 0 ? product.getName() : product.getName()+"-"+deviceNo); |
| | | nodeTag.addAttribute("name_path", product.getNamePath()); |
| | | nodeTag.addAttribute("type", "node"); |
| | | |
| | |
| | | element.addAttribute("k", algo.getVoteNum().toString()); |
| | | } else if ("switch".equals(algo.getAlgorithmType())) { |
| | | element.addAttribute("type", "standby"); |
| | | element.addAttribute("k", algo.getVoteNum().toString()); |
| | | } else if ("bridge".equals(algo.getAlgorithmType())) { |
| | | element.addAttribute("type", "bridge"); |
| | | } |
| | |
| | | break; |
| | | case 3: |
| | | // 二项分布 |
| | | if (taskBinoParam.getSimulatTimes().intValue() == taskBinoParam.getSuccessTimes().intValue()) { |
| | | if ((taskBinoParam.getSimulatTimes() == null && taskBinoParam.getSuccessTimes() == null) || |
| | | (taskBinoParam.getSimulatTimes().intValue() == taskBinoParam.getSuccessTimes().intValue())) { |
| | | // 相等则为成败型 |
| | | failureModel.setType(FailureModel.TYPE_FIX); |
| | | failureModel.setParam1(taskBinoParam.getSuccessRate()); |