<commit_before>package water.api;

import hex.drf.DRF;
import hex.gbm.GBM;
import hex.glm.GLM2;
import water.*;
import water.api.Inspect2.ColSummary.ColType;
import water.fvec.*;

public class Inspect2 extends Request2 {
  static final int API_WEAVER=1; // This file has auto-gen'd doc & json fields
  static public DocGen.FieldDoc[] DOC_FIELDS; // Initialized from Auto-Gen code.

  // This Request supports the HTML 'GET' command, and this is the help text
  // for GET.
  static final String DOC_GET = "Inspect a fluid-vec frame";
  static final String NA = ""; // not available information

  @API(help="An existing H2O Frame key.", required=true, filter=Default.class)
  Frame src_key;

  @API(help="Offset to begin viewing rows, or -1 to see a structural representation of the data", filter=Default.class, lmin=-1, lmax=Long.MAX_VALUE)
  long offset;

  @API(help="Number of data rows.") long numRows;
  @API(help="Number of data columns.") int numCols;
  @API(help="byte size in memory.") long byteSize;

  // An internal JSON-output-only class
  static class ColSummary extends Iced {
    public static enum ColType { Enum, Int, Real };
    static final int API_WEAVER=1; // This file has auto-gen'd doc & json fields
    static public DocGen.FieldDoc[] DOC_FIELDS; // Initialized from Auto-Gen code.
    public ColSummary( String name, Vec vec ) {
      this.name = name;
      this.type = vec.isEnum() ? ColType.Enum : vec.isInt() ? ColType.Int : ColType.Real;
      this.min  = vec.isEnum() ? Double.NaN : vec.min();
      this.max  = vec.isEnum() ? Double.NaN : vec.max();
      this.mean = vec.isEnum() ? Double.NaN : vec.mean();
      this.naCnt= vec.naCnt();
      this.cardinality = vec.cardinality();
    }
    @API(help="Label."           ) final String  name;
    @API(help="type."            ) final ColType type;
    @API(help="min."             ) final double  min;
    @API(help="max."             ) final double  max;
    @API(help="mean."            ) final double  mean;
    @API(help="Missing elements.") final long    naCnt;
    @API(help="Cardinality.")      final long    cardinality;
  }

  @API(help="Array of Column Summaries.")
  ColSummary cols[];


  // Called from some other page, to redirect that other page to this page.
  public static Response redirect(Request req, String src_key) {
    return Response.redirect(req, "/2/Inspect2", "src_key", src_key );
  }

  // Just validate the frame, and fill in the summary bits
  @Override protected Response serve() {
    if( src_key == null ) return RequestServer._http404.serve();
    numRows = src_key.numRows();
    numCols = src_key.numCols();
    Futures fs = new Futures();
    for( int i=0; i<numCols; i++ )
      src_key.vecs()[i].rollupStats(fs);
    fs.blockForPending();
    byteSize = src_key.byteSize();
    cols = new ColSummary[numCols];
    for( int i=0; i<cols.length; i++ )
      cols[i] = new ColSummary(src_key._names[i],src_key.vecs()[i]);
    return Response.done(this);
  }

  public static String jsonLink(Key key){return "2/Inspect2.json?src_key=" + key;}

  @Override public boolean toHTML( StringBuilder sb ) {
    Key skey = Key.make(input("src_key"));

    // Missing/NA count
    long naCnt = 0;
    // Enum column is in dataset
    boolean enumCol = false;
    for( int i=0; i<cols.length; i++ ) {
      naCnt += cols[i].naCnt;
      enumCol |= cols[i].type == ColType.Enum;
    }


    DocGen.HTML.title(sb,skey.toString());
    DocGen.HTML.section(sb,""+String.format("%,d",numCols)+" columns, "+String.format("%,d",numRows)+" rows, "+
                        PrettyPrint.bytes(byteSize)+" bytes (compressed), "+
                        (naCnt== 0 ? "no":PrettyPrint.bytes(naCnt))+" missing elements");

    sb.append("<div class='alert'>" +
              "<br/> Expand factors using " + OneHot.link(skey, "One Hot Expansion") +
              //"View " + SummaryPage2.link(key, "Summary") +
              "<br/>Build models using " +
              DRF.link(skey, "Distributed Random Forest") +", "+
              GBM.link(skey, "Distributed GBM") +", "+
              GLM2.link(skey, "Generalized Linear Modeling (beta)") +", "+
              hex.LR2.link(skey, "Linear Regression") + ",<br>"+
              SummaryPage2.link(skey,"Summary")+", "+
              DownloadDataset.link(skey, "Download as CSV") +
              "</div>");
    String _scrollto = String.valueOf(offset - 1);
      sb.append(
      " <script>$(document).ready(function(){ " +
      " $('html, body').animate({ scrollTop: $('#row_"+_scrollto+"').offset().top" +
      "}, 2000);" +
      "return false;" +
      "});</script>");
    sb.append(
        "<form class='well form-inline' action='Inspect2.html' id='inspect'>" +
        " <input type='hidden' name='src_key' value="+skey.toString()+">" +
        " <input type='text' class='input-small span5' placeholder='filter' " +
        "    name='offset' id='offset' value='"+offset+"' maxlength='512'>" +
        " <button type='submit' class='btn btn-primary'>Jump to row!</button>" +
        "</form>");

    // Start of where the pagination table goes.  For now, just the info button.
    sb.append(pagination(src_key.numRows(), skey));

    DocGen.HTML.arrayHead(sb);
    // Column labels<commit_msg>comment inspect2 page ~ one hot link rm<commit_after>package water.api;

import hex.drf.DRF;
import hex.gbm.GBM;
import hex.glm.GLM2;
import water.*;
import water.api.Inspect2.ColSummary.ColType;
import water.fvec.*;

public class Inspect2 extends Request2 {
  static final int API_WEAVER=1; // This file has auto-gen'd doc & json fields
  static public DocGen.FieldDoc[] DOC_FIELDS; // Initialized from Auto-Gen code.

  // This Request supports the HTML 'GET' command, and this is the help text
  // for GET.
  static final String DOC_GET = "Inspect a fluid-vec frame";
  static final String NA = ""; // not available information

  @API(help="An existing H2O Frame key.", required=true, filter=Default.class)
  Frame src_key;

  @API(help="Offset to begin viewing rows, or -1 to see a structural representation of the data", filter=Default.class, lmin=-1, lmax=Long.MAX_VALUE)
  long offset;

  @API(help="Number of data rows.") long numRows;
  @API(help="Number of data columns.") int numCols;
  @API(help="byte size in memory.") long byteSize;

  // An internal JSON-output-only class
  static class ColSummary extends Iced {
    public static enum ColType { Enum, Int, Real };
    static final int API_WEAVER=1; // This file has auto-gen'd doc & json fields
    static public DocGen.FieldDoc[] DOC_FIELDS; // Initialized from Auto-Gen code.
    public ColSummary( String name, Vec vec ) {
      this.name = name;
      this.type = vec.isEnum() ? ColType.Enum : vec.isInt() ? ColType.Int : ColType.Real;
      this.min  = vec.isEnum() ? Double.NaN : vec.min();
      this.max  = vec.isEnum() ? Double.NaN : vec.max();
      this.mean = vec.isEnum() ? Double.NaN : vec.mean();
      this.naCnt= vec.naCnt();
      this.cardinality = vec.cardinality();
    }
    @API(help="Label."           ) final String  name;
    @API(help="type."            ) final ColType type;
    @API(help="min."             ) final double  min;
    @API(help="max."             ) final double  max;
    @API(help="mean."            ) final double  mean;
    @API(help="Missing elements.") final long    naCnt;
    @API(help="Cardinality.")      final long    cardinality;
  }

  @API(help="Array of Column Summaries.")
  ColSummary cols[];


  // Called from some other page, to redirect that other page to this page.
  public static Response redirect(Request req, String src_key) {
    return Response.redirect(req, "/2/Inspect2", "src_key", src_key );
  }

  // Just validate the frame, and fill in the summary bits
  @Override protected Response serve() {
    if( src_key == null ) return RequestServer._http404.serve();
    numRows = src_key.numRows();
    numCols = src_key.numCols();
    Futures fs = new Futures();
    for( int i=0; i<numCols; i++ )
      src_key.vecs()[i].rollupStats(fs);
    fs.blockForPending();
    byteSize = src_key.byteSize();
    cols = new ColSummary[numCols];
    for( int i=0; i<cols.length; i++ )
      cols[i] = new ColSummary(src_key._names[i],src_key.vecs()[i]);
    return Response.done(this);
  }

  public static String jsonLink(Key key){return "2/Inspect2.json?src_key=" + key;}

  @Override public boolean toHTML( StringBuilder sb ) {
    Key skey = Key.make(input("src_key"));

    // Missing/NA count
    long naCnt = 0;
    // Enum column is in dataset
    boolean enumCol = false;
    for( int i=0; i<cols.length; i++ ) {
      naCnt += cols[i].naCnt;
      enumCol |= cols[i].type == ColType.Enum;
    }


    DocGen.HTML.title(sb,skey.toString());
    DocGen.HTML.section(sb,""+String.format("%,d",numCols)+" columns, "+String.format("%,d",numRows)+" rows, "+
                        PrettyPrint.bytes(byteSize)+" bytes (compressed), "+
                        (naCnt== 0 ? "no":PrettyPrint.bytes(naCnt))+" missing elements");

    sb.append("<div class='alert'>" +
              //"<br/> Expand factors using " + OneHot.link(skey, "One Hot Expansion") +
              //"View " + SummaryPage2.link(key, "Summary") +
              "<br/>Build models using " +
              DRF.link(skey, "Distributed Random Forest") +", "+
              GBM.link(skey, "Distributed GBM") +", "+
              GLM2.link(skey, "Generalized Linear Modeling (beta)") +", "+
              hex.LR2.link(skey, "Linear Regression") + ",<br>"+
              SummaryPage2.link(skey,"Summary")+", "+
              DownloadDataset.link(skey, "Download as CSV") +
              "</div>");
    String _scrollto = String.valueOf(offset - 1);
      sb.append(
      " <script>$(document).ready(function(){ " +
      " $('html, body').animate({ scrollTop: $('#row_"+_scrollto+"').offset().top" +
      "}, 2000);" +
      "return false;" +
      "});</script>");
    sb.append(
        "<form class='well form-inline' action='Inspect2.html' id='inspect'>" +
        " <input type='hidden' name='src_key' value="+skey.toString()+">" +
        " <input type='text' class='input-small span5' placeholder='filter' " +
        "    name='offset' id='offset' value='"+offset+"' maxlength='512'>" +
        " <button type='submit' class='btn btn-primary'>Jump to row!</button>" +
        "</form>");

    // Start of where the pagination table goes.  For now, just the info button.
    sb.append(pagination(src_key.numRows(), skey));

    DocGen.HTML.arrayHead(sb);
    // Column labels
{'fraction_non_alphanumeric': 0.15584045584045583, 'fraction_numerical': 0.006742640075973409, 'mean_word_length': 2.863169479090242, 'pattern_counts': {'":': 2, '<': 35, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3089535', 'n_tokens_mistral': 3435, 'n_tokens_neox': 3355, 'n_words': 879}