code: def _clearQuantity(self, offbids, gen):
          
          # Filter out offers/bids not applicable to the generator in question.
          gOffbids = [offer for offer in offbids if offer.generator == gen]
  
          # Offers/bids within valid price limits (not withheld).
          valid = [ob for ob in gOffbids if not ob.withheld]
  
          # Sort offers by price in ascending order and bids in decending order.
          valid.sort(key=lambda ob: ob.price, reverse=[False, True][gen.is_load])
  
          acceptedQty = 0.0
          for ob in valid:
              # Compute the fraction of the block accepted.
              accepted = (ob.totalQuantity - acceptedQty) / ob.quantity
  
              # Clip to the range 0-1.
              if accepted > 1.0:
                  accepted = 1.0
              elif accepted < 1.0e-05:
                  accepted = 0.0
  
              ob.clearedQuantity = accepted * ob.quantity
  
              ob.accepted = (accepted > 0.0)
  
              # Log the event.
  #            if ob.accepted:
  #                logger.info("%s [%s, %.3f, %.3f] accepted at %.2f MW." %
  #                    (ob.__class__.__name__, ob.generator.name, ob.quantity,
  #                     ob.price, ob.clearedQuantity))
  #            else:
  #                logger.info("%s [%s, %.3f, %.3f] rejected." %
  #                    (ob.__class__.__name__, ob.generator.name, ob.quantity,
  #                     ob.price))
  
              # Increment the accepted quantity.
              acceptedQty += ob.quantity
docs: Computes the cleared bid quantity from total dispatched quantity.