瀏覽代碼

fix float division by zero bug in score calculation

Thomas Pointhuber 10 年之前
父節點
當前提交
fdad5f7cad
共有 1 個檔案被更改,包括 16 行新增4 行删除
  1. 16
    4
      searx/engines/__init__.py

+ 16
- 4
searx/engines/__init__.py 查看文件

142
         })
142
         })
143
 
143
 
144
     for engine in pageloads:
144
     for engine in pageloads:
145
-        engine['percentage'] = int(engine['avg'] / max_pageload * 100)
145
+        if max_pageload:
146
+            engine['percentage'] = int(engine['avg'] / max_pageload * 100)
147
+        else:
148
+            engine['percentage'] = 0
146
 
149
 
147
     for engine in results:
150
     for engine in results:
148
-        engine['percentage'] = int(engine['avg'] / max_results * 100)
151
+        if max_results:
152
+            engine['percentage'] = int(engine['avg'] / max_results * 100)
153
+        else:
154
+            engine['percentage'] = 0
149
 
155
 
150
     for engine in scores:
156
     for engine in scores:
151
-        engine['percentage'] = int(engine['avg'] / max_score * 100)
157
+        if max_score:
158
+            engine['percentage'] = int(engine['avg'] / max_score * 100)
159
+        else:
160
+            engine['percentage'] = 0
152
 
161
 
153
     for engine in scores_per_result:
162
     for engine in scores_per_result:
154
-        engine['percentage'] = int(engine['avg'] / max_score_per_result * 100)
163
+        if max_score_per_result:
164
+            engine['percentage'] = int(engine['avg'] / max_score_per_result * 100)
165
+        else:
166
+            engine['percentage'] = 0
155
 
167
 
156
     for engine in errors:
168
     for engine in errors:
157
         if max_errors:
169
         if max_errors: