Examples of DataTable


Examples of com.google.visualization.datasource.datatable.DataTable

    assertStringArraysEqual(new String[]{"1996", "Youthanasia", "2.0"},
      resultStrings[3])
  }
 
  public void testSkippingWithFiltering() throws Exception {
    DataTable res = MockDataSource.getData(1);
   
    // The returned mock data table should consist of 45 rows
    assertEquals(45, res.getNumberOfRows());

    Query q = QueryBuilder.getInstance().parseQuery("SELECT Year, Band, Songs " +
        "WHERE Fans <= 3000 SKIPPING 10");
   
    q.validate();

    DataTable result = QueryEngine.executeQuery(q, res, ULocale.US);

    // Test column description
    List<ColumnDescription> cols =  result.getColumnDescriptions();

    assertEquals(3, cols.size());
    assertEquals("Year", cols.get(0).getId());
    assertEquals("Band", cols.get(1).getId());
    assertEquals("Songs", cols.get(2).getId());
View Full Code Here

Examples of com.google.visualization.datasource.datatable.DataTable

  }

  public void testRead() throws IOException, CsvDataSourceException {
    // Null reader.
    Reader reader = null;
    DataTable dataTable = CsvDataSourceHelper.read(reader, null, false);
    assertEquals(0, dataTable.getNumberOfRows());

    // Empty string reader.
    reader = new StringReader("");
    dataTable = CsvDataSourceHelper.read(reader, null, false);
    assertEquals(0, dataTable.getNumberOfRows());

    // Null TableDescription.
    reader = new StringReader("\n\n\n1,2,3\n\n4,5,6\n\n\n\n\n");
    dataTable = CsvDataSourceHelper.read(reader, null, false);
    assertEquals(2, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new TextValue("1"), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("2"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new TextValue("3"), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(new TextValue("4"), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("5"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(new TextValue("6"), dataTable.getRow(1).getCell(2).getValue());

    // Different column numbers.
    boolean catched = false;
    try {
      reader = new StringReader("1,2\na, b, c");
      dataTable = CsvDataSourceHelper.read(reader, null, false);
    } catch (CsvDataSourceException e) {
      catched = true;
      assertEquals(ReasonType.INTERNAL_ERROR, e.getReasonType());
      assertEquals(
          "Wrong number of columns in the data.",
          e.getMessageToUser());
    }
    assertTrue(catched);

    // Working example with a table description filled only with types.
    reader = new StringReader("1,a,true\n4,x13a,false\n1400,4,true");
    List<ColumnDescription> columnDescriptions = Lists.newArrayList();
    columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i2", ValueType.TEXT, null));
    columnDescriptions.add(new ColumnDescription("i3", ValueType.DATE, null));
    dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
    assertEquals(3, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(1), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("a"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(DateValue.getNullValue(), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(new NumberValue(4), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("x13a"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(DateValue.getNullValue(), dataTable.getRow(1).getCell(2).getValue());
    assertEquals(new NumberValue(1400), dataTable.getRow(2).getCell(0).getValue());
    assertEquals(new TextValue("4"), dataTable.getRow(2).getCell(1).getValue());
    assertEquals(DateValue.getNullValue(), dataTable.getRow(2).getCell(2).getValue());

    // Working example with a table description filled only with types.
    reader = new StringReader("1,a,2004-03-01\n4,x13a,2005-04-02\n1400,4,2006-05-03");
    columnDescriptions = Lists.newArrayList();
    columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i2", ValueType.TEXT, null));
    columnDescriptions.add(new ColumnDescription("i3", ValueType.DATE, null));
    dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
    assertEquals(3, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(1), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("a"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new DateValue(2004, 2, 1), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(new NumberValue(4), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("x13a"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(new DateValue(2005, 3, 2), dataTable.getRow(1).getCell(2).getValue());
    assertEquals(new NumberValue(1400), dataTable.getRow(2).getCell(0).getValue());
    assertEquals(new TextValue("4"), dataTable.getRow(2).getCell(1).getValue());
    assertEquals(new DateValue(2006, 4, 3), dataTable.getRow(2).getCell(2).getValue());
    assertEquals("i1", dataTable.getColumnDescription(0).getId());
    assertEquals("Column0", dataTable.getColumnDescription(0).getLabel());
    assertEquals("i2", dataTable.getColumnDescription(1).getId());
    assertEquals("Column1", dataTable.getColumnDescription(1).getLabel());
    assertEquals("i3", dataTable.getColumnDescription(2).getId());
    assertEquals("Column2", dataTable.getColumnDescription(2).getLabel());

    // Working example with header rows.
    reader = new StringReader("1,a,2004-03-01\n4,x13a,2005-04-02\n1400,4,2006-05-03");
    columnDescriptions = Lists.newArrayList();
    columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i2", ValueType.TEXT, null));
    columnDescriptions.add(new ColumnDescription("i3", ValueType.DATE, null));
    dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, true);
    assertEquals(2, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(4), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("x13a"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new DateValue(2005, 3, 2), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(new NumberValue(1400), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("4"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(new DateValue(2006, 4, 3), dataTable.getRow(1).getCell(2).getValue());
    assertEquals("i1", dataTable.getColumnDescription(0).getId());
    assertEquals("1",  dataTable.getColumnDescription(0).getLabel());
    assertEquals("i2", dataTable.getColumnDescription(1).getId());
    assertEquals("a", dataTable.getColumnDescription(1).getLabel());
    assertEquals("i3", dataTable.getColumnDescription(2).getId());
    assertEquals("2004-03-01", dataTable.getColumnDescription(2).getLabel());

    // Bad table description for that data.
    catched = false;
    try {
      reader = new StringReader("true\nfalse\nfalse");
      columnDescriptions = Lists.newArrayList();
      dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
    } catch (CsvDataSourceException e) {
      catched = true;
      assertEquals(ReasonType.INTERNAL_ERROR, e.getReasonType());
      assertEquals(
          "Wrong number of columns in the data.",
          e.getMessageToUser());
    }
    assertTrue(catched);

    // Working example with a null table description.
    reader = new StringReader("true,false\ntrue,false\ntrue,false\nfalse,false");
    columnDescriptions = null;
    dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
    assertEquals(4, dataTable.getNumberOfRows());
    assertEquals(2, dataTable.getNumberOfColumns());
    assertEquals(new TextValue("true"), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("false"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new TextValue("true"), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("false"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(new TextValue("true"), dataTable.getRow(2).getCell(0).getValue());
    assertEquals(new TextValue("false"), dataTable.getRow(2).getCell(1).getValue());
    assertEquals(new TextValue("false"), dataTable.getRow(3).getCell(0).getValue());
    assertEquals(new TextValue("false"), dataTable.getRow(3).getCell(1).getValue());

    // Working example with a table description filled with types.
    reader = new StringReader("true,false\ntrue,false\ntrue,false\nfalse,false");
    columnDescriptions = Lists.newArrayList();
    columnDescriptions.add(new ColumnDescription("1", ValueType.BOOLEAN, "123"));
    columnDescriptions.add(new ColumnDescription("2", ValueType.BOOLEAN, "123"));
    dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false);
    assertEquals(4, dataTable.getNumberOfRows());
    assertEquals(2, dataTable.getNumberOfColumns());
    assertEquals(BooleanValue.TRUE, dataTable.getRow(0).getCell(0).getValue());
    assertEquals(BooleanValue.FALSE, dataTable.getRow(0).getCell(1).getValue());
    assertEquals(BooleanValue.TRUE, dataTable.getRow(1).getCell(0).getValue());
    assertEquals(BooleanValue.FALSE, dataTable.getRow(1).getCell(1).getValue());
    assertEquals(BooleanValue.TRUE, dataTable.getRow(2).getCell(0).getValue());
    assertEquals(BooleanValue.FALSE, dataTable.getRow(2).getCell(1).getValue());
    assertEquals(BooleanValue.FALSE, dataTable.getRow(3).getCell(0).getValue());
    assertEquals(BooleanValue.FALSE, dataTable.getRow(3).getCell(1).getValue());
  }
View Full Code Here

Examples of com.google.visualization.datasource.datatable.DataTable

   
    ColumnDescription columnDescription = new ColumnDescription("i3", ValueType.DATE, null);
    columnDescription.setPattern("yyyyMMdd");
    columnDescriptions.add(columnDescription);
   
    DataTable dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, true);
    assertEquals(2, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(4), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new TextValue("x13a"), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new DateValue(2005, 3, 2), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(new NumberValue(1400), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(new TextValue("4"), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(new DateValue(2006, 4, 3), dataTable.getRow(1).getCell(2).getValue());
    assertEquals("i1", dataTable.getColumnDescription(0).getId());
    assertEquals("1",  dataTable.getColumnDescription(0).getLabel());
    assertEquals("i2", dataTable.getColumnDescription(1).getId());
    assertEquals("a", dataTable.getColumnDescription(1).getLabel());
    assertEquals("i3", dataTable.getColumnDescription(2).getId());
    assertEquals("20040301", dataTable.getColumnDescription(2).getLabel());
  }
View Full Code Here

Examples of com.google.visualization.datasource.datatable.DataTable

    List<ColumnDescription> columnDescriptions = Lists.newArrayList();
    columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i2", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i3", ValueType.NUMBER, null));
      
    DataTable dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, true);
    assertEquals(1, dataTable.getNumberOfRows());
    assertEquals(3, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(4), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new NumberValue(5), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new NumberValue(6), dataTable.getRow(0).getCell(2).getValue());
    assertEquals("i1", dataTable.getColumnDescription(0).getId());
    assertEquals("1",  dataTable.getColumnDescription(0).getLabel());
    assertEquals("i2", dataTable.getColumnDescription(1).getId());
    assertEquals("2", dataTable.getColumnDescription(1).getLabel());
    assertEquals("i3", dataTable.getColumnDescription(2).getId());
    assertEquals("3", dataTable.getColumnDescription(2).getLabel());
  }
View Full Code Here

Examples of com.google.visualization.datasource.datatable.DataTable

    columnDescriptions.add(new ColumnDescription("i1", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i2", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i3", ValueType.NUMBER, null));
    columnDescriptions.add(new ColumnDescription("i4", ValueType.NUMBER, null));
      
    DataTable dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, true);
    assertEquals(2, dataTable.getNumberOfRows());
    assertEquals(4, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(4), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(new NumberValue(5), dataTable.getRow(0).getCell(1).getValue());
    assertEquals(new NumberValue(6), dataTable.getRow(0).getCell(2).getValue());
    assertEquals(NumberValue.getNullValue(), dataTable.getRow(0).getCell(3).getValue());
    assertEquals(new NumberValue(7), dataTable.getRow(1).getCell(0).getValue());
    assertEquals(NumberValue.getNullValue(), dataTable.getRow(1).getCell(1).getValue());
    assertEquals(NumberValue.getNullValue(), dataTable.getRow(1).getCell(2).getValue());
    assertEquals(new NumberValue(10), dataTable.getRow(1).getCell(3).getValue());
    assertEquals("i1", dataTable.getColumnDescription(0).getId());
    assertEquals("1",  dataTable.getColumnDescription(0).getLabel());
    assertEquals("i2", dataTable.getColumnDescription(1).getId());
    assertEquals("", dataTable.getColumnDescription(1).getLabel());
    assertEquals("i3", dataTable.getColumnDescription(2).getId());
    assertEquals("2", dataTable.getColumnDescription(2).getLabel());
    assertEquals("i4", dataTable.getColumnDescription(3).getId());
    assertEquals("3", dataTable.getColumnDescription(3).getLabel());
 
View Full Code Here

Examples of com.google.visualization.datasource.datatable.DataTable

    columnDescriptions.add(new ColumnDescription("A", ValueType.NUMBER, "A"));
    columnDescriptions.add(new ColumnDescription("B", ValueType.TIMEOFDAY, "B"));
    TimeOfDayValue hindiTimeOfDayValue = new TimeOfDayValue(1, 12, 1);
    String hindiTimeOfDayString =  "\u0966\u0967\u003a\u0967\u0968\u003a\u0966\u0967";
    Reader reader = new StringReader("1," + hindiTimeOfDayString);
    DataTable dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false,
        new ULocale("hi_IN"));
    assertEquals(1, dataTable.getNumberOfRows());
    assertEquals(2, dataTable.getNumberOfColumns());
    assertEquals(new NumberValue(1), dataTable.getRow(0).getCell(0).getValue());
    assertEquals(hindiTimeOfDayValue, dataTable.getRow(0).getCell(1).getValue());
  }
View Full Code Here

Examples of com.google.visualization.datasource.datatable.DataTable

    List<String> columnIdsList = Lists.newArrayList("id", "fname", "lname",
        "gender", "salary", "ismarried", "startdate", "timestamp", "time");

    // Get the table description using the mock result set.
    DataTable dataTable = SqlDataSourceHelper.buildColumns(rs, columnIdsList);
    assertNotNull(dataTable);

    // Make sure the number of columns in the table description is correct.
    assertEquals(NUM_OF_COLS, dataTable.getNumberOfColumns());

    // Get the columns description list.
    List <ColumnDescription> columnsDescriptionList = dataTable.getColumnDescriptions();

    // Make sure the type of each column is correct.
    assertEquals(ValueType.NUMBER, columnsDescriptionList.get(0).getType());
    assertEquals(ValueType.TEXT, columnsDescriptionList.get(1).getType());
    assertEquals(ValueType.TEXT, columnsDescriptionList.get(2).getType());
    assertEquals(ValueType.TEXT, columnsDescriptionList.get(3).getType());
    assertEquals(ValueType.NUMBER, columnsDescriptionList.get(4).getType());
    assertEquals(ValueType.BOOLEAN, columnsDescriptionList.get(5).getType());
    assertEquals(ValueType.DATE, columnsDescriptionList.get(6).getType());
    assertEquals(ValueType.DATETIME, columnsDescriptionList.get(7).getType());
    assertEquals(ValueType.TIMEOFDAY, columnsDescriptionList.get(8).getType());

    // Make sure the label of each column is correct.
    assertEquals("ID", columnsDescriptionList.get(0).getLabel());
    assertEquals("Fname", columnsDescriptionList.get(1).getLabel());
    assertEquals("Lname", columnsDescriptionList.get(2).getLabel());
    assertEquals("Gender", columnsDescriptionList.get(3).getLabel());
    assertEquals("Salary", columnsDescriptionList.get(4).getLabel());
    assertEquals("IsMarried", columnsDescriptionList.get(5).getLabel());
    assertEquals("StartDate", columnsDescriptionList.get(6).getLabel());
    assertEquals("TimeStamp", columnsDescriptionList.get(7).getLabel());
    assertEquals("Time", columnsDescriptionList.get(8).getLabel());

    // Build the table rows.
    SqlDataSourceHelper.buildRows(dataTable, rs);

    assertNotNull(dataTable);

    // Make sure the number of rows int the table is correct.
    assertEquals(3, dataTable.getNumberOfRows());

    // Make sure the type of the data table cells is correct.
    for (int i = 0; i < dataTable.getNumberOfRows(); i++) {
      assertEquals(ValueType.NUMBER,
          dataTable.getRow(i).getCell(0).getValue().getType());
      assertEquals(ValueType.TEXT,
          dataTable.getRow(i).getCell(1).getValue().getType());
      assertEquals(ValueType.TEXT,
          dataTable.getRow(i).getCell(2).getValue().getType());
      assertEquals(ValueType.TEXT,
          dataTable.getRow(i).getCell(3).getValue().getType());
      assertEquals(ValueType.NUMBER,
          dataTable.getRow(i).getCell(4).getValue().getType());
      assertEquals(ValueType.BOOLEAN,
          dataTable.getRow(i).getCell(5).getValue().getType());
      assertEquals(ValueType.DATE,
          dataTable.getRow(i).getCell(6).getValue().getType());
      assertEquals(ValueType.DATETIME,
          dataTable.getRow(i).getCell(7).getValue().getType());
      assertEquals(ValueType.TIMEOFDAY,
          dataTable.getRow(i).getCell(8).getValue().getType());
    }

    // Make sure the value of the data table cells is correct. For cells with
    // null value, check that the value equals to the null value format of the
    // specific type value.
    assertEquals(new NumberValue(100.0),
        dataTable.getRow(0).getCell(0).getValue());
    assertEquals("Yaron", dataTable.getRow(0).getCell(1).getValue().toString());
    assertEquals(new TextValue(""), dataTable.getRow(0).getCell(2).getValue());
    assertEquals("Bar", dataTable.getRow(1).getCell(2).getValue().toString());
    assertEquals("F", dataTable.getRow(1).getCell(3).getValue().toString());
    assertEquals(BooleanValue.getNullValue(),
        dataTable.getRow(1).getCell(5).getValue());
    assertEquals(NumberValue.getNullValue(),
        dataTable.getRow(2).getCell(4).getValue());
    assertEquals("true", dataTable.getRow(2).getCell(5).getValue().toString());
    assertEquals(dataTable.getRow(0).getCell(6).getValue().toString(),
        new DateValue(gc), dataTable.getRow(0).getCell(6).getValue());
    assertEquals(new DateTimeValue(gc),
        dataTable.getRow(0).getCell(7).getValue());
    assertEquals(new TimeOfDayValue(gc),
        dataTable.getRow(0).getCell(8).getValue());
    assertEquals(DateValue.getNullValue(),
        dataTable.getRow(1).getCell(6).getValue());
    assertEquals(DateTimeValue.getNullValue(),
        dataTable.getRow(2).getCell(7).getValue());
    assertEquals(TimeOfDayValue.getNullValue(),
        dataTable.getRow(2).getCell(8).getValue());
  }
View Full Code Here

Examples of com.google.visualization.datasource.datatable.DataTable

    ResultSet rs = new MockResultSet(rows, NUM_OF_COLS, labels, types);

    List<String> columnIdsList = null;

    // Get the table description using the mock result set.
    DataTable dataTable = SqlDataSourceHelper.buildColumns(rs, columnIdsList);

    assertNotNull(dataTable);

    // Build the table rows.
    SqlDataSourceHelper.buildRows(dataTable, rs);

    // Make sure there aren't any rows in the data table.
    assertEquals(0, dataTable.getNumberOfRows());
    assertEquals(0, dataTable.getRows().size());
  }
View Full Code Here

Examples of com.googlecode.g2re.html.DataTable

        queryA.getParameters().add(new JdbcParameter(2, DataType.INTEGER, maxParam));
        report.getDataQueries().add(queryA);
       
       
        /* create data table, set the data query */
        DataTable table = new DataTable();
        table.setCellPadding(1);
        table.setDataQuery(queryA);

        /* create table header rows */
        GridRow tableHeader = new GridRow();
        tableHeader.addCell(new com.googlecode.g2re.html.GridCell(new RawHTML("Name")));
        tableHeader.addCell(new com.googlecode.g2re.html.GridCell(new RawHTML("Description")));
        tableHeader.addCell(new com.googlecode.g2re.html.GridCell(new RawHTML("City")));
        tableHeader.addCell(new com.googlecode.g2re.html.GridCell(new RawHTML("State")));
        tableHeader.addCell(new com.googlecode.g2re.html.GridCell(new RawHTML("Zip")));
        tableHeader.addCell(new com.googlecode.g2re.html.GridCell(new RawHTML("Price")));
        tableHeader.addCell(new com.googlecode.g2re.html.GridCell(new RawHTML("Image")));
        table.getHeaderRows().add(tableHeader);

        /* create table body rows */
        GridRow tableBody = new GridRow();
        tableBody.addCell(new com.googlecode.g2re.html.GridCell(new DataElement(col1, 0)));
        tableBody.addCell(new com.googlecode.g2re.html.GridCell(new DataElement(col2, 1)));
        tableBody.addCell(new com.googlecode.g2re.html.GridCell(new DataElement(col6, 2)));
        tableBody.addCell(new com.googlecode.g2re.html.GridCell(new DataElement(col7, 3)));
        tableBody.addCell(new com.googlecode.g2re.html.GridCell(new DataElement(col8, 4)));
        tableBody.addCell(new com.googlecode.g2re.html.GridCell(new DataElement("\"<img src='\" + row[4].toString() + \"' />\"",6)));
       
        /* add formatted price column */
        DataElement priceCellElement = new DataElement(col4, 5);
        priceCellElement.setNumberFormat("$###,###,###,##0.00");
        tableBody.addCell(new com.googlecode.g2re.html.GridCell(priceCellElement));
       
        /* add rows to table */
        table.getBodyRows().add(tableBody);

        /* add the table to the report */
        report.getWebPage().addChildElement(table);
       
        /* create and add a map */
 
View Full Code Here

Examples of com.googlecode.gwt.charts.client.DataTable

    for (CommunityAccount commAcc: listAccount) {
      listStats.add(commAcc.getName());
     
    }
    // Prepare the data
    DataTable dataTable = DataTable.create();
    dataTable.addColumn(ColumnType.STRING, "dates");
   
//    for (int i = 0; i < countries.length; i++) {
//      dataTable.addColumn(ColumnType.NUMBER, countries[i]);
//    }
    //
    for (String nameStat: listStats) {
      dataTable.addColumn(ColumnType.NUMBER, nameStat);
    }
   
    //dataTable.addRows(years.length);
    //
    CommunityAccount commAccount = listAccount.get(0);
    //String  tabDates[] = new String [100] ;
    //init tabDates
    int i = 0;
//    for(String date :commAccount.listDates) {
//      tabDates[i] = date;
//      i++;
//    }
   
   
//    //wn8 directe
//    Double [] tabWn8= new Double [100];
//    i = 0;
//    for(DataPlayerInfos data :commAccount.listDataPlayerInfos) {
//      tabWn8[i] = data.getStatistics().getAllStatistics().getWn8();
//      i++;
//    }
    //
    //wn8 directe
//    Double [] tabWr= new Double [100];
//    i = 0;
//    for(DataPlayerInfos data :commAccount.listDataPlayerInfos) {
//      tabWr[i] = data.getStatistics().getAllStatistics().getBattle_avg_performanceCalc()*100;
//      i++;
//    }
   
   
//    Integer [] tabBattlesWins = new Integer [100];
//    i = 0;
//    for(Integer wn :commAccount.listBattlesWins) {
//      tabBattlesWins[i] = wn;
//      i++;
//    }
   
//    Integer [] tabBattles = new Integer [100];
//    i = 0;
//    for(Integer wn :commAccount.listbattles) {
//      tabBattles[i] = wn;
//      i++;
//    }
   
    //
    dataTable.addRows(commAccount.listDates.size());
   
//    for (int i = 0; i < years.length; i++) {
//      dataTable.setValue(i, 0, String.valueOf(years[i]));
//    }
    //
    //on set la légende des abscisses ligne 0
//    i = 0;
//    for (String date: commAccount.listDates ) {
//      //String partdate= date.substring(0, 8);
//      dataTable.setValue(i, 0, String.valueOf(i));
//      i++;
//    }
    for (int row = 0; row < commAccount.listDates.size(); row++) {
      int index = commAccount.listDates.size() -1 ;
      index = index - row;
      String partdate = commAccount.listDates.get(index);
      //dd-Mm-AAAA
      partdate = partdate.substring(0, 5);
      dataTable.setValue(row, 0, String.valueOf(partdate));
     
     
    }
    //
//    for (int col = 0; col < values.length; col++) {
//      for (int row = 0; row < values[col].length; row++) {
   
   
//        dataTable.setValue(row, col + 1, values[col][row]);
//      }
//    }
    //
//    for (int col = 0; col < listStats.size() ; col++) {
//      for (int row = 0; row < commAccount.listDates.size(); row++) {
//        int bw = tabBattlesWins[col] ;
//        int b = tabBattles[col] ;
//        double db =  (double)bw/(double)b ;
//        int intdb = (int) (db * 100);
//        db = (double) intdb / (double)100 ;
//        dataTable.setValue(row, col + 1, db);
//      }
//    }
//   
    int col = 0 ;
    double avg = 0.0;
    int previousNbBattle = 0;
    for (CommunityAccount commAcc: listAccount) {
      avg = 0.0;
      previousNbBattle = 0;
      for (int row = 0; row < commAccount.listDates.size(); row++) {
        int index = commAccount.listDates.size() -1 ;
        index = index - row;
         DataPlayerInfos dataPlayerInfos = commAcc.listDataPlayerInfos.get(index);
         if (stat.equalsIgnoreCase("WN8")) {
           double tmp = dataPlayerInfos.getStatistics().getAllStatistics().getWn8();
          
           if (dataPlayerInfos.getStatistics().getAllStatistics().getWn8()!=0 && !Double.isNaN(dataPlayerInfos.getStatistics().getAllStatistics().getWn8())){
             avg = dataPlayerInfos.getStatistics().getAllStatistics().getWn8();
           }
           if (avg != 0.0) {
             int nb = (int) (avg * 100);
             avg = (double)nb/100;
             dataTable.setValue(row, col + 1, avg);
           }
         }
        
         if (stat.equalsIgnoreCase("WR")) {
           if (dataPlayerInfos.getStatistics().getAllStatistics().getBattle_avg_performanceCalc() ==null) {
             if (dataPlayerInfos.getStatistics().getAllStatistics().getWins() !=0 && dataPlayerInfos.getStatistics().getAllStatistics().getBattles() != 0) {
               avg = (double)dataPlayerInfos.getStatistics().getAllStatistics().getWins()/ (double)dataPlayerInfos.getStatistics().getAllStatistics().getBattles();
               avg = avg *100 ;
             }
             if (avg != 0.0)
               dataTable.setValue(row, col + 1, avg);
           } else {
             avg = dataPlayerInfos.getStatistics().getAllStatistics().getBattle_avg_performanceCalc() 100 ;
             if (avg != 0.0) {
               int nb = (int) (avg * 100);
               avg = (double)nb/100;
               dataTable.setValue(row, col + 1, avg);
             }
           }
         }
        
         if (stat.equalsIgnoreCase("BATTLE")) {
//           if (dataPlayerInfos.getStatistics().getAllStatistics().getBattle_avg_performanceCalc() == null) {
//             if (dataPlayerInfos.getStatistics().getAllStatistics().getWins() !=0 && dataPlayerInfos.getStatistics().getAllStatistics().getBattles() != 0) {
//               avg = (double)dataPlayerInfos.getStatistics().getAllStatistics().getWins()/ (double)dataPlayerInfos.getStatistics().getAllStatistics().getBattles();
//               avg = avg *100 ;
//             }
//             if (avg != 0.0)
//               dataTable.setValue(row, col + 1, avg);
//           } else {
//             avg = dataPlayerInfos.getStatistics().getAllStatistics().getBattle_avg_performanceCalc() *  100 ;
//             if (avg != 0.0) {
//               int nb = (int) (avg * 100);
//               avg = (double)nb/100;
//               dataTable.setValue(row, col + 1, avg);
//             }
//           }
           if (dataPlayerInfos.getStatistics().getAllStatistics()!= null) {
             int nbBattle = dataPlayerInfos.getStatistics().getAllStatistics().getBattles();
             avg = nbBattle;
             if (previousNbBattle == 0 )
               dataTable.setValue(row, col + 1, previousNbBattle);
             else {
               //diff par rapoort au précédent
               dataTable.setValue(row, col + 1, nbBattle - previousNbBattle);
             }
             previousNbBattle = nbBattle;
              
           }else {
             dataTable.setValue(row, col + 1, avg);
           }
         }
      }
     
      col++;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.