title: Number of Cycles from list of values, which are mix of positives and negatives in Spark and Scala
body: <p><strong>Have an RDD with List of values, which are mix of positives and negatives.
  Need to compute number of cycles from this data.</strong></p>
  
  <p>For example,</p>
  
  <p><code>val range = List(sampleRange(2020,2030,2040,2050,-1000,-1010,-1020,Starting point,-1030,2040,-1020,2050,2040,2020,end point,-1060,-1030,-1010)</code> </p>
  
  <p>the interval between each value in above list is 1 second. ie., 2020 and 2030 are recorded in 1 second interval and so on.  </p>
  
  <p>how many times it turns from negative to positive and stays positive for >= 2 seconds.<br>
  If >= 2 seconds it is a cycle.  </p>
  
  <p><strong>Number of cycles: Logic</strong><br>
  <strong>Example 1:</strong> List(1,2,3,4,5,6,-15,-66)<br>
  No. of cycles is <strong>1</strong>.<br>
  Reason: As we move from 1st element of list to 6th element, we had 5 intervals which means 5 seconds. So one cycle. 
  As we move to 6th element of list, it is a negative value. So we start counting from 6th element and move to 7th element. The negative values are only 2 and interval is only 1. So not counted as cycle.<br>
  <strong>Example 2:</strong><br>
  List(11,22,33,-25,-36,-43,20,25,28)<br>
  No. of cycles is <strong>3</strong>.<br>
  Reason: As we move from 1st element of list to 3rd element, we had 2 intervals which means 2 seconds. So one cycle As we move to 4th element of list, it is a negative value. So we start counting from 4th element and move to 5th, 6th element. we had 2 intervals which means 2 seconds. So one cycle As we move to 7th element of list, it is a positive value. So we start counting from 7th element and move to 8th, 9th element. we had 2 intervals which means 2 seconds. So one cycle.  </p>
  
  <p><em>range</em> is a RDD in the use case. It looks like<br>
  scala> range<br>
  range: Seq[com.Range] = List(XtreamRange(858,890,899,920,StartEngage,-758,-790,-890,-720,920,940,950))</p>