Browse Source

修改按楼层按照楼层计算平均数,增加新建场景时设置修改时间等问题

xiewenjie 3 năm trước cách đây
mục cha
commit
0708108918

+ 196 - 184
sxz-application/src/main/java/com.fdkk.sxz/main.java

@@ -1,196 +1,208 @@
 package com.fdkk.sxz;
 
 
-import cn.hutool.core.util.URLUtil;
-import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkk.sxz.util.FileUtils;
 
-import java.net.URISyntaxException;
-import java.util.concurrent.ExecutionException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 public class main {
-    //public static void main(String[] args) {
-    //    String json = "{\n" +
-    //            "    \"sweepLocations\": [\n" +
-    //            "        {\n" +
-    //            "            \"subgroup\": 0,\n" +
-    //            "            \"pose\": {\n" +
-    //            "                \"rotation\": {\n" +
-    //            "                    \"w\": 0.95928264,\n" +
-    //            "                    \"x\": -0.0017092235,\n" +
-    //            "                    \"y\": -0.0016763769,\n" +
-    //            "                    \"z\": -0.28243768\n" +
-    //            "                },\n" +
-    //            "                \"translation\": {\n" +
-    //            "                    \"x\": 3.6112025,\n" +
-    //            "                    \"y\": 0.12166519,\n" +
-    //            "                    \"z\": 0.07516695\n" +
-    //            "                }\n" +
-    //            "            },\n" +
-    //            "            \"visibles3\": [\n" +
-    //            "                1,\n" +
-    //            "                2,\n" +
-    //            "                3\n" +
-    //            "            ],\n" +
-    //            "            \"visibles2\": [\n" +
-    //            "                1,\n" +
-    //            "                2,\n" +
-    //            "                3\n" +
-    //            "            ],\n" +
-    //            "            \"puck\": {\n" +
-    //            "                \"x\": 3.6112025,\n" +
-    //            "                \"y\": 0.12166519,\n" +
-    //            "                \"z\": -1.39718955\n" +
-    //            "            },\n" +
-    //            "            \"uuid\": \"0\",\n" +
-    //            "            \"visibles\": [\n" +
-    //            "                1,\n" +
-    //            "                2,\n" +
-    //            "                3\n" +
-    //            "            ],\n" +
-    //            "            \"group\": 1\n" +
-    //            "        },\n" +
-    //            "        {\n" +
-    //            "            \"subgroup\": 0,\n" +
-    //            "            \"pose\": {\n" +
-    //            "                \"rotation\": {\n" +
-    //            "                    \"w\": 0.97998166,\n" +
-    //            "                    \"x\": -0.00051350286,\n" +
-    //            "                    \"y\": -0.00007887775,\n" +
-    //            "                    \"z\": -0.19908713\n" +
-    //            "                },\n" +
-    //            "                \"translation\": {\n" +
-    //            "                    \"x\": 1.6813623,\n" +
-    //            "                    \"y\": 0.20879818,\n" +
-    //            "                    \"z\": 0.07516695\n" +
-    //            "                }\n" +
-    //            "            },\n" +
-    //            "            \"visibles3\": [\n" +
-    //            "                0,\n" +
-    //            "                2,\n" +
-    //            "                3\n" +
-    //            "            ],\n" +
-    //            "            \"visibles2\": [\n" +
-    //            "                0,\n" +
-    //            "                2,\n" +
-    //            "                3\n" +
-    //            "            ],\n" +
-    //            "            \"puck\": {\n" +
-    //            "                \"x\": 1.6813623,\n" +
-    //            "                \"y\": 0.20879818,\n" +
-    //            "                \"z\": -1.39718955\n" +
-    //            "            },\n" +
-    //            "            \"uuid\": \"2\",\n" +
-    //            "            \"visibles\": [\n" +
-    //            "                0,\n" +
-    //            "                2,\n" +
-    //            "                3\n" +
-    //            "            ],\n" +
-    //            "            \"group\": 1\n" +
-    //            "        },\n" +
-    //            "        {\n" +
-    //            "            \"subgroup\": 0,\n" +
-    //            "            \"pose\": {\n" +
-    //            "                \"rotation\": {\n" +
-    //            "                    \"w\": 0.7688388,\n" +
-    //            "                    \"x\": -0.0022818057,\n" +
-    //            "                    \"y\": 0.0016657045,\n" +
-    //            "                    \"z\": -0.6394364\n" +
-    //            "                },\n" +
-    //            "                \"translation\": {\n" +
-    //            "                    \"x\": -1.0941758,\n" +
-    //            "                    \"y\": -0.15828772,\n" +
-    //            "                    \"z\": 0.07516695\n" +
-    //            "                }\n" +
-    //            "            },\n" +
-    //            "            \"visibles3\": [\n" +
-    //            "                0,\n" +
-    //            "                1,\n" +
-    //            "                3\n" +
-    //            "            ],\n" +
-    //            "            \"visibles2\": [\n" +
-    //            "                0,\n" +
-    //            "                1,\n" +
-    //            "                3\n" +
-    //            "            ],\n" +
-    //            "            \"puck\": {\n" +
-    //            "                \"x\": -1.0941758,\n" +
-    //            "                \"y\": -0.15828772,\n" +
-    //            "                \"z\": -1.39718955\n" +
-    //            "            },\n" +
-    //            "            \"uuid\": \"4\",\n" +
-    //            "            \"visibles\": [\n" +
-    //            "                0,\n" +
-    //            "                1,\n" +
-    //            "                3\n" +
-    //            "            ],\n" +
-    //            "            \"group\": 1\n" +
-    //            "        },\n" +
-    //            "        {\n" +
-    //            "            \"subgroup\": 1,\n" +
-    //            "            \"pose\": {\n" +
-    //            "                \"rotation\": {\n" +
-    //            "                    \"w\": 0.75378096,\n" +
-    //            "                    \"x\": -0.00085483055,\n" +
-    //            "                    \"y\": 0.0011985971,\n" +
-    //            "                    \"z\": -0.6571241\n" +
-    //            "                },\n" +
-    //            "                \"translation\": {\n" +
-    //            "                    \"x\": -4.213454,\n" +
-    //            "                    \"y\": -0.17369196,\n" +
-    //            "                    \"z\": 0.07516695\n" +
-    //            "                }\n" +
-    //            "            },\n" +
-    //            "            \"visibles3\": [\n" +
-    //            "                0,\n" +
-    //            "                1,\n" +
-    //            "                2\n" +
-    //            "            ],\n" +
-    //            "            \"visibles2\": [\n" +
-    //            "                0,\n" +
-    //            "                1,\n" +
-    //            "                2\n" +
-    //            "            ],\n" +
-    //            "            \"puck\": {\n" +
-    //            "                \"x\": -4.213454,\n" +
-    //            "                \"y\": -0.17369196,\n" +
-    //            "                \"z\": -1.39718955\n" +
-    //            "            },\n" +
-    //            "            \"uuid\": \"6\",\n" +
-    //            "            \"visibles\": [\n" +
-    //            "                0,\n" +
-    //            "                1,\n" +
-    //            "                2\n" +
-    //            "            ],\n" +
-    //            "            \"group\": 1\n" +
-    //            "        }\n" +
-    //            "    ]\n" +
-    //            "}";
-    //    JSONObject visionJson = JSON.parseObject(json);
-    //    JSONArray sweepArray = visionJson.getJSONArray("sweepLocations");
-    //    List<JSONObject> roamingPoint = new ArrayList();
-    //    for (int i = 0; i < sweepArray.size(); i++) {
-    //        JSONObject objectJson = sweepArray.getJSONObject(i);
-    //        JSONObject newJson = new JSONObject();
-    //        newJson.put("uuid", objectJson.getString("uuid"));
-    //        JSONObject puck = objectJson.getJSONObject("puck");
-    //        puck.put("y", puck.getDoubleValue("y") * -1);
-    //        puck.remove("z");
-    //        newJson.put("puck", puck);
-    //        newJson.put("subgroup", objectJson.getInteger("subgroup"));
-    //        roamingPoint.add(newJson);
-    //    }
-    //    Map<String, List<JSONObject>> subgroup = roamingPoint.stream().collect(
-    //                    Collectors.groupingBy(x -> x.getString("subgroup"))).entrySet().stream()
-    //            .collect(Collectors.toMap(e -> "floor" + e.getKey(), Map.Entry::getValue));
-    //
-    //    System.out.println(JSON.toJSONString(subgroup));
-    //}
+    public static void main(String[] args) throws IOException {
+        String json = "{\n" +
+                "    \"sweepLocations\": [\n" +
+                "        {\n" +
+                "            \"subgroup\": 0,\n" +
+                "            \"pose\": {\n" +
+                "                \"rotation\": {\n" +
+                "                    \"w\": 0.95928264,\n" +
+                "                    \"x\": -0.0017092235,\n" +
+                "                    \"y\": -0.0016763769,\n" +
+                "                    \"z\": -0.28243768\n" +
+                "                },\n" +
+                "                \"translation\": {\n" +
+                "                    \"x\": 3.6112025,\n" +
+                "                    \"y\": 0.12166519,\n" +
+                "                    \"z\": 1\n" +
+                "                }\n" +
+                "            },\n" +
+                "            \"visibles3\": [\n" +
+                "                1,\n" +
+                "                2,\n" +
+                "                3\n" +
+                "            ],\n" +
+                "            \"visibles2\": [\n" +
+                "                1,\n" +
+                "                2,\n" +
+                "                3\n" +
+                "            ],\n" +
+                "            \"puck\": {\n" +
+                "                \"x\": 3.6112025,\n" +
+                "                \"y\": 0.12166519,\n" +
+                "                \"z\": -1.39718955\n" +
+                "            },\n" +
+                "            \"uuid\": \"0\",\n" +
+                "            \"visibles\": [\n" +
+                "                1,\n" +
+                "                2,\n" +
+                "                3\n" +
+                "            ],\n" +
+                "            \"group\": 1\n" +
+                "        },\n" +
+                "        {\n" +
+                "            \"subgroup\": 0,\n" +
+                "            \"pose\": {\n" +
+                "                \"rotation\": {\n" +
+                "                    \"w\": 0.97998166,\n" +
+                "                    \"x\": -0.00051350286,\n" +
+                "                    \"y\": -0.00007887775,\n" +
+                "                    \"z\": -0.19908713\n" +
+                "                },\n" +
+                "                \"translation\": {\n" +
+                "                    \"x\": 1.6813623,\n" +
+                "                    \"y\": 0.20879818,\n" +
+                "                    \"z\": 1\n" +
+                "                }\n" +
+                "            },\n" +
+                "            \"visibles3\": [\n" +
+                "                0,\n" +
+                "                2,\n" +
+                "                3\n" +
+                "            ],\n" +
+                "            \"visibles2\": [\n" +
+                "                0,\n" +
+                "                2,\n" +
+                "                3\n" +
+                "            ],\n" +
+                "            \"puck\": {\n" +
+                "                \"x\": 1.6813623,\n" +
+                "                \"y\": 0.20879818,\n" +
+                "                \"z\": -1.50\n" +
+                "            },\n" +
+                "            \"uuid\": \"2\",\n" +
+                "            \"visibles\": [\n" +
+                "                0,\n" +
+                "                2,\n" +
+                "                3\n" +
+                "            ],\n" +
+                "            \"group\": 1\n" +
+                "        },\n" +
+                "        {\n" +
+                "            \"subgroup\": 0,\n" +
+                "            \"pose\": {\n" +
+                "                \"rotation\": {\n" +
+                "                    \"w\": 0.7688388,\n" +
+                "                    \"x\": -0.0022818057,\n" +
+                "                    \"y\": 0.0016657045,\n" +
+                "                    \"z\": -0.6394364\n" +
+                "                },\n" +
+                "                \"translation\": {\n" +
+                "                    \"x\": -1.0941758,\n" +
+                "                    \"y\": -0.15828772,\n" +
+                "                    \"z\": 2\n" +
+                "                }\n" +
+                "            },\n" +
+                "            \"visibles3\": [\n" +
+                "                0,\n" +
+                "                1,\n" +
+                "                3\n" +
+                "            ],\n" +
+                "            \"visibles2\": [\n" +
+                "                0,\n" +
+                "                1,\n" +
+                "                3\n" +
+                "            ],\n" +
+                "            \"puck\": {\n" +
+                "                \"x\": -1.0941758,\n" +
+                "                \"y\": -0.15828772,\n" +
+                "                \"z\": -1.39718955\n" +
+                "            },\n" +
+                "            \"uuid\": \"4\",\n" +
+                "            \"visibles\": [\n" +
+                "                0,\n" +
+                "                1,\n" +
+                "                3\n" +
+                "            ],\n" +
+                "            \"group\": 1\n" +
+                "        },\n" +
+                "        {\n" +
+                "            \"subgroup\": 1,\n" +
+                "            \"pose\": {\n" +
+                "                \"rotation\": {\n" +
+                "                    \"w\": 0.75378096,\n" +
+                "                    \"x\": -0.00085483055,\n" +
+                "                    \"y\": 0.0011985971,\n" +
+                "                    \"z\": -0.6571241\n" +
+                "                },\n" +
+                "                \"translation\": {\n" +
+                "                    \"x\": -4.213454,\n" +
+                "                    \"y\": -0.17369196,\n" +
+                "                    \"z\": 0.07516695\n" +
+                "                }\n" +
+                "            },\n" +
+                "            \"visibles3\": [\n" +
+                "                0,\n" +
+                "                1,\n" +
+                "                2\n" +
+                "            ],\n" +
+                "            \"visibles2\": [\n" +
+                "                0,\n" +
+                "                1,\n" +
+                "                2\n" +
+                "            ],\n" +
+                "            \"puck\": {\n" +
+                "                \"x\": -4.213454,\n" +
+                "                \"y\": -0.17369196,\n" +
+                "                \"z\": -1.39718955\n" +
+                "            },\n" +
+                "            \"uuid\": \"6\",\n" +
+                "            \"visibles\": [\n" +
+                "                0,\n" +
+                "                1,\n" +
+                "                2\n" +
+                "            ],\n" +
+                "            \"group\": 1\n" +
+                "        }\n" +
+                "    ]\n" +
+                "}";
 
+        JSONObject visionJson = JSON.parseObject(json);
+        FileUtils.writeFile("D:\\test\\vision.txt", visionJson.toString());
 
-    public static void main(String[] args) throws URISyntaxException, ExecutionException, InterruptedException {
-        String url = URLUtil.normalize("http://192.168.0.26:8081/" + "change/fbxToObj/dataPush/" + "5901:;1460842946479132672:;226:;datasmith:;false:;1");
-        String result = HttpUtil.get(url);
 
+        JSONArray sweepArray = visionJson.getJSONArray("sweepLocations");
+        List<JSONObject> roamingPoint = new ArrayList();
+        for (int i = 0; i < sweepArray.size(); i++) {
+            JSONObject objectJson = sweepArray.getJSONObject(i);
+            JSONObject newJson = new JSONObject();
+            JSONObject puck = objectJson.getJSONObject("puck");
+            JSONObject pose = objectJson.getJSONObject("pose");
+            newJson.put("puck", puck);
+            newJson.put("pose", pose);
+            newJson.put("subgroup", objectJson.getInteger("subgroup"));
+            roamingPoint.add(newJson);
+        }
+        Map<String, List<JSONObject>> subgroup = roamingPoint.stream().collect(
+                        Collectors.groupingBy(x -> x.getString("subgroup"))).entrySet().stream()
+                .collect(Collectors.toMap(e -> "floor" + e.getKey(), Map.Entry::getValue));
+        Map<String, Map<String, Object>> avg = new HashMap<>();
+        for (String s : subgroup.keySet()) {
+            List<JSONObject> jsonObjects = subgroup.get(s);
+            Map<String, Object> avgMath = new HashMap<>();
+            double translationTotal = jsonObjects.stream().collect(Collectors.averagingDouble(item -> item.getJSONObject("puck").getDouble("z")));
+            double puckTotal = jsonObjects.stream().collect(Collectors.averagingDouble(item -> item.getJSONObject("pose").getJSONObject("translation").getDouble("z")));
+            avgMath.put("translationTotalAvg", translationTotal);
+            avgMath.put("puckTotalAvg", puckTotal);
+            avg.put(s, avgMath);
+        }
+
+        System.out.println(JSON.toJSONString(subgroup));
     }
 
 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 562 - 553
sxz-base/src/main/java/com/fdkk/sxz/util/ConvertCadKjl.java


+ 20 - 18
sxz-core/src/main/java/com/fdkk/sxz/webApi/controller/ImportDataController.java

@@ -38,10 +38,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.io.File;
 import java.math.BigDecimal;
 import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
@@ -153,6 +150,7 @@ public class ImportDataController extends BaseController {
                 sceneStyleEntity.setSceneNum(sceneNum);
                 sceneStyleEntity.setStyleName(styleName);
                 sceneStyleEntity.setStyleNum(vrNum);
+                sceneStyleEntity.setUpdateTime(new Date());
                 //新生成的换装风格,未渲染
                 sceneStyleEntity.setStatus(2);
                 sceneStyleService.save(sceneStyleEntity);
@@ -216,8 +214,8 @@ public class ImportDataController extends BaseController {
                     "data/data" + sceneNum + "/roamingPoint.json");
 
             //计算translationAverage,和puckAverage并重新赋予值
-            Map<String, Double> averageMap = ConvertCadKjl.getAverageValue(filePath + "vision.txt");
-            ImportDataController.setAverageValue(filePath + "vision.txt", averageMap.get("translationAverage"), averageMap.get("puckAverage"));
+            Map<String, Map<String, Double>> averageMap = ConvertCadKjl.getAverageValue(filePath + "vision.txt");
+            ImportDataController.setAverageValue(filePath + "vision.txt", averageMap);
 
             FileUtils.writeFile(filePath + "proLight.json", proLight);
 
@@ -868,19 +866,23 @@ public class ImportDataController extends BaseController {
         }
     }
 
-    public static void setAverageValue(String visionPath, Double translationAverage, Double puckAverage) throws Exception {
-        Map<String, Double> map = new HashMap<>();
+    public static void setAverageValue(String visionPath, Map<String, Map<String, Double>> avgMap) throws Exception {
         JSONObject visionJson = JSONObject.parseObject(FileUtils.readFile(visionPath));
         JSONArray sweepLocations = visionJson.getJSONArray("sweepLocations");
 
         for (int i = 0, len = sweepLocations.size(); i < len; i++) {
-            sweepLocations.getJSONObject(i).getJSONObject("pose").
-                    getJSONObject("translation").put("z", translationAverage);
-            sweepLocations.getJSONObject(i).getJSONObject("puck").put("z", puckAverage);
+            int subgroup = sweepLocations.getJSONObject(i).getInteger("subgroup");
+            Map<String, Double> subgroupMap = avgMap.get("floor" + subgroup);
+            if (subgroupMap != null) {
+                sweepLocations.
+                        getJSONObject(i).getJSONObject("pose").
+                        getJSONObject("translation").put("z", subgroupMap.get("translationTotalAvg"));
+                sweepLocations.getJSONObject(i).getJSONObject("puck").put("z", subgroupMap.get("puckTotalAvg"));
+            }
         }
         visionJson.put("sweepLocations", sweepLocations);
 
-        FileUtils.writeFile(visionPath, visionJson.toString());
+        FileUtils.writeFile("D:\\test\\vision1.txt", visionJson.toString());
     }
 
     /**
@@ -1344,12 +1346,12 @@ public class ImportDataController extends BaseController {
 
     public static void main(String[] args) {
         try {
-            Map<String, Double> map = ConvertCadKjl.getAverageValue("G:\\javaProject\\changeing\\vision.txt");
-
-            System.out.println(map.get("translationAverage"));
-            System.out.println(map.get("puckAverage"));
-
-            ImportDataController.setAverageValue("G:\\javaProject\\changeing\\vision.txt", map.get("translationAverage"), map.get("puckAverage"));
+            Map<String, Map<String, Double>> map = ConvertCadKjl.getAverageValue("D:\\test\\vision.txt");
+            //
+            //System.out.println(map.get("translationAverage"));
+            //System.out.println(map.get("puckAverage"));
+            //
+            ImportDataController.setAverageValue("D:\\test\\vision.txt", map);
 
 
         } catch (Exception e) {