Example #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pressure_monitor);
    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    pressuremeter = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
    textViewPressure = (TextView) findViewById(R.id.textViewPressure);
    radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
    radioGroup.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.preasure) sensorId = 0;
            else if (checkedId == R.id.altitude) sensorId = 1;
            else sensorId = 2;
            plotLongHistory();
          }
        });
    setTitle("Pressure");

    // setup the APR History plot:
    preHistoryPlot = (XYPlot) findViewById(R.id.pressurePlot);
    preHistoryPlot.setRangeBoundaries(900, 1300, BoundaryMode.AUTO);
    preHistoryPlot.setDomainBoundaries(0, 100, BoundaryMode.AUTO); // FIXED);
    preHistoryPlot.addSeries(
        pressureHistorySeries,
        new LineAndPointFormatter(
            Color.BLACK, Color.RED, null, new PointLabelFormatter(Color.TRANSPARENT)));
    preHistoryPlot.setDomainStepValue(5);
    preHistoryPlot.setTicksPerRangeLabel(3);
    // preHistoryPlot.setDomainLabel("Sample Index");
    preHistoryPlot.getDomainLabelWidget().pack();
    preHistoryPlot.setRangeLabel("Temperature (ºC)");
    preHistoryPlot.getRangeLabelWidget().pack();
    preHistoryPlot.setRangeLabel("Pressure (hPa)");

    longHistoryPlot = (XYPlot) findViewById(R.id.longHistoryPlot);
    longHistoryPlot.setRangeBoundaries(900, 1300, BoundaryMode.AUTO);
    longHistoryPlot.setDomainBoundaries(0, 100, BoundaryMode.AUTO); // FIXED);
    longHistoryPlot.addSeries(
        longHistorySeries,
        new LineAndPointFormatter(
            Color.BLACK, Color.BLUE, null, new PointLabelFormatter(Color.TRANSPARENT)));
    longHistoryPlot.setDomainStepValue(5);
    longHistoryPlot.setTicksPerRangeLabel(3);
    longHistoryPlot.getDomainLabelWidget().pack();
    longHistoryPlot.setRangeLabel("Temperature (ºC)");
    longHistoryPlot.getRangeLabelWidget().pack();
    longHistoryPlot.setRangeLabel("Pressure (hPa)");

    // TEST
    if (!SamplingService.isRunning(this)) {
      SamplingAlarm.SetAlarm(this);
    }
  }
    /**
     * sectionalFFT takes an array with size greater than HISTORY_SIZE and creates FFT frames to
     * graph. The graph's domain is equal to HISTORY_SIZE
     *
     * @param input
     */
    private void sectionalFFT(double[] input) {
      AppLog.APP_TAG = "sectionalFFT";
      // Split this data into pieces that are HISTORY_SIZE elements in size
      int nFrames = input.length / HISTORY_SIZE; // Number of frames we will create from a mic read
      Number[] graphable = new Number[HISTORY_SIZE];
      double[] section = new double[HISTORY_SIZE];

      AppLog.logString("input.length: " + input.length + " nFrames: " + nFrames);

      // for the number of sections
      for (int j = 1; j < nFrames + 1; j++) {
        // Get the section
        for (int i = 0; i < HISTORY_SIZE; i++)
          section[i] = input[i * j]; // get the fft magnitude of 64 value frame
        graphable = fft_mag(section);
        audioHist.clear();
        for (int i = 0; i < graphable.length; i++) audioHist.add(i, graphable[i]);

        // adjust the Range (y axis) to be as long as it needs to be.
        // plot.setRangeBoundaries(0, max(graphable), BoundaryMode.FIXED);
        plot.setRangeBoundaries(30, 100, BoundaryMode.FIXED);
        // update the graph.
        audioHistSeries.setModel(audioHist, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY);
        plot.setDomainBoundaries(0, graphable.length, BoundaryMode.FIXED);
        try {
          dynamicPlot.postRedraw();
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
 private void checkBoundaries() {
   // Make sure the proposed domain boundaries will not cause plotting issues
   if (minXY.x < absMinX || ((Double) minXY.x).equals(Double.NaN)) minXY.x = absMinX;
   else if (minXY.x > maxNoError) minXY.x = maxNoError;
   if (maxXY.x > absMaxX || ((Double) maxXY.x).equals(Double.NaN)) maxXY.x = absMaxX;
   else if (maxXY.x < minNoError) maxXY.x = minNoError;
   if (maxXY.x - minXY.x < minDif) maxXY.x = maxXY.x + (double) (minDif - (maxXY.x - minXY.x));
   else if (maxXY.x - minXY.x > maxDif)
     maxXY.x = maxXY.x + (double) (maxDif - (maxXY.x - minXY.x));
   graph.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED);
 }
  private void updatePlot(SeriesSize seriesSize) {

    // Remove all current series from each plot
    plot.clear();

    // Setup our Series with the selected number of elements
    series1 =
        new SimpleXYSeries(
            Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Us");
    series2 =
        new SimpleXYSeries(
            Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Them");

    plot.setDomainBoundaries(-1, series1.size(), BoundaryMode.FIXED);
    plot.setRangeUpperBoundary(
        SeriesUtils.minMax(series1, series2).getMaxY().doubleValue() + 1, BoundaryMode.FIXED);

    if (seriesSize != null) {
      switch (seriesSize) {
        case TEN:
          plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 2);
          break;
        case TWENTY:
          plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 4);
          break;
        case SIXTY:
          plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 6);
          break;
      }
    }

    // add a new series' to the xyplot:
    if (series1CheckBox.isChecked()) plot.addSeries(series1, formatter1);
    if (series2CheckBox.isChecked()) plot.addSeries(series2, formatter2);

    // Setup the BarRenderer with our selected options
    MyBarRenderer renderer = plot.getRenderer(MyBarRenderer.class);
    renderer.setBarOrientation((BarRenderer.BarOrientation) spRenderStyle.getSelectedItem());
    final BarRenderer.BarGroupWidthMode barGroupWidthMode =
        (BarRenderer.BarGroupWidthMode) spWidthStyle.getSelectedItem();
    renderer.setBarGroupWidth(
        barGroupWidthMode,
        barGroupWidthMode == BarRenderer.BarGroupWidthMode.FIXED_WIDTH
            ? sbFixedWidth.getProgress()
            : sbVariableWidth.getProgress());

    if (BarRenderer.BarOrientation.STACKED.equals(spRenderStyle.getSelectedItem())) {
      plot.getInnerLimits().setMaxY(15);
    } else {
      plot.getInnerLimits().setMaxY(0);
    }

    plot.redraw();
  }
  public GraphUpdater(Activity activity) {
    this.activity = activity;
    wifi = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
    plot = (XYPlot) activity.findViewById(R.id.graph);
    hash = new HashMap<String, WifiStrengthXYSeries>();

    plot.setTitle("");
    plot.setTicksPerRangeLabel(2);
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);
    plot.setDomainBoundaries(-1, 15, BoundaryMode.FIXED);
    plot.setDomainLabel("Channel");
    DecimalFormat df = new DecimalFormat("#0");
    df.setParseIntegerOnly(true);
    plot.setDomainValueFormat(df);
    plot.setRangeBoundaries(-100, -20, BoundaryMode.FIXED);
    plot.setRangeLabel("Strength");
    plot.getLegendWidget().setVisible(false);
  }
  private void scroll(float pan) {
    final double domainSpan = maxXY.x - minXY.x;
    final double step = domainSpan / graph.getWidth();
    final double offset = pan * step;
    minXY.x += offset;
    maxXY.x += offset;

    if (minXY.x < absMinX) {
      minXY.x = absMinX;
      maxXY.x -= offset; // (absMinX-minXY.x);
    } else if (minXY.x > maxNoError) minXY.x = maxNoError;
    if (maxXY.x > absMaxX) {
      maxXY.x = absMaxX; // (maxXY.x-absMaxX);
      minXY.x -= offset; // (maxXY.x-absMaxX);
    } else if (maxXY.x < minNoError) maxXY.x = minNoError;
    if (maxXY.x - minXY.x < minDif) maxXY.x = maxXY.x + (double) (minDif - (maxXY.x - minXY.x));

    graph.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED);
  }
Example #7
0
  /** DESCRIPTION: Sets the boundaries for the X and Y-axis based on the data values. */
  private void setPlotAxisBoundaries() {

    // set y-axis boundaries
    long boundy = 25;
    while (maxy >= boundy) boundy *= 2;
    plot.setRangeBoundaries(0, (float) boundy, BoundaryMode.FIXED);

    // set y-axis steps
    double stepy = ((double) boundy) / 10;
    plot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, stepy);
    plot.setTicksPerRangeLabel(2);

    // set x-axis boundaries
    lowerboundx = minx - 1;
    upperboundx = maxx + 1;
    plot.setDomainBoundaries(lowerboundx, upperboundx, BoundaryMode.FIXED);

    // set x-axis steps
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);
    plot.setTicksPerDomainLabel(1);

    // determine the number of months being plotted
    long months = maxx - minx + 1;

    // adjust bar thickness based on number of months being plotted
    BarRenderer<?> barRenderer = (BarRenderer<?>) plot.getRenderer(BarRenderer.class);
    if (barRenderer != null) {
      Display display = activity.getWindowManager().getDefaultDisplay();
      float displayWidth = Utilities.convertPixelsToDp(display.getWidth());
      float plotWidth = displayWidth * 0.75f;
      float barWidth = plotWidth / months;
      barRenderer.setBarWidth(barWidth);
    }

    // adjust label size based on number of months being plotted
    xlabels.setAbbreviate(months > 6);
  }
 private void checkBoundaries() {
   // Make sure the proposed domain boundaries will not cause plotting issues
   m_viewPort.updateBoudaries();
   mySimpleXYPlot.setDomainBoundaries(m_viewPort.minXY.x, m_viewPort.maxXY.x, BoundaryMode.AUTO);
 }
Example #9
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.poincare);

    // Rellenar vector RR1
    for (int i = 1; i < Representar.RR.size(); i++) {
      RR1.add(Representar.RR.get(i));
    }
    // Rellenar vector RRaux
    for (int i = 0; i < Representar.RR.size() - 1; i++) {
      RRaux.add(Representar.RR.get(i));

      Log.i("RRaux", String.valueOf(Representar.RR.get(i)));
    }

    // Declarar el Plot
    mySimpleXYPlot = (XYPlot) findViewById(R.id.plotPoincare);

    // Configurar el Plot
    XYSeries series1 =
        new SimpleXYSeries(
            RRaux, // Vector a representar en el eje X
            RR1, // Vector a representar en el eje Y
            "Poincaré"); // Etiqueta

    LineAndPointFormatter series1Format =
        new LineAndPointFormatter(
            Color.TRANSPARENT, // Color de la línea
            Color.rgb(
                Representar.color0, Representar.color1, Representar.color2), // Color de los puntos
            null); // Color de relleno

    // Propiedades para configurar el Plot
    mySimpleXYPlot.addSeries(series1, series1Format);
    mySimpleXYPlot.setTicksPerRangeLabel(4);
    mySimpleXYPlot.disableAllMarkup();
    mySimpleXYPlot.getBackgroundPaint().setAlpha(0);
    mySimpleXYPlot.getGraphWidget().getBackgroundPaint().setAlpha(0);
    mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setAlpha(0);
    // Redibujar el Plot
    mySimpleXYPlot.redraw();

    // Configuración boundaries
    mySimpleXYPlot.calculateMinMaxVals();
    // Cálculo del valor mínimo y máximo
    minXY =
        new PointF(
            mySimpleXYPlot.getCalculatedMinX().floatValue(),
            mySimpleXYPlot.getCalculatedMinY().floatValue());
    maxXY =
        new PointF(
            mySimpleXYPlot.getCalculatedMaxX().floatValue(),
            mySimpleXYPlot.getCalculatedMaxY().floatValue());
    mySimpleXYPlot.setScrollbarFadingEnabled(true);
    mySimpleXYPlot.setScrollContainer(true);

    mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getLegendWidget());
    // Etiquetas vertical y horizontal
    mySimpleXYPlot.setRangeLabel("RR N+1");
    mySimpleXYPlot.setDomainLabel("RR N");
    mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getTitleWidget());
    // Márgenes del Plot
    mySimpleXYPlot.setPlotMargins(10, 10, 10, 10);
    mySimpleXYPlot.setPlotPadding(10, 10, 10, 10);
    // Comienzo y fin del plot
    mySimpleXYPlot.setDomainBoundaries(
        mySimpleXYPlot.getCalculatedMinX().floatValue() - 10.0,
        mySimpleXYPlot.getCalculatedMaxX().floatValue() + 10.0,
        BoundaryMode.FIXED);
    mySimpleXYPlot.setRangeBoundaries(
        mySimpleXYPlot.getCalculatedMinY().floatValue() - 10.0,
        mySimpleXYPlot.getCalculatedMaxY().floatValue() + 10.0,
        BoundaryMode.FIXED);
  }
Example #10
0
  void generatePlot() {
    TextView tv = (TextView) findViewById(R.id.plotViewTitle);
    tv.setText(
        "Avistamientos durante " + meses[actualMonth - 1] + " del " + String.valueOf(actualYear));

    SQLiteDatabase myDB = null;

    myDB = this.openOrCreateDatabase(DB_NAME, 1, null);

    myDB.execSQL(
        "CREATE TABLE IF NOT EXISTS "
            + TABLE
            + " ("
            + ADDR_DB
            + " TEXT NOT NULL PRIMARY KEY, "
            + COORD_X_DB
            + " INTEGER NOT NULL, "
            + COORD_Y_DB
            + " INTEGER NOT NULL, "
            + INF_DB
            + " TEXT, "
            + DAY_DB
            + " INTEGER, "
            + MONTH_DB
            + " INTEGER, "
            + YEAR_DB
            + " INTEGER);");

    /*
     * Solo obtendremos los días donde se han visto avistamientos ordenados por menor a mayor.
     */
    String[] FROM = {DAY_DB};
    String ORDER_BY = YEAR_DB + " DESC, " + MONTH_DB + " DESC, " + DAY_DB + " DESC";

    Cursor c =
        myDB.query(
            TABLE,
            FROM,
            MONTH_DB + "=" + actualMonth + " AND " + YEAR_DB + "=" + actualYear,
            null,
            null,
            null,
            ORDER_BY);

    /*
     * Preparamos el vector de Number dependiendo del mes que tengamos que mostrar
     */
    Number[] series1Numbers;
    int daysOfMonth = 0;

    if (actualMonth == 1
        || actualMonth == 3
        || actualMonth == 5
        || actualMonth == 7
        || actualMonth == 8
        || actualMonth == 10
        || actualMonth == 12) {
      daysOfMonth = 32;
      series1Numbers = new Number[daysOfMonth];
      for (int i = 0; i < daysOfMonth; ++i) series1Numbers[i] = 0;
    } else if (actualMonth == 2) {
      daysOfMonth = 29;
      series1Numbers = new Number[daysOfMonth];
      for (int i = 0; i < daysOfMonth; ++i) series1Numbers[i] = 0;
    } else {
      daysOfMonth = 31;
      series1Numbers = new Number[daysOfMonth];
      for (int i = 0; i < daysOfMonth; ++i) series1Numbers[i] = 0;
    }

    int max = 0; // sirve para establecer el máximo Y valor del gráfico
    int aux = 0;
    int dayAux = 0;

    startManagingCursor(c);
    while (c.moveToNext()) {
      int dayDB = c.getInt(0);
      if (max < aux) max = aux;
      if (dayAux == 0) {
        dayAux = dayDB;
        ++aux;
      } else {
        if (dayAux == dayDB) ++aux;
        else {
          series1Numbers[dayAux] = aux;
          aux = 1;
          dayAux = dayDB;
        }
      }
    }
    if (dayAux != 0) series1Numbers[dayAux] = aux;

    c.close();

    if (myDB != null) {
      myDB.close();
    }

    // Inicializamos el objeto XYPlot búscandolo desde el layout:
    mySimpleXYPlot = (XYPlot) findViewById(R.id.plot);
    mySimpleXYPlot.clear();
    mySimpleXYPlot.setDomainLabel("Días de " + meses[actualMonth - 1]);
    mySimpleXYPlot.setRangeLabel("Número de avistamientos");

    // Añadimos Línea Número UNO:
    XYSeries series1 =
        new SimpleXYSeries(
            Arrays.asList(series1Numbers), // Array de datos
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Valores verticales
            "Número de avistamientos"); // Nombre de la serie

    // Modificamos los colores de la primera serie
    LineAndPointFormatter series1Format =
        new LineAndPointFormatter(
            Color.rgb(200, 0, 0), // Color de la l�nea
            Color.rgb(0, 0, 0), // Color del punto
            Color.rgb(190, 150, 150)); // Relleno

    // Una vez definida la serie (datos y estilo), la añadimos al panel
    mySimpleXYPlot.addSeries(series1, series1Format);

    if (max == 0) ++max;

    // Tuneamos el grafico
    mySimpleXYPlot.setDomainValueFormat(new DecimalFormat("#"));
    mySimpleXYPlot.setDomainBoundaries(1, daysOfMonth - 1, BoundaryMode.FIXED);
    mySimpleXYPlot.setDomainStepValue(daysOfMonth);
    if (daysOfMonth == 32) {
      mySimpleXYPlot.setTicksPerDomainLabel(2);
    } else if (daysOfMonth == 31) {
      mySimpleXYPlot.setTicksPerDomainLabel(3);
    } else if (daysOfMonth == 28) {
      mySimpleXYPlot.setTicksPerDomainLabel(2);
    }
    mySimpleXYPlot.setRangeUpperBoundary(max + 2, BoundaryMode.FIXED);
    mySimpleXYPlot.setRangeStepValue(max + 3);
    mySimpleXYPlot.setTicksPerRangeLabel(1);
    mySimpleXYPlot.disableAllMarkup();

    /*
     * Generamos la vista de nueva para mostrar la nueva gráfica
     */
    ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
    sv.postInvalidate();
  }