nodes: 0, module; 1, function_definition; 2, function_name:sorted_timeseries; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, expression_statement; 12, for_statement; 13, expression_statement; 14, return_statement; 15, identifier:ascending; 16, True; 17, comment:"""Returns a sorted copy of the TimeSeries, preserving the original one.
  
          As an assumption this new TimeSeries is not ordered anymore if a new value is added.
  
          :param boolean ascending:    Determines if the TimeSeries will be ordered ascending
              or descending.
  
          :return:    Returns a new TimeSeries instance sorted in the requested order.
          :rtype:     TimeSeries
          """; 18, assignment; 19, not_operator; 20, block; 21, assignment; 22, assignment; 23, identifier:entry; 24, identifier:data; 25, block; 26, assignment; 27, identifier:newTS; 28, identifier:sortorder; 29, integer:1; 30, identifier:ascending; 31, expression_statement; 32, identifier:data; 33, call; 34, identifier:newTS; 35, call; 36, expression_statement; 37, attribute; 38, identifier:ascending; 39, assignment; 40, identifier:sorted; 41, argument_list; 42, identifier:TimeSeries; 43, argument_list; 44, call; 45, identifier:newTS; 46, identifier:_sorted; 47, identifier:sortorder; 48, unary_operator; 49, attribute; 50, keyword_argument; 51, attribute; 52, attribute; 53, argument_list; 54, integer:1; 55, identifier:self; 56, identifier:_timeseriesData; 57, identifier:key; 58, lambda; 59, identifier:self; 60, identifier:_normalized; 61, identifier:newTS; 62, identifier:add_entry; 63, list_splat; 64, lambda_parameters; 65, binary_operator:sortorder * i[0]; 66, identifier:entry; 67, identifier:i; 68, identifier:sortorder; 69, subscript; 70, identifier:i; 71, integer:0
code: def sorted_timeseries(self, ascending=True):
          """Returns a sorted copy of the TimeSeries, preserving the original one.
  
          As an assumption this new TimeSeries is not ordered anymore if a new value is added.
  
          :param boolean ascending:    Determines if the TimeSeries will be ordered ascending
              or descending.
  
          :return:    Returns a new TimeSeries instance sorted in the requested order.
          :rtype:     TimeSeries
          """
          sortorder = 1
          if not ascending:
              sortorder = -1
  
          data = sorted(self._timeseriesData, key=lambda i: sortorder * i[0])
  
          newTS = TimeSeries(self._normalized)
          for entry in data:
              newTS.add_entry(*entry)
  
          newTS._sorted = ascending
  
          return newTS