فهرست منبع

故障诊断字段模糊

Gaokun Wang 2 ماه پیش
والد
کامیت
45da694eff

+ 10 - 4
als-modules/agile-assurance/src/main/java/org/eco/als/service/impl/AlgorithmService.java

@@ -110,7 +110,7 @@ public class AlgorithmService implements IAlgorithmService {
             throw new BusinessException("模型信息为空,请检查!");
         }
 
-        SysOssVo sysOssVo = getSysOssVo(algorithmBo);
+        SysOssVo sysOssVo = getSysOssVo(algorithmBo, null);
         if (sysOssVo == null) {
             return null;
         }
@@ -226,7 +226,7 @@ public class AlgorithmService implements IAlgorithmService {
         }
         list.forEach(modelVo -> {
             algorithmBo.setColumnData(modelVo.getColumnData().split(","));
-            SysOssVo sysOssVo = getSysOssVo(algorithmBo);
+            SysOssVo sysOssVo = getSysOssVo(algorithmBo, "5");
             if (sysOssVo == null) {
                 throw new BusinessException("架次数据为空,请检查!");
             }
@@ -320,15 +320,21 @@ public class AlgorithmService implements IAlgorithmService {
         return httpVo != null ? httpVo.getData() : null;
     }
 
-    private SysOssVo getSysOssVo(AlgorithmBo algorithmBo) {
+    private SysOssVo getSysOssVo(AlgorithmBo algorithmBo, String modelType) {
         SysOssVo sysOss = ossService.getById(algorithmBo.getOssId());
         if (ObjectUtil.isNull(sysOss)) {
             throw new BusinessException("文件数据不存在!");
         }
         String path = StringUtils.substringAfter(sysOss.getFileName(), Constants.RESOURCE_PREFIX);
         String tempPathCsv = EcoConfig.getTempPath() + "/" + CsvUtils.getName(FileUtils.getNameNotSuffix(sysOss.getOriginalName()));
+        JSONArray jsonArray;
+        if (StrUtil.equals(modelType, "5")) {
 
-        JSONArray jsonArray = CsvUtils.getCsvDataByHeaders(path, Arrays.asList(algorithmBo.getColumnData()), null);
+            jsonArray = CsvUtils.getCsvDataByColumn(path, Arrays.asList(algorithmBo.getColumnData()), null);
+        } else {
+            jsonArray = CsvUtils.getCsvDataByHeaders(path, Arrays.asList(algorithmBo.getColumnData()), null);
+
+        }
         if (CollUtil.isEmpty(jsonArray)) {
             throw new BusinessException("获取参数列为空。");
         }

+ 56 - 0
als-modules/agile-assurance/src/main/java/org/eco/als/utils/CsvUtils.java

@@ -30,6 +30,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 /**
  * @Description: CsvUtils
@@ -247,6 +248,61 @@ public class CsvUtils {
         return jsonArray;
     }
 
+    /**
+     * 根据头名称(参数名称)获取csv文件中参数数据
+     *
+     * @param csvFilePath csv文件地址
+     * @param headerNames 参数名称
+     * @return 参数名称列表
+     */
+    public static JSONArray getCsvDataByColumn(String csvFilePath, List<String> headerNames, Integer step) {
+        log.info("参数列:{}", headerNames);
+        List<CsvRow> rows = getCsvRowList(EcoConfig.getProfile() + csvFilePath);
+        // 获取CSV表头,即第一行数据
+        List<String> headers = rows.get(0).getRawList();
+        log.info("getCsvDataByColumn CSV表头:{}", headers.toString());
+        List<Integer> indexList = IntStream.range(0, headers.size())
+            .filter(i -> headerNames.stream()
+                .anyMatch(name -> StrUtil.containsIgnoreCase(headers.get(i), name)))
+            .boxed()
+            .collect(Collectors.toList());
+//        headerNames.forEach(name -> {
+//            int index = headers.indexOf(name);
+//            if (index != -1) {
+//                log.info("匹配到的表头:{},索引为:{}", name, index);
+//                indexList.add(index);
+//            }
+//        });
+//        for (int i = 0; i < headers.size(); i++ ) {
+//            if (StrUtil.containsAny(headers.get(i), headerNames.toArray(new String[0]))) {
+//                log.info("匹配到的表头:{},索引为:{}", headers.get(i), i);
+//                indexList.add(i);
+//            }
+//        };
+
+        if (CollectionUtil.isEmpty(indexList)) {
+            throw new BusinessException("参数列匹配为空!");
+        }
+        // 去除第一行,保留后续数据
+        List<CsvRow> dataLines = rows.subList(1, rows.size());
+        JSONArray jsonArray = new JSONArray();
+        for (CsvRow line : dataLines) {
+            JSONObject jsonObject = new JSONObject();
+            for (int i = 0; i < headers.size(); i++) {
+                // 参数索引位置
+                if (indexList.contains(i)) {
+                    jsonObject.putOnce(headers.get(i), line.getRawList().get(i));
+                }
+            }
+            jsonArray.add(jsonObject);
+        }
+        if (step != null) {
+            jsonArray = reduceFrameRate(jsonArray, 10, step);
+        }
+        log.info("处理后数据:{}", jsonArray.size());
+        return jsonArray;
+    }
+
     public static JSONObject getPlaybackByHeaders(String csvFilePath, List<String> headerNames, Integer step) {
         log.info("getPlaybackByHeaders 参数列:{}", headerNames);
         List<CsvRow> rows = getCsvRowList(EcoConfig.getProfile() + csvFilePath);