<commit_before>package org.mwc.debrief.track_shift.zig_detector;

import java.util.ArrayList;
import java.util.List;

public class CumulativeLegDetector implements IOwnshipLegDetector
{

  /**
   * slice this data into ownship legs, where the course and speed are relatively steady
   * 
   * @param course_degs
   * @param speed
   * @param bearings
   * @param elapsedTimess
   * @return
   */
  public List<LegOfData> identifyOwnshipLegs(final long[] times,
      final double[] rawSpeeds, final double[] rawCourses,
      final int minsOfAverage, Precision precision)
  {

    double lastCourse = 0;
    long lastTime = 0;

    final double areaUnderTurn = 20000; // deg millis

    final List<LegOfData> legs = new ArrayList<LegOfData>();
    legs.add(new LegOfData("Leg-1"));
    Integer lastSign = null;
    double leftArea = 0;
    double rightArea = 0;

    // 1. make continuous dataset
    double[] newCourses =
        PeakTrackingOwnshipLegDetector.makeContinuous(rawCourses);
    
    final long startTime = times[0];

    for (int i = 0; i < times.length; i++)
    {
      final long thisTime = times[i];
      final double thisCourse = newCourses[i];

      if (i > 0)
      {
        // ok, check out the course change rate
        final double timeStep = thisTime - lastTime;
        final double courseDelta = thisCourse - lastCourse;
        // final double courseRate = courseDelta / timeStepSecs;
        final double courseArea = courseDelta * timeStep;

        // ok, find the sign of the course
        final int thisSign = (int) Math.signum(courseDelta);

        leftArea += courseArea;
        rightArea += courseArea;

        if (lastSign != null && thisSign != lastSign && thisSign != 0)
        {
          // ok, have we turned to left or right?
          if (thisSign == 1)
          {
            // turn to right

            // 1. the left turn is complete. does it count?
            if (Math.abs(leftArea) > areaUnderTurn)
            {
              System.out.println("left turn end at" +  (thisTime - startTime)/1000);
            }
            else
            {
              System.out.println("skipping turn to right at " + (thisTime - startTime)/1000 + " area:" + leftArea + " crse" + thisCourse);
            }
            leftArea = 0;
          }
          else
          {
            // turn to left

            // 1. the right turn is complete. does it count?
            if (Math.abs(rightArea) > areaUnderTurn)
            {
              System.out.println("right turn end at" +  (thisTime - startTime)/1000);
            }
            else
            {
              System.out.println("skipping turn to left at " +  (thisTime - startTime)/1000 + " area:" + rightArea + " crse" + thisCourse);
            }
            rightArea = 0;
          }
        }

        // ok, store the values
        if (thisSign != 0)
        {
          lastSign = thisSign;
        }
      }

      final long soFar = (thisTime - startTime)/1000;
      if(soFar > 600 && soFar < 1000)
      {
      System.out.println(soFar + "," + thisCourse + "," + lastSign + ","
          + (int) leftArea + "," + (int) rightArea);
      }
      if(i % 450 == 0)
      {
        System.out.println("here");
      }
      
      lastTime = thisTime;
      lastCourse = thisCourse;
      // lastSpeed = thisSpeed;

    }

    return legs;
  }
<commit_msg>ditch debug lines<commit_after>package org.mwc.debrief.track_shift.zig_detector;

import java.util.ArrayList;
import java.util.List;

public class CumulativeLegDetector implements IOwnshipLegDetector
{

  /**
   * slice this data into ownship legs, where the course and speed are relatively steady
   * 
   * @param course_degs
   * @param speed
   * @param bearings
   * @param elapsedTimess
   * @return
   */
  public List<LegOfData> identifyOwnshipLegs(final long[] times,
      final double[] rawSpeeds, final double[] rawCourses,
      final int minsOfAverage, Precision precision)
  {

    double lastCourse = 0;
    long lastTime = 0;

    final double areaUnderTurn = 20000; // deg millis

    final List<LegOfData> legs = new ArrayList<LegOfData>();
    legs.add(new LegOfData("Leg-1"));
    Integer lastSign = null;
    double leftArea = 0;
    double rightArea = 0;

    // 1. make continuous dataset
    double[] newCourses =
        PeakTrackingOwnshipLegDetector.makeContinuous(rawCourses);
    
    final long startTime = times[0];

    for (int i = 0; i < times.length; i++)
    {
      final long thisTime = times[i];
      final double thisCourse = newCourses[i];

      if (i > 0)
      {
        // ok, check out the course change rate
        final double timeStep = thisTime - lastTime;
        final double courseDelta = thisCourse - lastCourse;
        // final double courseRate = courseDelta / timeStepSecs;
        final double courseArea = courseDelta * timeStep;

        // ok, find the sign of the course
        final int thisSign = (int) Math.signum(courseDelta);

        leftArea += courseArea;
        rightArea += courseArea;

        if (lastSign != null && thisSign != lastSign && thisSign != 0)
        {
          // ok, have we turned to left or right?
          if (thisSign == 1)
          {
            // turn to right

            // 1. the left turn is complete. does it count?
            if (Math.abs(leftArea) > areaUnderTurn)
            {
              System.out.println("left turn end at" +  (thisTime - startTime)/1000);
            }
            else
            {
//              System.out.println("skipping turn to right at " + (thisTime - startTime)/1000 + " area:" + leftArea + " crse" + thisCourse);
            }
            leftArea = 0;
          }
          else
          {
            // turn to left

            // 1. the right turn is complete. does it count?
            if (Math.abs(rightArea) > areaUnderTurn)
            {
              System.out.println("right turn end at" +  (thisTime - startTime)/1000);
            }
            else
            {
//              System.out.println("skipping turn to left at " +  (thisTime - startTime)/1000 + " area:" + rightArea + " crse" + thisCourse);
            }
            rightArea = 0;
          }
        }

        // ok, store the values
        if (thisSign != 0)
        {
          lastSign = thisSign;
        }
      }

      final long soFar = (thisTime - startTime)/1000;
      if(soFar > 600 && soFar < 1000)
      {
      System.out.println(soFar + "," + thisCourse + "," + lastSign + ","
          + (int) leftArea + "," + (int) rightArea);
      }
      if(i % 450 == 0)
      {
 //       System.out.println("here");
      }
      
      lastTime = thisTime;
      lastCourse = thisCourse;
      // lastSpeed = thisSpeed;

    }

    return legs;
  }

{'fraction_non_alphanumeric': 0.10655253837072019, 'fraction_numerical': 0.015348288075560802, 'mean_word_length': 1.7763211798443261, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4159530', 'n_tokens_mistral': 2085, 'n_tokens_neox': 1930, 'n_words': 554}