package swf.app;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import swf.accel.model.AccelerationData;
import swf.model.TimeSeries;
import swf.nnc.NearestNeighbourClassificator;
import swf.transformer.SubTransformer;

public class GestureDistanceInfo implements Evaluator {
  private NearestNeighbourClassificator<TimeSeries<AccelerationData>> nearestNeighbourClassificator;

  public GestureDistanceInfo(
      NearestNeighbourClassificator<TimeSeries<AccelerationData>> nearestNeighbourClassificator
  ) {
    this.nearestNeighbourClassificator = nearestNeighbourClassificator;
  }

  /**
   * Checks if the library gestures match the given gestures.
   */
  public String evaluate(List<TimeSeries<AccelerationData>> timeSeriesList) {
    Iterator<TimeSeries<AccelerationData>> iterator = timeSeriesList.iterator();
    String output = "";
    while (iterator.hasNext()) {
      output += this.evaluateTimeSeries(iterator.next()) + "\n";
    }
    return output;
  }

  private String evaluateTimeSeries(TimeSeries<AccelerationData> timeSeries) {
    LinkedList<TimeSeries<AccelerationData>> library =
        new LinkedList<TimeSeries<AccelerationData>>();
    LinkedList<TimeSeries<AccelerationData>> gestures =
        new LinkedList<TimeSeries<AccelerationData>>();
    for (int i = 1; i < 9; i++) {
      SubTransformer<AccelerationData> subTransformer =
          new SubTransformer<AccelerationData>("START " + i, "END " + i);
      library.add(subTransformer.transform(timeSeries));
      subTransformer = new SubTransformer<AccelerationData>("START " + (i + 8), "END " + (i + 8));
      gestures.add(subTransformer.transform(timeSeries));
    }
    String output = "";
    for (int i = 0; i < 8; i++) {
      TimeSeries<AccelerationData> gesture = gestures.get(i);
      output += i + " => " + library.indexOf(
          this.nearestNeighbourClassificator.searchNearestNeighbour(gesture, library)
      ) + "\n";
    }
    return output;
  }
}

@@ -863,25 +863,449 @@
 g output = %22
-%22
+    ____  _______       __%5Cn%22%0A        + %22   / __ %5C%5C/_  __/ %7C     / /%5Cn%22%0A        + %22  / / / / / /  %7C %7C /%7C / / %5Cn%22%0A        + %22 / /_/ / / /   %7C %7C/ %7C/ /  %5Cn%22%0A        + %22/_____/ /_/    %7C__/%7C__/   %5Cn%22%0A        + %22                          %5Cn%22;%0A    String format = %22%7C Record %25d %7C %25d %7C %25d %7C %25d %7C %25d %7C %25d %7C %25d %7C %25d %7C %25d %7C%5Cn%22;%0A    int recordIndex = 1;%0A    String top = %22+----------+---+---+---+---+---+---+---+---+%5Cn%22;%0A    output += top
 ;%0A    while 
@@ -1333,24 +1333,29 @@
 %7B%0A      
-outpu
+int%5B%5D resul
 t 
-+
 = this.e
@@ -1388,23 +1388,285 @@
 .next())
- + %22%5Cn%22
+;%0A      output += String.format(%0A          format,%0A          recordIndex,%0A          result%5B0%5D,%0A          result%5B1%5D,%0A          result%5B2%5D,%0A          result%5B3%5D,%0A          result%5B4%5D,%0A          result%5B5%5D,%0A          result%5B6%5D,%0A          result%5B7%5D%0A      );%0A      recordIndex++
 ;%0A    %7D%0A
@@ -1678,24 +1678,30 @@
 eturn output
+ + top
 ;%0A  %7D%0A%0A  pri
@@ -1705,22 +1705,21 @@
 private 
-String
+int%5B%5D
  evaluat
@@ -2388,26 +2388,33 @@
     
-String output = %22%22
+int%5B%5D result = new int%5B8%5D
 ;%0A  
@@ -2517,30 +2517,19 @@
     
-output += i + %22 =%3E %22 +
+result%5Bi%5D =
  lib
@@ -2639,15 +2639,8 @@
    )
- + %22%5Cn%22
 ;%0A  
@@ -2654,21 +2654,21 @@
  return 
-outpu
+resul
 t;%0A  %7D%0A%7D

format gesture info