Package com.google.visualization.datasource.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


  }

  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

   
    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

    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

    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

    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

    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

    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

  @Override
  public DataTable generateDataTable(Query query, HttpServletRequest request) {

    // Create a data table,
    DataTable data = new DataTable();
    ArrayList cd = new ArrayList();
    try {
      // Fill the data table.
      cd.add(new ColumnDescription("date", ValueType.DATETIME, "Date"));
      Sensor sensor =
          ofy().load().type(Sensor.class).id(Long.parseLong(request.getParameter("id"))).now();
      log.log(Level.WARNING, "sensor={0}", sensor);
      if (sensor.getType() == Sensor.Type.TEMPERATURE || sensor.getType() == Sensor.Type.HUMIDITY) {
        cd.add(new ColumnDescription("high", ValueType.NUMBER, "High"));
        cd.add(new ColumnDescription("low", ValueType.NUMBER, "Low"));
      } else if (sensor.getType() == Sensor.Type.LIGHT) {
        cd.add(new ColumnDescription("nonzeroavg", ValueType.NUMBER, "Total"));
      } else if (sensor.getType() == Sensor.Type.WINDSPEED) {
        cd.add(new ColumnDescription("high", ValueType.NUMBER, "High"));
      }
      data.addColumns(cd);

      List<ReadingHistory> readings =
          ofy().load().type(ReadingHistory.class).ancestor(sensor).list();
      GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
      // without a timezone of GMT, you will get:
      // can't create DateTimeValue from GregorianCalendar that is not GMT.
      // and if you want your graph in a TZ other than GMT? Nope.
      for (ReadingHistory reading : readings) {
        cal.setTime(new Date(reading.getTimestamp().getTime()));
        if (sensor.getType() == Sensor.Type.TEMPERATURE || sensor.getType() == Sensor.Type.HUMIDITY) {
          data.addRowFromValues(cal, new Double(reading.getHigh()), new Double(reading.getLow()));
        } else if (sensor.getType() == Sensor.Type.LIGHT) {
          data.addRowFromValues(cal, new Double(reading.getAverage()));
        } else if (sensor.getType() == Sensor.Type.WINDSPEED) {
          data.addRowFromValues(cal, new Double(reading.getHigh()));
        }
      }
    } catch (final TypeMismatchException e) {
      log.log(Level.SEVERE, e.toString(), e);
    }
View Full Code Here

  }

  @Override
  public DataTable generateDataTable(Query query, HttpServletRequest request) {
    // Create a data table,
    DataTable data = new DataTable();
    ArrayList cd = new ArrayList();
    cd.add(new ColumnDescription("date", ValueType.DATETIME, "Date"));
    cd.add(new ColumnDescription("reading", ValueType.NUMBER, "Reading"));
    data.addColumns(cd);

    // Fill the data table.
    try {
      // TODO pass sensor id in as a parameter, then pass back values for that id
      Sensor sensor =
          ofy().load().type(Sensor.class).id(Long.parseLong(request.getParameter("id"))).now();
      Date cutoffdate = new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24 * 7));
      List<Reading> readings =
          ofy().load().type(Reading.class).ancestor(sensor).filter("timestamp >", cutoffdate)
              .list();
      GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
      // without a timezone of GMT, you will get:
      // can't create DateTimeValue from GregorianCalendar that is not GMT.
      // and if you want your graph in a TZ other than GMT? Nope.
      for (Reading reading : readings) {
        cal.setTime(new Date(reading.getTimestamp().getTime() - (7 * 60 * 60 * 1000))); // convert
                                                                                        // timezones...TODO
                                                                                        // fix this
                                                                                        // kludge
        data.addRowFromValues(cal, new Double(reading.getValue()));
      }
    } catch (final TypeMismatchException e) {
      log.log(Level.SEVERE, e.toString(), e);
    }
    return data;
View Full Code Here

TOP

Related Classes of com.google.visualization.datasource.datatable.DataTable

Copyright © 2018 www.massapicom. 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.