Browse Source

修改平均值计算

xiewenjie 3 years ago
parent
commit
b90258668e

+ 11 - 9
sxz-application/src/main/java/com.fdkk.sxz/main.java

@@ -191,15 +191,17 @@ public class main {
         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);
+        Map<String, Map<String, Double>> avg = new HashMap<>();
+        if (subgroup.size() == 1) {
+            for (String s : subgroup.keySet()) {
+                List<JSONObject> jsonObjects = subgroup.get(s);
+                Map<String, Double> avgMath = new HashMap<>();
+                double puckTotal = jsonObjects.stream().collect(Collectors.averagingDouble(item -> item.getJSONObject("puck").getDouble("z")));
+                double translationTotal = 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));

+ 10 - 8
sxz-base/src/main/java/com/fdkk/sxz/util/ConvertCadKjl.java

@@ -525,14 +525,16 @@ public class ConvertCadKjl {
                         Collectors.groupingBy(x -> x.getString("subgroup"))).entrySet().stream()
                 .collect(Collectors.toMap(e -> "floor" + e.getKey(), Map.Entry::getValue));
         Map<String, Map<String, Double>> avg = new HashMap<>();
-        for (String s : subgroup.keySet()) {
-            List<JSONObject> jsonObjects = subgroup.get(s);
-            Map<String, Double> avgMath = new HashMap<>();
-            double puckTotal = jsonObjects.stream().collect(Collectors.averagingDouble(item -> item.getJSONObject("puck").getDouble("z")));
-            double translationTotal = 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);
+        if (subgroup.size() == 1) {
+            for (String s : subgroup.keySet()) {
+                List<JSONObject> jsonObjects = subgroup.get(s);
+                Map<String, Double> avgMath = new HashMap<>();
+                double puckTotal = jsonObjects.stream().collect(Collectors.averagingDouble(item -> item.getJSONObject("puck").getDouble("z")));
+                double translationTotal = 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);
+            }
         }
 
         return avg;

+ 13 - 12
sxz-core/src/main/java/com/fdkk/sxz/webApi/controller/ImportDataController.java

@@ -870,20 +870,21 @@ public class ImportDataController extends BaseController {
     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++) {
-            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"));
+        if (avgMap.size() == 1) {
+            for (int i = 0, len = sweepLocations.size(); i < len; i++) {
+                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);
+            visionJson.put("sweepLocations", sweepLocations);
 
-        FileUtils.writeFile(visionPath, visionJson.toString());
+            FileUtils.writeFile(visionPath, visionJson.toString());
+        }
     }
 
     /**

+ 5 - 3
sxz-core/src/main/java/com/fdkk/sxz/webApi/controller/SceneController.java

@@ -1,6 +1,5 @@
 package com.fdkk.sxz.webApi.controller;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkk.sxz.annotation.auth.NoAuthentication;
 import com.fdkk.sxz.annotation.log.AroundLog;
@@ -17,7 +16,10 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.HashMap;
@@ -64,7 +66,7 @@ public class SceneController extends BaseController {
         Map<String, String> header = new HashMap<>();
         header.put("token", request.getHeader("token"));
 
-        return  OkHttpUtils.httpPostJson(mainUrl + "api/user/scene/list", data.toJSONString(), header);
+        return OkHttpUtils.httpPostJson(mainUrl + "api/decorate/scene/list", data.toJSONString(), header);
     }
 
     @RequestMapping(value = "/sendMsg", method = RequestMethod.GET)