Browse Source

avoid division by zero by setting minimum value to minimum precision

Daniel Sheffield 6 months ago
parent
commit
4a308913ba
2 changed files with 4 additions and 3 deletions
  1. 2 1
      app/activities/Rating.py
  2. 2 2
      app/widgets.py

+ 2 - 1
app/activities/Rating.py

@@ -17,10 +17,11 @@ class Rating():
             self.text_fields['marker'].set_text('')
             return
         current = None if None in (price, quantity or None) else float(price/quantity)
-        
+
         chars = ['|', *['-']*(self.size - 2), '|' ]
         rating = [' ']*len(chars)
         _min, _max = min(_min, current or _min), max(_max, current or _max)
+        _avg = max(_avg, 0.0001)
         ls = np.linspace(_min, _max, len(chars))
         if current is not None and _avg is not None:
             if current <= _avg:

+ 2 - 2
app/widgets.py

@@ -136,7 +136,7 @@ class AutoCompleteFloatEdit(FloatEdit):
         return super().keypress(size, key)
 
 class NoTabCheckBox(CheckBox):
-    
+
     def keypress(self, size, key):
         if not isinstance(key, tuple) and key == 'tab':
             return None
@@ -358,7 +358,7 @@ class FlowBarGraphWithVScale(Columns):
         labels = vscale or []
         caption = caption or u''
         top = self.height
-        scale = _max*(top+1)/top
+        scale = max(_max*(top+1)/top, 0.0001)
         self.graph.set_data(data, scale)
         self.graph_vscale._invalidate()
         self.graph_vscale.set_scale([