getCursor - noetl/noetl GitHub Wiki

E.g. expandedCursor = getCursor(["201401:201405", "201407", "201412:201503"], "date", "2m", "%Y%m")

Parameters

  • cursor: list of dates or a range of dates
  • datatype: datatype of cursor; date or integer
  • increment: increment of cursor if cursor is a range; add a "y", "m", or "d" (year, month, day) if the cursor is of type date
  • dateFormat: default="%Y%m"; dateFormat of cursor if cursor is of type date

Key Variables

  • curId: element index corresponding to curVal when iterating through the cursor list
  • curVal: element in cursor
  • curList: if cursor is a range, start and end are split by ":" and stored in curList
  • incType: if datatype is date, incType specifies "y", "m", or "d" (year, month, day) of the cursor increment
  • incAmt: numeric value of increment
  • partialCursor: expanded cursor range for particular element in cursor list
  • cur: single cursor date or integer

Functionality

  • GetCursor iterates through each element in cursor. If the element is a range, it is split by ":" and the start and end of the cursor are stored in curList. If the cursor datatype is a date and the current cursor element is a range, the starting date is stored at the element's index in the cursor (to replace the range so the cursor is a list of single values - the other values are appended to the list later). The increment parameter is split into the incType ("y", "m", "d") and the incAmt, and the partialCursor is computed by calling addTime.
  • AddTime returns a list of individual cursor dates - the result of expanding the range into separate dates. GetCursor loops through each element in the element's expanded partialCursor, and adds it to the cursor (if it is not already there).
  • Otherwise, if the cursor datatype is an integer and the current cursor element is a range, the starting date is stored at the element's index in the cursor to replace the range in the cursor. The increment is converted from a string to an integer, and a counter is set to the starting element in the range plus the increment value. While this counter is less than or equal to the ending element in the range, the cursor appends the counter, and adds the increment to the counter each loop.
  • The cursor is converted to a set, and the sorted set is returned.

Except Statement

If an error arises, the except block prints the time and the error message.

Return Value

GetCursor returns the sorted set of cursor values in the range provided as the cursor.