yf_yzl 2 years ago
parent
commit
8793c0bda1
1 changed files with 26 additions and 25 deletions
  1. 26 25
      smartfarming/api/views/forecast/worm_lamp.py

+ 26 - 25
smartfarming/api/views/forecast/worm_lamp.py

@@ -672,19 +672,20 @@ def pest_statistics_char_new(request):
         else:
             for result in indentify_result.split("#"):
                 tuple_result = result.split(",")
-                try:
-                    pest_name = insect_dict.get(tuple_result[0],"未命名")
-                    pest_num = int(tuple_result[1])
-                    if pest_name in pest_day_info:
-                        pest_day_info[pest_name]["sum"] += pest_num
-                    else:
-                        pest_day_info[pest_name] = {"addtime":date_stamp,"sum":pest_num}
-                    if pest_name in pest_info_total:
-                        pest_info_total[pest_name] += pest_num
-                    else:
-                        pest_info_total[pest_name] = pest_num
-                except Exception as e:
-                    logger.error(f'虫情分析errorlogger.error(f"{result} {tuple_result} {e} {photo_object.id}")')
+                if len(tuple_result) >= 2:
+                    try:
+                        pest_name = insect_dict.get(tuple_result[0],"未命名")
+                        pest_num = int(tuple_result[1])
+                        if pest_name in pest_day_info:
+                            pest_day_info[pest_name]["sum"] += pest_num
+                        else:
+                            pest_day_info[pest_name] = {"addtime":date_stamp,"sum":pest_num}
+                        if pest_name in pest_info_total:
+                            pest_info_total[pest_name] += pest_num
+                        else:
+                            pest_info_total[pest_name] = pest_num
+                    except Exception as e:
+                        logger.error(f'虫情分析errorlogger.error(f"{result} {tuple_result} {e} {photo_object.id}")')
     # 最后一天的数据统计,循环内加不了
     for pest_day_key,pest_day_value in pest_day_info.items():
         if pest_day_key in chart_info:
@@ -800,15 +801,14 @@ def pest_image_source(request):
                         pest_dict[pest_name] = 1
         else:
             for index,result in enumerate(indentify_result.split("#")) :
-                try:
-                    if index != 0:
-                        pest_string += "、"
-                    tuple_result = result.split(",")
+                if index != 0:
+                    pest_string += "、"
+                tuple_result = result.split(",")
+                if len(tuple_result) >= 2:
                     pest_name = insect_dict.get(tuple_result[0],"未命名")
                     pest_string+=pest_name
                     pest_dict[pest_name] = int(tuple_result[1])
-                except Exception as e:
-                    logger.error(f"{result} {tuple_result} {e}")
+
         if select_name and select_name not in pest_string:
             continue
         addtime = photo_object.addtime
@@ -902,12 +902,13 @@ def pest_base_data(request):
         else:
             for result in indentify_result.split("#"):
                 tuple_result = result.split(",")
-                pest_name = insect_dict.get(tuple_result[0],"未命名")
-                if select_name and select_name not in pest_name:
-                    continue
-                pest_num = int(tuple_result[1])
-                pest_dict=dict(pest_name=pest_name,pest_num=pest_num,addtime=addtime)
-                pest_base_data.append(pest_dict)
+                if len(tuple_result) >= 2:
+                    pest_name = insect_dict.get(tuple_result[0],"未命名")
+                    if select_name and select_name not in pest_name:
+                        continue
+                    pest_num = int(tuple_result[1])
+                    pest_dict=dict(pest_name=pest_name,pest_num=pest_num,addtime=addtime)
+                    pest_base_data.append(pest_dict)
         
     return_data = pest_base_data[(page-1)*page_size:page*page_size]