nodes: 0, module; 1, function_definition; 2, function_name:format_time_and_value_to_segment_list; 3, parameters; 4, block; 5, identifier:time_and_value_list; 6, identifier:segments_count; 7, identifier:start_timestamp; 8, identifier:end_timestamp; 9, default_parameter; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, return_statement; 15, identifier:average; 16, False; 17, comment:"""
      Format time_and_value_list to time segments
  
      Parameters
      ^^^^^^^^^^
      time_and_value_list: list of tuples
          Have to be sorted by time
          Example: [(time, value), (time, value) ...]
      segments_count: integer
          How many segments will be in result
      Returns
      ^^^^^^^
      List of dictionaries
          Example:
          [{'from': time1, 'to': time2, 'value': sum_of_values_from_time1_to_time2}, ...]
      """; 18, assignment; 19, assignment; 20, identifier:i; 21, call; 22, block; 23, identifier:segment_list; 24, identifier:segment_list; 25, list; 26, identifier:time_step; 27, binary_operator:(end_timestamp - start_timestamp) / segments_count; 28, identifier:range; 29, argument_list; 30, expression_statement; 31, expression_statement; 32, expression_statement; 33, expression_statement; 34, if_statement; 35, expression_statement; 36, parenthesized_expression; 37, identifier:segments_count; 38, identifier:segments_count; 39, assignment; 40, assignment; 41, assignment; 42, assignment; 43, boolean_operator; 44, block; 45, call; 46, binary_operator:end_timestamp - start_timestamp; 47, identifier:segment_start_timestamp; 48, binary_operator:start_timestamp + time_step * i; 49, identifier:segment_end_timestamp; 50, binary_operator:segment_start_timestamp + time_step; 51, identifier:value_list; 52, list_comprehension; 53, identifier:segment_value; 54, call; 55, identifier:average; 56, comparison_operator:len(value_list) != 0; 57, expression_statement; 58, attribute; 59, argument_list; 60, identifier:end_timestamp; 61, identifier:start_timestamp; 62, identifier:start_timestamp; 63, binary_operator:time_step * i; 64, identifier:segment_start_timestamp; 65, identifier:time_step; 66, identifier:value; 67, for_in_clause; 68, if_clause; 69, identifier:sum; 70, argument_list; 71, call; 72, integer:0; 73, augmented_assignment; 74, identifier:segment_list; 75, identifier:append; 76, dictionary; 77, identifier:time_step; 78, identifier:i; 79, pattern_list; 80, identifier:time_and_value_list; 81, boolean_operator; 82, identifier:value_list; 83, identifier:len; 84, argument_list; 85, identifier:segment_value; 86, call; 87, pair; 88, pair; 89, pair; 90, identifier:time; 91, identifier:value; 92, comparison_operator:time >= segment_start_timestamp; 93, comparison_operator:time < segment_end_timestamp; 94, identifier:value_list; 95, identifier:len; 96, argument_list; 97, string; 98, identifier:segment_start_timestamp; 99, string; 100, identifier:segment_end_timestamp; 101, string; 102, identifier:segment_value; 103, identifier:time; 104, identifier:segment_start_timestamp; 105, identifier:time; 106, identifier:segment_end_timestamp; 107, identifier:value_list; 108, string_content:from; 109, string_content:to; 110, string_content:value
code: def format_time_and_value_to_segment_list(time_and_value_list, segments_count, start_timestamp,
                                            end_timestamp, average=False):
      """
      Format time_and_value_list to time segments
  
      Parameters
      ^^^^^^^^^^
      time_and_value_list: list of tuples
          Have to be sorted by time
          Example: [(time, value), (time, value) ...]
      segments_count: integer
          How many segments will be in result
      Returns
      ^^^^^^^
      List of dictionaries
          Example:
          [{'from': time1, 'to': time2, 'value': sum_of_values_from_time1_to_time2}, ...]
      """
      segment_list = []
      time_step = (end_timestamp - start_timestamp) / segments_count
      for i in range(segments_count):
          segment_start_timestamp = start_timestamp + time_step * i
          segment_end_timestamp = segment_start_timestamp + time_step
          value_list = [
              value for time, value in time_and_value_list
              if time >= segment_start_timestamp and time < segment_end_timestamp]
          segment_value = sum(value_list)
          if average and len(value_list) != 0:
              segment_value /= len(value_list)
  
          segment_list.append({
              'from': segment_start_timestamp,
              'to': segment_end_timestamp,
              'value': segment_value,
          })
      return segment_list