示例#1
0
  /**
   * Returns a sample dataset.
   *
   * @return A sample dataset.
   */
  private static XYDataset createDataset() {
    TimeSeriesCollection result = new TimeSeriesCollection();
    TimeSeries series1 = new TimeSeries("Value");

    for (int i = 0; i <= 23; i++) {
      series1.add(new Hour(i, 18, 10, 2011), Math.random() * 50 + 40);
    }

    result.addSeries(series1);
    return result;
  }
示例#2
0
  /**
   * Creates a sample dataset.
   *
   * @return a sample dataset.
   */
  XYDataset createDataset(Context context) {

    // get data from database
    // Form an array specifying which columns to return.
    int counter = 0;
    String[] projection =
        new String[] {
          BPTable1.COLUMN_ID,
          BPTable1.COLUMN_DATE,
          BPTable1.COLUMN_TIME,
          BPTable1.COLUMN_SYSTOLIC,
          BPTable1.COLUMN_DIASTOLIC,
          BPTable1.COLUMN_HEARTRATE
        };

    // Get the base URI for the BPTable table in the Contacts content provider.
    Uri uri = MyContentProvider.CONTENT_URI;

    // Make the query.
    if (uri != null) {
      Cursor cur =
          context
              .getContentResolver()
              .query(
                  uri, /// managedQuery(uri,  //
                  projection, // Which columns to return
                  null, // Which rows to return (all rows)
                  null, // Selection arguments (none)
                  // Put the results in ascendingorder by name
                  BPTable1.COLUMN_ID + " ASC");

      // reading data
      if (cur.moveToFirst()) {
        // String name;
        // String phoneNumber;
        int dateColumn = cur.getColumnIndex(BPTable1.COLUMN_DATE);
        int timeColumn = cur.getColumnIndex(BPTable1.COLUMN_TIME);
        int systolicColumn = cur.getColumnIndex(BPTable1.COLUMN_SYSTOLIC);
        int diastolicColumn = cur.getColumnIndex(BPTable1.COLUMN_DIASTOLIC);
        int pulseColumn = cur.getColumnIndex(BPTable1.COLUMN_HEARTRATE);

        // String imagePath;
        do {
          // Get the field values
          list_date.add(cur.getString(dateColumn));
          list_time.add(cur.getString(timeColumn));
          list_systolic.add(cur.getString(systolicColumn));
          list_diastolic.add(cur.getString(diastolicColumn));
          list_pulse.add(cur.getString(pulseColumn));
          counter++;

        } while (cur.moveToNext());
      }
    }

    TimeSeries ts1 = new TimeSeries("systolic");
    for (int j = 0; j < counter; j++) {
      ts1.addOrUpdate(
          new Minute(
              Integer.parseInt(list_time.get(j).substring(2)),
              Integer.parseInt(list_time.get(j).substring(0, 2)),
              Integer.parseInt(list_date.get(j).substring(6)),
              Integer.parseInt(list_date.get(j).substring(4, 6)),
              Integer.parseInt(list_date.get(j).substring(0, 4))),
          Integer.parseInt(list_systolic.get(j)));
    }

    TimeSeries ts2 = new TimeSeries("diastolic");
    for (int j = 0; j < counter; j++) {
      ts2.addOrUpdate(
          new Minute(
              Integer.parseInt(list_time.get(j).substring(2)),
              Integer.parseInt(list_time.get(j).substring(0, 2)),
              Integer.parseInt(list_date.get(j).substring(6)),
              Integer.parseInt(list_date.get(j).substring(4, 6)),
              Integer.parseInt(list_date.get(j).substring(0, 4))),
          Integer.parseInt(list_diastolic.get(j)));
    }

    TimeSeries ts3 = new TimeSeries("pulse");
    for (int j = 0; j < counter; j++) {
      ts3.addOrUpdate(
          new Minute(
              Integer.parseInt(list_time.get(j).substring(2)),
              Integer.parseInt(list_time.get(j).substring(0, 2)),
              Integer.parseInt(list_date.get(j).substring(6)),
              Integer.parseInt(list_date.get(j).substring(4, 6)),
              Integer.parseInt(list_date.get(j).substring(0, 4))),
          Integer.parseInt(list_pulse.get(j)));
    }

    /*
    TimeSeries ts2 = new TimeSeries("diastolic");
    for (int j=0;j<=i-4;j=j+4)  {
       ts2.add(new Second(Integer.parseInt(array1[j+3].substring(12)), Integer.parseInt(array1[j+3].substring(10,12)),Integer.parseInt(array1[j+3].substring(8,10)),
      		 Integer.parseInt(array1[j+3].substring(6,8)),Integer.parseInt(array1[j+3].substring(4,6)),Integer.parseInt(array1[j+3].substring(0,4))), Integer.parseInt(array1[j+1]));
    }

    TimeSeries ts3 = new TimeSeries("heart rate");
    for (int j=0;j<=i-4;j=j+4)  {
    ts3.add(new Second(Integer.parseInt(array1[j+3].substring(12)), Integer.parseInt(array1[j+3].substring(10,12)),Integer.parseInt(array1[j+3].substring(8,10)),
            Integer.parseInt(array1[j+3].substring(6,8)),Integer.parseInt(array1[j+3].substring(4,6)),Integer.parseInt(array1[j+3].substring(0,4))), Integer.parseInt(array1[j+2]));
    }  */

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(ts1);
    dataset.addSeries(ts2);
    dataset.addSeries(ts3);

    return dataset;
  }