Переглянути джерело

Merge remote-tracking branch 'origin/master'

wangzhiqiang 2 роки тому
батько
коміт
b34aab0794

+ 7 - 14
api-common/src/main/java/api/common/pojo/vo/project/SubScListVo.java

@@ -7,24 +7,17 @@ import lombok.Setter;
 @Setter
 public class SubScListVo {
 
-    private String sublistName1;
 
+    private String sceneNum;
+    private String notScoredSceneNum;
+    private String notStandardSceneNum;
+    private String standardSceneNum;
+    private String lastScore;
+    private String firstScore;
+    private String sublistName1;
     private String sublistName2;
-
     private String sublistName3;
-
     private String sublistName4;
-
     private String sublistName5;
-
     private String sublistName6;
-
-    private String sceneNum;
-
-    private String notStandardSceneNum;
-
-    private String lastScore;
-
-    private String firstScore;
-
 }

+ 2 - 0
api-common/src/main/java/api/common/pojo/vo/project/SublistScoreVo.java

@@ -17,7 +17,9 @@ public class SublistScoreVo {
     private Double firScore;
     private Double lasScore;
     private String packageAndRules;
+    private String notScoredSceneNum;
     private String notStandardSceneNum;
+    private String standardSceneNum;
     private String scoreExplain;
     private Double sceneScore;
     private String targetEvaluate;

+ 25 - 4
api-common/src/main/java/api/common/util/PythonUtil.java

@@ -9,17 +9,38 @@ import java.util.UUID;
 @Slf4j
 public class PythonUtil {
 
+    /*
+        C:惯例,违反了编码风格标准
+        R:重构,代码非常糟糕
+        W:警告,某些 Python 特定的问题
+        E:错误,很可能是代码中的错误
+        F:致命错误,阻止 Pylint 进一步运行的错误
+     */
+
+    public static String LINE_TOO_LONG = "C0301";
+    public static String C = "C";
+    public static String R = "R";
+    public static String W = "W";
+    public static String E = "E";
+    public static String F = "F";
+    public static String PASS = "Your code has been rated at 10.00/10";
+
     /**
      * @param pythonCode python 代码
+     * @param disables   忽略指定等级的日志
      */
     @SneakyThrows
-    public static String pylint(String pythonCode) {
+    public static String pylint(String pythonCode, String... disables) {
         //1 把代码保存成本地文件
         String filePath = "/tmp/" + UUID.randomUUID().toString().replace("-", "") + ".py";
         FileUtil.writeStringToLocalFile(pythonCode, filePath);
         //2 执行命令检查格式
-        LinuxUtil.execute("apt install python-pip");
-        LinuxUtil.execute("pip3 install pylint");
-        return LinuxUtil.execute("pylint " + filePath);
+        StringBuilder command = new StringBuilder("pylint --disable=");
+        for (String disable : disables) {
+            command.append(disable).append(",");
+        }
+        command.append(" ").append(filePath);
+        return LinuxUtil.execute(command.toString());
     }
 }
+

+ 2 - 2
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/manager/TaskManager.java

@@ -236,7 +236,7 @@ public class TaskManager {
                         // 计算每个任务的得分
                         String result1OfMinio = taskOfLeaf.getRunResultFilePath() + "/Ego.csv";
                         String result1OfLinux = linuxTempPath + result1OfMinio;
-                        String result2OfMinio = taskOfLeaf.getRunResultFilePath() + "/combined_ogt.csv";
+                        String result2OfMinio = taskOfLeaf.getRunResultFilePath() + "/evaluation.csv";
                         String result2OfLinux = linuxTempPath + result2OfMinio;
                         String scoreCommand = "python3 " + pyPath + "main.py "
                                 + result1OfLinux + " "
@@ -259,7 +259,7 @@ public class TaskManager {
                             score = JsonUtil.jsonToBean(replace, ScoreTO.class);
                             FileUtil.rm(result1OfLinux);
                             FileUtil.rm(result2OfLinux);
-                            log.info("TaskService--state 已删除运行结果文件 Ego.csv 和 combined_ogt.csv。");
+                            log.info("TaskService--state 已删除运行结果文件 Ego.csv 和 evaluation.csv。");
                         } catch (IOException e) {
                             throw new RuntimeException("------- TaskService--state 项目" + projectId + "的任务" + task2Id + " 打分出错,命令为:" + scoreCommand + " 修改状态为:" + DictConstants.TASK_ABORTED + "\n" + e.getMessage());
                         }

+ 0 - 3
simulation-resource-server/src/main/java/com/css/simulation/resource/project/ctrl/SimulationProjectCtrl.java

@@ -176,8 +176,6 @@ public class SimulationProjectCtrl {
     /**
      * 查询工作任务列表
      *
-     * @param param
-     * @return
      */
     @RequestMapping("selectProjectTaskList")
     @ResponseBody
@@ -189,7 +187,6 @@ public class SimulationProjectCtrl {
     /**
      * 导出测试报告
      *
-     * @return
      */
     @RequestMapping("exportProjectReportById")
     @ResponseBody

+ 60 - 51
simulation-resource-server/src/main/java/com/css/simulation/resource/project/impl/SimulationProjectServiceImpl.java

@@ -727,7 +727,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         projectReportVo.setProjectName(poParam.getProjectName());
         projectReportVo.setAlgorithmName(algorithmBaseInfoVo.getAlgorithmName());
         projectReportVo.setAlgorithmDescribe(algorithmBaseInfoVo.getDescription());
-        String sceneNames = "";
+        String sceneNames;
 
         //算法测试得分表
         /*
@@ -747,34 +747,38 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         StringBuilder stringBuilder = new StringBuilder();
 
         //汇总数据初始化
-        Integer totalSceneNum = 0;
+        int totalSceneNum = 0;
         double totalScore = 0D;
         double totalScoreRatio = 0D;
-        Integer totalSceneScoreNum = 0;
+        int totalSceneScoreNum = 0;
 
-
-        for (SimulationMptFirstTargetScorePo v : pos) {
+        // 根据一级指标表结果获取平分细则
+        for (SimulationMptFirstTargetScorePo firstTargetScorePo : pos) {
             //获取指标信息
-            stringBuilder.append(v.getSublistName()).append("、");
-            AlgorithmScoreVo algorithmScoreVo = new AlgorithmScoreVo();
-            algorithmScoreVo.setProjectName(v.getSublistName());
-            Integer sceneNum = v.getSceneNum();
-            totalSceneNum += sceneNum;
-            algorithmScoreVo.setSceneNum(sceneNum);
-            String weight = v.getWeight();
+            int sceneNum = firstTargetScorePo.getSceneNum();    // 一级指标包含场景数量
+            String weight = firstTargetScorePo.getWeight();     // 一级指标权重
             double weightDouble = Double.parseDouble(weight);
-            algorithmScoreVo.setWeight(weight);
             //单个二级指标得分
-            Double score = v.getScore();
+            Double score = firstTargetScorePo.getScore();
             totalScore += BigDecimal.valueOf(score).multiply(BigDecimal.valueOf(weightDouble).divide(BigDecimal.valueOf(100))).doubleValue();
-            algorithmScoreVo.setScore(saveTwoDecimalPlaces(score));
-            //获取得分不为0的场景数量
-            Integer scoreNum = getSetScoreNum(v.getSublistId(), poParam.getId());
+            //获取得分不为 0 的场景数量
+            Integer scoreNum = getSetScoreNum(firstTargetScorePo.getSublistId(), poParam.getId());
             totalSceneScoreNum += scoreNum;
+
+            totalScoreRatio += Double.valueOf(scoreNum) / Double.valueOf(sceneNum) * 100;
+
+            AlgorithmScoreVo algorithmScoreVo = new AlgorithmScoreVo();
+            algorithmScoreVo.setProjectName(firstTargetScorePo.getSublistName());
+            algorithmScoreVo.setSceneNum(sceneNum);
+            algorithmScoreVo.setWeight(weight);
+            algorithmScoreVo.setScore(saveTwoDecimalPlaces(score));
             algorithmScoreVo.setScoreRatio(saveTwoDecimalPlaces(Double.valueOf(scoreNum) / Double.valueOf(sceneNum) * 100));
+
             algorithmScoreVoList.add(algorithmScoreVo);
 
-            totalScoreRatio += Double.valueOf(scoreNum) / Double.valueOf(sceneNum) * 100;
+            // 其他操作
+            stringBuilder.append(firstTargetScorePo.getSublistName()).append("、");
+            totalSceneNum += sceneNum;
         }
         // 汇总
         AlgorithmScoreVo algorithmScoreVo = new AlgorithmScoreVo();
@@ -1877,36 +1881,40 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         SimulationManualProjectParam query = new SimulationManualProjectParam();
         query.setId(projectId);
         query.setPackageId(scenePackageId);
-//        List<SublistScoreVo> pos = simulationProjectMapper.selectSubScore(query);
         List<SublistScoreVo> pos = simulationProjectMapper.selectSubScore2(query);
-
         HashMap<String, Object> hashMap = new HashMap<>();
-
         int size = 0;
         List<List<String>> result = new ArrayList<>();
         //递归指标名称得分
         for (SublistScoreVo po : pos) {
-//            if(ObjectUtil.isNotNull(po.getPackageAndRules())){
             if (ObjectUtil.isNotNull(po.getPackageAndRules()) && (po.getFirTarget() != null || po.getLasTarget() != null)) {
                 //末级指标
                 setParent(po, null, pos, scenePackageId);
 
                 String sublistName = po.getSublistName();
                 Double firScore = po.getFirScore();
-                String firstScore = "";//first得分
+                String firstScore = ""; // first得分
                 if (firScore != null) {
                     firstScore = saveTwoDecimalPlaces(firScore, 1).toString();
                 }
                 Double lasScore = po.getLasScore();
-                String LastScore = "";//last得分
+                String LastScore = "";  // last得分
                 if (lasScore != null) {
                     LastScore = saveTwoDecimalPlaces(lasScore, 1).toString();
                 }
                 String sceneNum = po.getSceneNum();//场景数量
-                String notStandardSceneNum = po.getNotStandardSceneNum();//未达标场景数量
+                String notScoredSceneNum = po.getNotScoredSceneNum();       // 未参与评分数量
+                String notStandardSceneNum = po.getNotStandardSceneNum();   // 未达标场景数量
+                String standardSceneNum = po.getStandardSceneNum();         // 达标场景数量
 
                 if (ObjectUtil.isNotNull(sublistName)) {
-                    sublistName += ProjectConstants.SEPARATOR + sceneNum + ProjectConstants.SEPARATOR + notStandardSceneNum + ProjectConstants.SEPARATOR + LastScore + ProjectConstants.SEPARATOR + firstScore;
+                    sublistName += ProjectConstants.SEPARATOR
+                            + sceneNum + ProjectConstants.SEPARATOR
+                            + notScoredSceneNum + ProjectConstants.SEPARATOR
+                            + notStandardSceneNum + ProjectConstants.SEPARATOR
+                            + standardSceneNum + ProjectConstants.SEPARATOR
+                            + LastScore + ProjectConstants.SEPARATOR
+                            + firstScore;
                     String[] split = sublistName.split(ProjectConstants.SEPARATOR);
 
 
@@ -1944,10 +1952,12 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
                 }
 
             }
-            subScListVo.setSceneNum(list.get(start));
-            subScListVo.setNotStandardSceneNum(list.get(start + 1));
-            subScListVo.setLastScore(list.get(start + 2));
-            subScListVo.setFirstScore(list.get(start + 3));
+            subScListVo.setSceneNum(list.get(start + 0));
+            subScListVo.setNotScoredSceneNum(list.get(start + 1));
+            subScListVo.setNotStandardSceneNum(list.get(start + 2));
+            subScListVo.setStandardSceneNum(list.get(start + 3));
+            subScListVo.setLastScore(list.get(start + 4));
+            subScListVo.setFirstScore(list.get(start + 5));
 
             objects.add(subScListVo);
 
@@ -1959,7 +1969,9 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             addHeaders(i, headerList);
         }
         headerList.add(ImmutableMap.builder().put("label", "场景数量").put("prop", "sceneNum").build());
+        headerList.add(ImmutableMap.builder().put("label", "未参与评分场景个数").put("prop", "notScoredSceneNum").build());
         headerList.add(ImmutableMap.builder().put("label", "未达标场景数量").put("prop", "notStandardSceneNum").build());
+        headerList.add(ImmutableMap.builder().put("label", "达标场景个数").put("prop", "standardSceneNum").build());
         headerList.add(ImmutableMap.builder().put("label", "得分").put("prop", "lastScore").build());
         headerList.add(ImmutableMap.builder().put("label", "总分").put("prop", "firstScore").build());
         hashMap.put("headerList", headerList);
@@ -2244,7 +2256,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
     }
 
     /**
-     * 获取二级场景下所有得分不为0的场景数量
+     * 获取二级场景下所有得分不为 0 的场景数量
      *
      * @param sublistId
      * @param pId
@@ -2257,7 +2269,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
 
 
     /**
-     * 获取一级指标下所有得分不为0的场景总数
+     * 获取一级指标下所有得分不为 0 的场景总数
      *
      * @param resultVo     返回值,返回统计数量,首次传null
      * @param parentVoList 首次传null
@@ -2266,8 +2278,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
      * @param sublistId    指标id(用户查询指标下的所有场景)
      * @return
      */
-    private SceneScoreVo selectScoreNum(SceneScoreVo resultVo, List<ScenePackageSubListVO> parentVoList,
-                                        boolean isRoot, String pId, String sublistId) {
+    private SceneScoreVo selectScoreNum(SceneScoreVo resultVo, List<ScenePackageSubListVO> parentVoList, boolean isRoot, String pId, String sublistId) {
         if (isRoot) {
             //初始化返回值
             resultVo = new SceneScoreVo();
@@ -2496,23 +2507,21 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             }
             document.add(pdfPTable);
 
-            /*
-            评价等级
-             */
-            Paragraph levelTableElements = new Paragraph(
-                    50,
-                    "评价等级",
-                    defaultFont(font));
-            levelTableElements.setAlignment(Element.ALIGN_CENTER); //居中
-            document.add(levelTableElements);
-
-            setBlankLineSpacing(20, font, document);
-
-            PdfPTable pdfPTable1 = new PdfPTable(5);
-            addTitleList(pdfPTable1, font, new String[]{"测试项目", "90<总分<100", "80<总分<90", "70<总分<80", "0<总分<70"});
-            addDataList(pdfPTable1, font, new String[]{"评价等级", "优秀(G)", "良好(A)", "一般(M)", "较差(P)",
-                    "评价等级", "++++++", "+++++", "++++", "+++",});
-            document.add(pdfPTable1);
+            // 评价等级(已去掉)
+//            Paragraph levelTableElements = new Paragraph(
+//                    50,
+//                    "评价等级",
+//                    defaultFont(font));
+//            levelTableElements.setAlignment(Element.ALIGN_CENTER); //居中
+//            document.add(levelTableElements);
+//
+//            setBlankLineSpacing(20, font, document);
+//
+//            PdfPTable pdfPTable1 = new PdfPTable(5);
+//            addTitleList(pdfPTable1, font, new String[]{"测试项目", "90<总分<100", "80<总分<90", "70<总分<80", "0<总分<70"});
+//            addDataList(pdfPTable1, font, new String[]{"评价等级", "优秀(G)", "良好(A)", "一般(M)", "较差(P)",
+//                    "评价等级", "++++++", "+++++", "++++", "+++",});
+//            document.add(pdfPTable1);
 
 
             //新的一页,横向显示

+ 3 - 4
simulation-resource-server/src/main/java/com/css/simulation/resource/scene/ctrl/ScoringRulesController.java

@@ -7,7 +7,6 @@ import api.common.pojo.po.scene.ScoringRulesPO;
 import api.common.pojo.vo.scene.ScoringRulesVO;
 import api.common.util.ObjectUtil;
 import api.common.util.PythonUtil;
-import api.common.util.StringUtil;
 import com.css.simulation.resource.common.utils.PageUtil;
 import com.css.simulation.resource.scene.service.ScoringRulesService;
 import com.github.pagehelper.PageInfo;
@@ -89,9 +88,9 @@ public class ScoringRulesController {
             return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "规则名称ruleName已存在,请重新命名。");
         }
         //2 校验 python 语法错误
-        String pycodestyleResult = PythonUtil.pylint(scoringRulesPO.getRuleDetails());
-        if (StringUtil.isNotEmpty(pycodestyleResult)) {
-            return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, pycodestyleResult);
+        String pylint = PythonUtil.pylint(scoringRulesPO.getRuleDetails(), PythonUtil.C, PythonUtil.R, PythonUtil.W);
+        if (!pylint.contains(PythonUtil.PASS)) {
+            return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, pylint);
         }
 
         //3 保存

+ 2 - 0
simulation-resource-server/src/main/resources/mapper/project/SimulationProjectMapper.xml

@@ -571,7 +571,9 @@
                fir.score      as firScore,
                las.score      as lasScore,
                sub.package_and_rules,
+               las.not_scored_scene_num,
                las.not_standard_scene_num,
+               las.standard_scene_num,
                las.score_explain,
                fir.target     as firTarget,
                las.target     as lasTarget