nodes: 0, module; 1, function_definition; 2, function_name:_compute_gas_price; 3, parameters; 4, block; 5, identifier:probabilities; 6, identifier:desired_probability; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, for_statement; 12, comment:"""
      Given a sorted range of ``Probability`` named-tuples returns a gas price
      computed based on where the ``desired_probability`` would fall within the
      range.
  
      :param probabilities: An iterable of `Probability` named-tuples sorted in reverse order.
      :param desired_probability: An floating point representation of the desired
          probability. (e.g. ``85% -> 0.85``)
      """; 13, assignment; 14, assignment; 15, comparison_operator:desired_probability >= first.prob; 16, block; 17, elif_clause; 18, pattern_list; 19, call; 20, block; 21, else_clause; 22, identifier:first; 23, subscript; 24, identifier:last; 25, subscript; 26, identifier:desired_probability; 27, attribute; 28, return_statement; 29, comparison_operator:desired_probability <= last.prob; 30, block; 31, identifier:left; 32, identifier:right; 33, identifier:sliding_window; 34, argument_list; 35, if_statement; 36, expression_statement; 37, expression_statement; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, return_statement; 42, comment:# The initial `if/else` clause in this function handles the case where; 43, comment:# the `desired_probability` is either above or below the min/max; 44, comment:# probability found in the `probabilities`.; 45, comment:#; 46, comment:# With these two cases handled, the only way this code block should be; 47, comment:# reachable would be if the `probabilities` were not sorted correctly.; 48, comment:# Otherwise, the `desired_probability` **must** fall between two of the; 49, comment:# values in the `probabilities``.; 50, block; 51, identifier:probabilities; 52, integer:0; 53, identifier:probabilities; 54, unary_operator; 55, identifier:first; 56, identifier:prob; 57, call; 58, identifier:desired_probability; 59, attribute; 60, return_statement; 61, integer:2; 62, identifier:probabilities; 63, comparison_operator:desired_probability < right.prob; 64, block; 65, elif_clause; 66, assignment; 67, assignment; 68, assignment; 69, assignment; 70, assignment; 71, identifier:gas_price; 72, raise_statement; 73, integer:1; 74, identifier:int; 75, argument_list; 76, identifier:last; 77, identifier:prob; 78, call; 79, identifier:desired_probability; 80, attribute; 81, continue_statement; 82, comparison_operator:desired_probability > left.prob; 83, comment:# This code block should never be reachable as it would indicate; 84, comment:# that we already passed by the probability window in which our; 85, comment:# `desired_probability` is located.; 86, block; 87, identifier:adj_prob; 88, binary_operator:desired_probability - right.prob; 89, identifier:window_size; 90, binary_operator:left.prob - right.prob; 91, identifier:position; 92, binary_operator:adj_prob / window_size; 93, identifier:gas_window_size; 94, binary_operator:left.gas_price - right.gas_price; 95, identifier:gas_price; 96, call; 97, call; 98, attribute; 99, identifier:int; 100, argument_list; 101, identifier:right; 102, identifier:prob; 103, identifier:desired_probability; 104, attribute; 105, raise_statement; 106, identifier:desired_probability; 107, attribute; 108, attribute; 109, attribute; 110, identifier:adj_prob; 111, identifier:window_size; 112, attribute; 113, attribute; 114, identifier:int; 115, argument_list; 116, identifier:Exception; 117, argument_list; 118, identifier:first; 119, identifier:gas_price; 120, attribute; 121, identifier:left; 122, identifier:prob; 123, call; 124, identifier:right; 125, identifier:prob; 126, identifier:left; 127, identifier:prob; 128, identifier:right; 129, identifier:prob; 130, identifier:left; 131, identifier:gas_price; 132, identifier:right; 133, identifier:gas_price; 134, call; 135, string; 136, identifier:last; 137, identifier:gas_price; 138, identifier:Exception; 139, argument_list; 140, attribute; 141, argument_list; 142, string_content:Invariant; 143, string; 144, identifier:math; 145, identifier:ceil; 146, binary_operator:right.gas_price + gas_window_size * position; 147, string_content:Invariant; 148, attribute; 149, binary_operator:gas_window_size * position; 150, identifier:right; 151, identifier:gas_price; 152, identifier:gas_window_size; 153, identifier:position
code: def _compute_gas_price(probabilities, desired_probability):
      """
      Given a sorted range of ``Probability`` named-tuples returns a gas price
      computed based on where the ``desired_probability`` would fall within the
      range.
  
      :param probabilities: An iterable of `Probability` named-tuples sorted in reverse order.
      :param desired_probability: An floating point representation of the desired
          probability. (e.g. ``85% -> 0.85``)
      """
      first = probabilities[0]
      last = probabilities[-1]
  
      if desired_probability >= first.prob:
          return int(first.gas_price)
      elif desired_probability <= last.prob:
          return int(last.gas_price)
  
      for left, right in sliding_window(2, probabilities):
          if desired_probability < right.prob:
              continue
          elif desired_probability > left.prob:
              # This code block should never be reachable as it would indicate
              # that we already passed by the probability window in which our
              # `desired_probability` is located.
              raise Exception('Invariant')
  
          adj_prob = desired_probability - right.prob
          window_size = left.prob - right.prob
          position = adj_prob / window_size
          gas_window_size = left.gas_price - right.gas_price
          gas_price = int(math.ceil(right.gas_price + gas_window_size * position))
          return gas_price
      else:
          # The initial `if/else` clause in this function handles the case where
          # the `desired_probability` is either above or below the min/max
          # probability found in the `probabilities`.
          #
          # With these two cases handled, the only way this code block should be
          # reachable would be if the `probabilities` were not sorted correctly.
          # Otherwise, the `desired_probability` **must** fall between two of the
          # values in the `probabilities``.
          raise Exception('Invariant')