package hex.schemas;

import hex.kmeans.KMeans;
import hex.kmeans.KMeansModel.KMeansParameters;
import water.api.API;
import water.api.ModelParametersSchema;
import water.fvec.Frame;
import water.util.PojoUtils;

public class KMeansV2 extends ModelBuilderSchema<KMeans,KMeansV2,KMeansV2.KMeansParametersV2> {

  public static final class KMeansParametersV2 extends ModelParametersSchema<KMeansParameters, KMeansParametersV2> {
    public String[] fields() {
      return new String[] {
            "destination_key",
            "training_frame",
            "K",
            "max_iters",
            "normalize",
            "seed",
            "init"
      };
    }

    // Input fields
    @API(help = "Number of clusters", required = true)
    public int K;

    @API(help="Maximum training iterations.")
    public int max_iters;        // Max iterations

    @API(help = "Normalize columns", level = API.Level.secondary)
    public boolean normalize = true;

    @API(help = "RNG Seed", level = API.Level.expert /* tested, works: , dependsOn = {"K", "max_iters"} */ )
    public long seed;

    @API(help = "Initialization mode", values = { "None", "PlusPlus", "Furthest" }) // TODO: pull out of enum class. . .
    public KMeans.Initialization init;

    @Override public KMeansParametersV2 fillFromImpl(KMeansParameters parms) {
      super.fillFromImpl(parms);
      this.init = KMeans.Initialization.Furthest;
      return this;
    }

    public KMeansParameters fillImpl(KMeansParameters impl) {
      PojoUtils.copyProperties(impl, this, PojoUtils.FieldNaming.DEST_HAS_UNDERSCORES);
      impl._init = KMeans.Initialization.Furthest;

      // Sigh:
      impl._train = (this.training_frame == null ? null : this.training_frame._key);
      impl._valid = (this.validation_frame == null ? null : this.validation_frame._key);
      return impl;
    }
  }

  //==========================
  // Custom adapters go here

  // TODO: UGH
  // Return a URL to invoke KMeans on this Frame
  @Override protected String acceptsFrame( Frame fr ) { return "/v2/KMeans?training_frame="+fr._key; }
}

@@ -420,24 +420,31 @@
 rsV2%3E %7B%0A    
+static 
 public Strin
@@ -451,136 +451,40 @@
 g%5B%5D 
+own_
 fields
-() %7B%0A      return new String%5B%5D %7B%0A            %22destination_key%22,%0A            %22training_frame%22,%0A            %22K%22,%0A           
+ = new String%5B%5D %7B %22K%22,
  %22ma
@@ -492,28 +492,16 @@
 _iters%22,
-%0A           
  %22normal
@@ -509,62 +509,26 @@
 ze%22,
-%0A            %22seed%22,%0A            %22init%22%0A      %7D;%0A    %7D
+ %22seed%22, %22init%22 %7D;
 %0A%0A  

Fix KMeansV2 for New World Order