Skip to content
Discussion options

You must be logged in to vote

Hi. You do not actually need persistent state for this. You can use a function for example that always returns one data point containing the longest streak of all time. For example:

  local core = require("tng.core")

  return function(source)
      local emitted = false

      -- Source data points are reverse chronological, so collect them first.
      local points = source.dpall()

      local current_streak = 0
      local best_streak = 0
      local newest_point = points[1]

      -- Walk oldest -> newest.
      for i = #points, 1, -1 do
          local dp = points[i]

          if dp.value and dp.value > 0 then
              current_streak = current_streak + 1
              if curre…

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@Tungill
Comment options

@Tungill
Comment options

@SamAmco
Comment options

@Tungill
Comment options

@Tungill
Comment options

Answer selected by SamAmco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants