Преглед на файлове

fix bugs in ai/video return data

张许妍 преди 3 години
родител
ревизия
62049be71f

+ 12 - 12
backend_refactor/service/ai/video/classify/jump.py

@@ -12,40 +12,40 @@ def classify_jump(re):
         ret = ret + "The movement process is terrible and needs to be improved. "
 
     if re["1"]["is_prepared"]:
-        if float(re["1"]["first_score"]) > 85:
+        if float(re["1"]["score"]) > 85:
             ret = ret + "Your upper and lower body movements are coordinated, and the setup position is perfect. "
-        elif float(re["1"]["first_score"]) > 75:
+        elif float(re["1"]["score"]) > 75:
             ret = ret + "Your upper and lower body movements are coordinated, but the setup position is not standard enough. "
-        elif float(re["1"]["first_score"]) > 65:
+        elif float(re["1"]["score"]) > 65:
             ret = ret + "The setup position is not standard enough. Take more practice."
         else:
             ret = ret + "The setup position is far from standard, see some relevant video to correct posture."
     else:
         ret = ret + "Lack the setup position. "
 
-    if float(re["2"]["second_score"]) > 85:
+    if float(re["2"]["score"]) > 85:
         ret = ret + "The upper part of the body is slightly forward, and the push is fast and powerful. "
-    elif float(re["2"]["second_score"]) > 75:
+    elif float(re["2"]["score"]) > 75:
         ret = ret + "The upper part of the body is slightly forward, and the push is fast and powerful. "
-    elif float(re["2"]["second_score"]) > 65:
+    elif float(re["2"]["score"]) > 65:
         ret = ret + "There is no front drive on the upper body, and the push is fast and powerful. "
     else:
         ret = ret + "The upper body has no front drive, and the push-off is not fast and powerful. "
 
-    if float(re["3"]["third_score"]) > 85:
+    if float(re["3"]["score"]) > 85:
         ret = ret + "The pedal and the hand swing are very harmonious. "
-    elif float(re["3"]["third_score"]) > 75:
+    elif float(re["3"]["score"]) > 75:
         ret = ret + "Pedal and hand swing are not in harmony. "
-    elif float(re["3"]["third_score"]) > 65:
+    elif float(re["3"]["score"]) > 65:
         ret = ret + "Foot pedal and hand swing are not coordinated. "
     else:
         ret = ret + "Foot pedal and hand swing are not coordinated. "
 
-    if float(re["4"]["forth_score"]) > 80:
+    if float(re["4"]["score"]) > 80:
         ret = ret + "The air stretch is full.  "
-    elif float(re["4"]["forth_score"]) > 70:
+    elif float(re["4"]["score"]) > 70:
         ret = ret + "The air stretch is not sufficient. "
-    elif float(re["4"]["forth_score"]) > 60:
+    elif float(re["4"]["score"]) > 60:
         ret = ret + "The air stretch is insufficient. "
     else:
         ret = ret + "There is no stretch in the air. "

+ 6 - 6
backend_refactor/service/ai/video/classify/jumpwithboth.py

@@ -9,20 +9,20 @@ def classify_jumpwithboth(re):
     else:
         ret = ret + "The movement process is terrible and needs to be improved. "
 
-    if float(re["1"]["first_score"]) > 85:
+    if float(re["1"]["score"]) > 85:
         ret = ret + "You did the good jump in the air.  "
-    elif float(re["1"]["first_score"]) > 75:
+    elif float(re["1"]["score"]) > 75:
         ret = ret + "Your jumping in the air is not up to standard. "
-    elif float(re["1"]["first_score"]) > 60:
+    elif float(re["1"]["score"]) > 60:
         ret = ret + "Your jumping in the air needs a lot of improvement. "
     else:
         ret = ret + "Your jumping in the air is far from standard, see some relevant video to correct posture. "
 
-    if float(re["2"]["second_score"]) > 85:
+    if float(re["2"]["score"]) > 85:
         ret = ret + "You did the good landing action.  "
-    elif float(re["2"]["second_score"]) > 75:
+    elif float(re["2"]["score"]) > 75:
         ret = ret + "Your landing action is not up to standard. "
-    elif float(re["2"]["second_score"]) > 60:
+    elif float(re["2"]["score"]) > 60:
         ret = ret + "Your landing action needs a lot of improvement. "
     else:
         ret = ret + "Your landing action is far from standard, see some relevant video to correct posture. "

+ 7 - 7
backend_refactor/service/ai/video/classify/pingban.py

@@ -9,24 +9,24 @@ def classify_pingban(re):
     else:
         ret = ret + "The movement process is terrible and needs to be improved. "
 
-    if re["1"]["no_first_posture"] == "true":
+    if not re["1"]["is_prepared"]:
         ret = ret + "Lack the setup position. "
     else:
-        if float(re["1"]["first_score"]) > 80:
+        if float(re["1"]["score"]) > 80:
             ret = ret + "The setup position is good. "
-        elif float(re["1"]["first_score"]) > 70:
+        elif float(re["1"]["score"]) > 70:
             ret = ret + "The setup position is not bad. "
-        elif float(re["1"]["first_score"]) > 60:
+        elif float(re["1"]["score"]) > 60:
             ret = ret + "The setup position is not standard enough. Take more practice."
         else:
             ret = ret + "The setup position is far from standard, see some relevant video to correct posture."
 
     if float(re["2"]["elbow_right_angle"]) > 120 or float(re["2"]["elbow_left_angle"]) > 120:
-        if float(re["2"]["second_score"]) > 84:
+        if float(re["2"]["score"]) > 84:
             ret = ret + "The core strength is good. "
-        elif float(re["2"]["second_score"]) > 75:
+        elif float(re["2"]["score"]) > 75:
             ret = ret + "The core strength is not bad. "
-        elif float(re["2"]["second_score"]) > 65:
+        elif float(re["2"]["score"]) > 65:
             ret = ret + "Need to do more to promote the core strength. "
         else:
             ret = ret + "The core strength need to be improved. "

+ 6 - 6
backend_refactor/service/ai/video/classify/tennisthrow.py

@@ -9,11 +9,11 @@ def classify_tennisthrow(re):
     else:
         ret = ret + "The movement process is terrible and needs to be improved. "
 
-    if float(re["1"]["first_score"]) > 85:
+    if float(re["1"]["score"]) > 85:
         ret = ret + "The setup position is good. "
-    elif float(re["1"]["first_score"]) > 75:
+    elif float(re["1"]["score"]) > 75:
         ret = ret + "The setup position is not bad. "
-    elif float(re["1"]["first_score"]) > 65:
+    elif float(re["1"]["score"]) > 65:
         ret = ret + "The setup position is not standard enough. Take more practice. "
     else:
         ret = ret + "The setup position is far from standard, see some relevant video to correct posture. "
@@ -23,11 +23,11 @@ def classify_tennisthrow(re):
     else:
         ret = ret + "Your knees are not bent in place and need some improvement. "
 
-    if float(re["2"]["second_score"])>85:
+    if float(re["2"]["score"]) > 85:
         ret = ret + "When you throw the tennis ball, your action is standard. "
-    elif float(re["2"]["second_score"])>75:
+    elif float(re["2"]["score"]) > 75:
         ret = ret + "You don't throw the tennis ball very well. "
-    elif float(re["2"]["second_score"])>65:
+    elif float(re["2"]["score"]) > 65:
         ret = ret + "You need to improve your motion when you throw the tennis ball. "
     else:
         ret = ret + "When you throw the tennis ball, your action is far from standard, see some relevant video to correct posture. "

+ 6 - 6
backend_refactor/service/ai/video/classify/turnaround.py

@@ -12,20 +12,20 @@ def classify_turnaround(re):
         ret = ret + "Pay attention to arm bending during running. "
     else:
         ret = ret + "Not bad arm posture during the run. "
-    if float(re["1"]["first_score"]) > 85:
+    if float(re["1"]["score"]) > 85:
         ret = ret + "The leg muscle is good. "
-    elif float(re["1"]["first_score"]) > 75:
+    elif float(re["1"]["score"]) > 75:
         ret = ret + "The leg muscle is not bad, but still need to do more practise. "
-    elif float(re["1"]["first_score"]) > 60:
+    elif float(re["1"]["score"]) > 60:
         ret = ret + "Need to do more to promote leg muscle strength. "
     else:
         ret = ret + "The leg muscle is weak and the position needs to be improved. "
 
-    if float(re["2"]["second_score"]) > 88:
+    if float(re["2"]["score"]) > 88:
         ret = ret + "Your movements when you touch the obstacles are very standard. "
-    elif float(re["2"]["second_score"]) > 78:
+    elif float(re["2"]["score"]) > 78:
         ret = ret + "The action when you touch the obstacle is not very standard. "
-    elif float(re["2"]["second_score"]) > 65:
+    elif float(re["2"]["score"]) > 65:
         ret = ret + "The way you touch the obstacles needs a lot of improvement. "
     else:
         ret = ret + "You may have questions about what to do when you touch an obstacle, see some relevant video to correct posture."

+ 5 - 3
backend_refactor/service/ai/video/video_score/balancebeam.py

@@ -37,8 +37,10 @@ def cal_second_score(list):
                 item["elbow_left_angle"]) == 0 or float(item["neck_left_angle"]) == 0:
             num = num - 1
         else:
-            score = cal_ratio(item["neck_right_angle"], 90) * 30 + cal_ratio(item["neck_left_angle"], 90) * 30 + cal_ratio(item["elbow_right_angle"],
-                                                                               180) * 20 + cal_ratio(
+            score = cal_ratio(item["neck_right_angle"], 90) * 30 + cal_ratio(item["neck_left_angle"],
+                                                                             90) * 30 + cal_ratio(
+                item["elbow_right_angle"],
+                180) * 20 + cal_ratio(
                 item["elbow_left_angle"],
                 180) * 20
             sum_score = sum_score + score
@@ -80,7 +82,7 @@ def cal_balancebeam(result):
     re["1"]["number_of_satisfied"] = len(satisfied_pics)
     re["1"]["begin_index"] = begin_index
     re["1"]["finish_index"] = finish_index
-    re["1"]["highest_wrist_index"] = highest_wrist_index
+    re["1"]["index"] = highest_wrist_index
     re["1"]["total_score"] = round(total_score, 2)
     print("finish capturing postures and calculating scores")
     print("result-----------")

+ 10 - 10
backend_refactor/service/ai/video/video_score/jump.py

@@ -83,8 +83,8 @@ def cal_jump(result):
         float(result_ig[min_wrist_index]["ankle_left_angle"]), 90) * 10), 2)
 
     re["1"] = result_ig[min_wrist_index]
-    re["1"]["first_score"] = round(first_score, 2)
-    re["1"]["first_score_index"] = min_wrist_index
+    re["1"]["score"] = round(first_score, 2)
+    re["1"]["index"] = min_wrist_index
     re["1"]["is_prepared"] = is_prepared
     # second socre
     result_ig = is_zero(result_ig, min_hip_angle_index)
@@ -96,8 +96,8 @@ def cal_jump(result):
                           cal_ratio(float(result_ig[min_hip_angle_index][
                                               "ankle_left_angle"]), 85) * 10), 2)
     re["2"] = result_ig[min_hip_angle_index]
-    re["2"]["second_score"] = round(second_score, 2)
-    re["2"]["second_score_index"] = min_hip_angle_index
+    re["2"]["score"] = round(second_score, 2)
+    re["2"]["index"] = min_hip_angle_index
     # third score
     max_hip_angle = float(result[min_hip_angle_index]["knee_right_angle"])
     max_hip_index = "1"
@@ -124,8 +124,8 @@ def cal_jump(result):
         result_ig[max_hip_index]["ankle_left_angle"], 165) * 20
 
     re["3"] = result_ig[max_hip_index]
-    re["3"]["third_score"] = round(third_score, 2)
-    re["3"]["third_score_index"] = max_hip_index
+    re["3"]["score"] = round(third_score, 2)
+    re["3"]["index"] = max_hip_index
     # forth score
     result_ig = is_zero(result_ig, highest_ankle_index)
     forth_score = cal_ratio(result_ig[highest_ankle_index]["hip_right_angle"], 180) * 25 + cal_ratio(
@@ -134,8 +134,8 @@ def cal_jump(result):
         result_ig[highest_ankle_index]["knee_left_angle"], 55) * 25
 
     re["4"] = result_ig[highest_ankle_index]
-    re["4"]["forth_score"] = round(forth_score, 2)
-    re["4"]["forth_score_index"] = highest_ankle_index
+    re["4"]["score"] = round(forth_score, 2)
+    re["4"]["index"] = highest_ankle_index
     # fifth score
     lowest_ankle_height = float(result[reland_index]["leg_heigh"])
     lowest_ankle_index = "1"
@@ -158,8 +158,8 @@ def cal_jump(result):
         result_ig[lowest_ankle_index]["ankle_left_angle"], 90) * 10
 
     re["5"] = result_ig[lowest_ankle_index]
-    re["5"]["fifth_score"] = round(fifth_score, 2)
-    re["5"]["fifth_score_index"] = lowest_ankle_index
+    re["5"]["score"] = round(fifth_score, 2)
+    re["5"]["index"] = lowest_ankle_index
     if is_prepared:
         re["5"]["total_score"] = round(
             0.1 * first_score + 0.2 * second_score + 0.3 * third_score + 0.3 * forth_score + 0.1 * fifth_score, 2)

+ 4 - 4
backend_refactor/service/ai/video/video_score/jumpwithboth.py

@@ -82,8 +82,8 @@ def cal_jumpwithboth(result):
     first_score = cal_average_score([result_ig[highest_ankle_index]], 1)
     re["1"] = result_ig[highest_ankle_index]
     re["1"]["highest_ankle"] = highest_ankle
-    re["1"]["highest_ankle_index"] = highest_ankle_index
-    re["1"]["first_score"] = first_score
+    re["1"]["index"] = highest_ankle_index
+    re["1"]["score"] = first_score
 
     # second score
     reload_pics_index = []
@@ -100,8 +100,8 @@ def cal_jumpwithboth(result):
     second_score = cal_average_score(reload_pics, 2)
     re["2"] = result_ig[reload_pics_index[0]]
     re["2"]["number_of_satisfied"] = len(reload_pics)
-    re["2"]["index_of_satisfied"] = reload_pics_index
-    re["2"]["second_score"] = second_score
+    re["2"]["index"] = reload_pics_index
+    re["2"]["score"] = second_score
     re["2"]["total_score"] = round(0.6 * first_score + 0.4 * second_score, 2)
     print("finish capturing postures and calculating scores")
     print("result-----------")

+ 6 - 5
backend_refactor/service/ai/video/video_score/pingban.py

@@ -73,11 +73,12 @@ def cal_pingban(result):
                                                                            180) * 20 + cal_ratio(
             result_ig[first_index]["elbow_left_angle"], 180) * 20
         re["1"] = result_ig[first_index]
-        re["1"]["first_score"] = round(first_score, 2)
-        re["1"]["first_index"] = first_index
+        re["1"]["score"] = round(first_score, 2)
+        re["1"]["index"] = first_index
+        re["1"]["is_prepared"] = True
     else:
         re["1"] = result_ig[list(result.keys())[0]]
-        re["1"]["no_first_posture"] = "true"
+        re["1"]["is_prepared"] = False
     # second posture
     max_knee_angle = float(result_ig[list(result.keys())[0]]["hip_right_angle"])
     max_knee_angle_index = "1"
@@ -100,8 +101,8 @@ def cal_pingban(result):
         total_score = round(0.05 * first_score + 0.95 * pingban_2_score, 2)
     re["2"] = result_ig[max_knee_angle_index]
     re["2"]["number_of_satisfied"] = len(second_pics)
-    re["2"]["satisfied_index"] = satisfied_index
-    re["2"]["second_score"] = round(pingban_2_score, 2)
+    re["2"]["index"] = satisfied_index
+    re["2"]["score"] = round(pingban_2_score, 2)
     re["2"]["max_knee_angle"] = max_knee_angle
     re["2"]["max_knee_angle_index"] = max_knee_angle_index
     re["2"]["total_score"] = round(total_score, 2)

+ 1 - 1
backend_refactor/service/ai/video/video_score/sitforward.py

@@ -51,7 +51,7 @@ def cal_sitforward(result):
 
     re["1"] = result[highest_weist_index]
     re["1"]["highest_wrist_x"] = highest_wrist_x
-    re["1"]["highest_weist_index"] = highest_weist_index
+    re["1"]["index"] = highest_weist_index
     re["1"]["total_score"] = total_score
     print("finish capturing postures and calculating scores")
     print("result-----------")

+ 1 - 1
backend_refactor/service/ai/video/video_score/standing.py

@@ -98,7 +98,7 @@ def cal_standing(result):
     re["1"] = result[minest_knee_angle_index]
     re["1"]["mode"] = mode
     re["1"]["minest_knee_angle"] = minest_knee_angle
-    re["1"]["minest_knee_angle_index"] = minest_knee_angle_index
+    re["1"]["index"] = minest_knee_angle_index
     re["1"]["total_score"] = minest_knee_score
 
     # re["1"]["begin_index"] = begin_index

+ 4 - 4
backend_refactor/service/ai/video/video_score/tennisthrow.py

@@ -115,14 +115,14 @@ def cal_tennisthrow(result):
     result_ig = is_zero(result_ig, farrest_distance_index)
     first_score = cal_average_score(result_ig[farrest_distance_index], hand, 1)
     re["1"] = result_ig[farrest_distance_index]
-    re["1"]["farrest_distance_index"] = farrest_distance_index
+    re["1"]["index"] = farrest_distance_index
     re["1"]["farrest_distance"] = farrest_distance
-    re["1"]["first_score"] = first_score
+    re["1"]["score"] = first_score
 
     re["2"] = result_ig[highest_wrist_index]
-    re["2"]["highest_wrist_index"] = highest_wrist_index
+    re["2"]["index"] = highest_wrist_index
     re["2"]["highest_wrist"] = highest_wrist
-    re["2"]["second_score"] = third_score
+    re["2"]["score"] = third_score
     re["2"]["total_score"] = round(first_score * 0.3 + third_score * 0.7, 2)
 
     print("finish capturing postures and calculating scores")

+ 7 - 7
backend_refactor/service/ai/video/video_score/turnaround.py

@@ -52,9 +52,9 @@ def cal_average_score(list, mode):
         if mode == 1:
             is_clean = check_elbow(item)
             if (is_clean):
-                if abs(float(item["ankle_right_angle"])-float(item["ankle_left_angle"]))>60:
-                    if abs(float(item["ankle_right_angle"])-110)>abs(float(item["ankle_left_angle"])-110):
-                        item["ankle_right_angle"]=item["ankle_left_angle"]
+                if abs(float(item["ankle_right_angle"]) - float(item["ankle_left_angle"])) > 60:
+                    if abs(float(item["ankle_right_angle"]) - 110) > abs(float(item["ankle_left_angle"]) - 110):
+                        item["ankle_right_angle"] = item["ankle_left_angle"]
                         score = cal_ratio(item["elbow_right_angle"], 95) * 20 + cal_ratio(item["elbow_left_angle"],
                                                                                           95) * 20 + cal_ratio(
                             item["ankle_left_angle"],
@@ -122,9 +122,9 @@ def cal_turnaround(result):
     re["1"] = result_ig[satisfied_index[0]]
     # re["1"]["max_distance"] = max_distance
     # re["1"]["max_distance_index"] = max_distance_index
-    re["1"]["satisfied_index"] = satisfied_index
+    re["1"]["index"] = satisfied_index
     re["1"]["number_of_satisfied"] = len(satisfied_pics)
-    re["1"]["first_score"] = first_score
+    re["1"]["score"] = first_score
 
     # second score
     lowest_midhip = 0
@@ -140,8 +140,8 @@ def cal_turnaround(result):
 
     re["2"] = result_ig[lowest_midhip_index]
     re["2"]["lowest_midhip"] = lowest_midhip
-    re["2"]["lowest_midhip_index"] = lowest_midhip_index
-    re["2"]["second_score"] = second_score
+    re["2"]["index"] = lowest_midhip_index
+    re["2"]["score"] = second_score
     re["2"]["total_score"] = round(0.7 * first_score + 0.3 * second_score, 2)
     print("finish capturing postures and calculating scores")
     print("result-----------")